fix(engine): a reset or a lost focus commits the pending text

Clicking elsewhere, changing focus, or any client reset dropped the
composition in the GTK module and IBus (only XIM ResetIC handed it
back), so typing 안녕 and clicking Send lost 녕. The engine now returns
the pending text — a moved-to candidate first, as Enter would — on
Keyreset and Keyrelease; the GTK module asks for it before closing on
focus-out and commits it, IBus commits it on FocusOut, Reset and a
switch to a password field, and XIM commits it on focus loss and hands
it back on ResetIC without a separate capability probe.
This commit is contained in:
2026-08-16 21:05:31 +09:00
parent 4c8954b8ae
commit 11bf379ad3
10 changed files with 151 additions and 98 deletions

View File

@@ -27,6 +27,7 @@ struct Log
int rfirst;
int rcommit;
int rdone;
int flushed;
};
static void
@@ -51,6 +52,11 @@ legacy(IBusInputContext *ctx, IBusText *text, guint cursor,
log = arg;
log->legacy++;
s = ibus_text_get_text(text);
if(log->repeat == 3){
if(s[0] != '\0' || cursor != 0 || visible)
log->invalid = 1;
return;
}
if(log->repeat != 0){
revent(log, 'P');
if(log->repeat == 1){
@@ -134,6 +140,16 @@ commit(IBusInputContext *ctx, IBusText *text, void *arg)
log->commit++;
s = ibus_text_get_text(text);
attrs = ibus_text_get_attributes(text);
if(log->repeat == 3){
/* Focus loss hands the pending syllable back as a commit. */
if(strcmp(s, "") == 0)
log->flushed = 1;
else
log->invalid = 1;
if(log->loop != NULL && log->waiting != NULL && *log->waiting)
g_main_loop_quit(log->loop);
return;
}
if(log->repeat != 0){
revent(log, 'K');
if(log->repeat != 2 || strcmp(s, "") != 0 || attrs == NULL ||
@@ -253,9 +269,10 @@ main(int argc, char **argv)
log.rn = 0;
ok = ok && ibus_input_context_process_key_event(a, 'z', 0, 0) &&
waitflag(&log, &log.rdone) && strcmp(log.revent, "PKP") == 0;
log.repeat = 0;
log.repeat = 3;
ibus_input_context_focus_out(a);
if(log.legacy == 0 || log.modern != 0 || log.commit != 2 ||
ok = ok && waitflag(&log, &log.flushed);
if(log.legacy == 0 || log.modern != 0 || log.commit != 3 ||
log.invalid || !log.done || !log.atext || !log.aclear ||
log.clearctx != a || !log.rdone)
ok = 0;
@@ -265,12 +282,12 @@ main(int argc, char **argv)
g_object_unref(bus);
if(!ok){
fprintf(stderr,
"ibus_client_smoke: legacy=%d modern=%d commit=%d invalid=%d preedit=%d committed=%d transfer-text=%d a-clear=%d repeat=%s\n",
"ibus_client_smoke: legacy=%d modern=%d commit=%d invalid=%d preedit=%d committed=%d transfer-text=%d a-clear=%d repeat=%s flushed=%d\n",
log.legacy, log.modern, log.commit, log.invalid,
log.sawpreedit, log.sawcommit, log.atext, log.aclear,
log.revent);
log.revent, log.flushed);
return 1;
}
printf("official libibus client preedit, commit, and owner clear: ok\n");
printf("official libibus client preedit, commit, owner clear, and focus-out hand-back: ok\n");
return 0;
}