From b63122dd14d95953b9b165bdb8486425e8db9c5a Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Mon, 3 Aug 2026 12:03:45 +0900 Subject: [PATCH] add GtkInputPurpose --- gtk/main.c | 46 +++++++++++++++++++++++++++++++++++++--------- strans.c | 2 +- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/gtk/main.c b/gtk/main.c index 55c16cf..326822d 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -113,10 +113,26 @@ sendreset(Im *im) buf[1] = 0; buf[2] = Kesc & 0xff; 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)); } +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 kpress(GtkIMContext *ctx, GdkEventKey *ev) { @@ -125,29 +141,41 @@ kpress(GtkIMContext *ctx, GdkEventKey *ev) char resp[64]; uint32_t key, mod; int r; + GtkInputPurpose purpose; im = (Im*)ctx; if(ev->type != GDK_KEY_PRESS) return FALSE; - srvconnect(im); - if(im->fd < 0) - return FALSE; key = kget(ev->keyval); if(key == 0) return FALSE; 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[1] = mod; buf[2] = key & 0xff; buf[3] = key >> 8; - if(write(im->fd, buf, 4) != 4) - return FALSE; + if(send(im->fd, buf, 4, MSG_NOSIGNAL) != 4){ + close(im->fd); + im->fd = -1; + return plaincommit(ctx, key, mod); + } r = readresp(im, resp, sizeof(resp)); - if(r < 0) - return FALSE; + if(r < 0){ + close(im->fd); + im->fd = -1; + return plaincommit(ctx, key, mod); + } if(resp[0] != '\0') g_signal_emit_by_name(ctx, "commit", resp); - return r != 0; + if(r != 0) + return TRUE; + return plaincommit(ctx, key, mod); } static void diff --git a/strans.c b/strans.c index 90c5c01..01f968e 100644 --- a/strans.c +++ b/strans.c @@ -17,7 +17,7 @@ Lang langs[] = { {LangJPK, "kata", "kanji", transmap, backmap, dictqmap, nil, nil}, {LangKO, "hangul", nil, transko, backko, 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);