add GtkInputPurpose
This commit is contained in:
46
gtk/main.c
46
gtk/main.c
@@ -113,10 +113,26 @@ sendreset(Im *im)
|
|||||||
buf[1] = 0;
|
buf[1] = 0;
|
||||||
buf[2] = Kesc & 0xff;
|
buf[2] = Kesc & 0xff;
|
||||||
buf[3] = Kesc >> 8;
|
buf[3] = Kesc >> 8;
|
||||||
if(write(im->fd, buf, 4) == 4)
|
if(send(im->fd, buf, 4, MSG_NOSIGNAL) == 4)
|
||||||
readresp(im, resp, sizeof(resp));
|
readresp(im, resp, sizeof(resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
plaincommit(GtkIMContext *ctx, uint32_t key, uint32_t mod)
|
||||||
|
{
|
||||||
|
char u[8];
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if(mod & (Mctrl|Malt|Msuper))
|
||||||
|
return FALSE;
|
||||||
|
if(key < 0x20 || key >= Kspec)
|
||||||
|
return FALSE;
|
||||||
|
n = g_unichar_to_utf8(key, u);
|
||||||
|
u[n] = '\0';
|
||||||
|
g_signal_emit_by_name(ctx, "commit", u);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
kpress(GtkIMContext *ctx, GdkEventKey *ev)
|
kpress(GtkIMContext *ctx, GdkEventKey *ev)
|
||||||
{
|
{
|
||||||
@@ -125,29 +141,41 @@ kpress(GtkIMContext *ctx, GdkEventKey *ev)
|
|||||||
char resp[64];
|
char resp[64];
|
||||||
uint32_t key, mod;
|
uint32_t key, mod;
|
||||||
int r;
|
int r;
|
||||||
|
GtkInputPurpose purpose;
|
||||||
|
|
||||||
im = (Im*)ctx;
|
im = (Im*)ctx;
|
||||||
if(ev->type != GDK_KEY_PRESS)
|
if(ev->type != GDK_KEY_PRESS)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
srvconnect(im);
|
|
||||||
if(im->fd < 0)
|
|
||||||
return FALSE;
|
|
||||||
key = kget(ev->keyval);
|
key = kget(ev->keyval);
|
||||||
if(key == 0)
|
if(key == 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
mod = mget(ev->state);
|
mod = mget(ev->state);
|
||||||
|
g_object_get(ctx, "input-purpose", &purpose, NULL);
|
||||||
|
if(purpose == GTK_INPUT_PURPOSE_PASSWORD || purpose == GTK_INPUT_PURPOSE_PIN)
|
||||||
|
return plaincommit(ctx, key, mod);
|
||||||
|
srvconnect(im);
|
||||||
|
if(im->fd < 0)
|
||||||
|
return plaincommit(ctx, key, mod);
|
||||||
buf[0] = 1;
|
buf[0] = 1;
|
||||||
buf[1] = mod;
|
buf[1] = mod;
|
||||||
buf[2] = key & 0xff;
|
buf[2] = key & 0xff;
|
||||||
buf[3] = key >> 8;
|
buf[3] = key >> 8;
|
||||||
if(write(im->fd, buf, 4) != 4)
|
if(send(im->fd, buf, 4, MSG_NOSIGNAL) != 4){
|
||||||
return FALSE;
|
close(im->fd);
|
||||||
|
im->fd = -1;
|
||||||
|
return plaincommit(ctx, key, mod);
|
||||||
|
}
|
||||||
r = readresp(im, resp, sizeof(resp));
|
r = readresp(im, resp, sizeof(resp));
|
||||||
if(r < 0)
|
if(r < 0){
|
||||||
return FALSE;
|
close(im->fd);
|
||||||
|
im->fd = -1;
|
||||||
|
return plaincommit(ctx, key, mod);
|
||||||
|
}
|
||||||
if(resp[0] != '\0')
|
if(resp[0] != '\0')
|
||||||
g_signal_emit_by_name(ctx, "commit", resp);
|
g_signal_emit_by_name(ctx, "commit", resp);
|
||||||
return r != 0;
|
if(r != 0)
|
||||||
|
return TRUE;
|
||||||
|
return plaincommit(ctx, key, mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
2
strans.c
2
strans.c
@@ -17,7 +17,7 @@ Lang langs[] = {
|
|||||||
{LangJPK, "kata", "kanji", transmap, backmap, dictqmap, nil, nil},
|
{LangJPK, "kata", "kanji", transmap, backmap, dictqmap, nil, nil},
|
||||||
{LangKO, "hangul", nil, transko, backko, dictqmap, nil, nil},
|
{LangKO, "hangul", nil, transko, backko, dictqmap, nil, nil},
|
||||||
{LangEMOJI, "emoji", "emoji", transmap, backmap, dictqmap, nil, nil},
|
{LangEMOJI, "emoji", "emoji", transmap, backmap, dictqmap, nil, nil},
|
||||||
{LangVI, "telex", nil, transvi, backmap, dictqmap, nil, nil},
|
// {LangVI, "telex", nil, transvi, backmap, dictqmap, nil, nil},
|
||||||
};
|
};
|
||||||
int nlang = nelem(langs);
|
int nlang = nelem(langs);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user