fix(frontends): preserve preedit lifecycle

This commit is contained in:
2026-08-15 15:05:49 +09:00
parent aeb6010f3c
commit d29d43f443
6 changed files with 164 additions and 46 deletions

28
ibus.c
View File

@@ -55,10 +55,12 @@ static int icctr;
static int busctr;
static Channel *replyc;
static const char ibusowner[] = ":1.0";
static Ictx *preowner;
static DBusHandlerResult onmsg(DBusConnection*, DBusMessage*, void*);
static DBusHandlerResult handleerror(DBusConnection*, DBusMessage*,
const char*, const char*);
static void checkpreowner(void);
static void
unlinkaddr(void)
@@ -355,6 +357,8 @@ static void
dropcontext(Ictx *ctx)
{
releasecontext(ctx);
if(preowner == ctx)
preowner = nil;
memset(ctx, 0, sizeof *ctx);
}
@@ -382,6 +386,8 @@ processkey(Ictx *ctx, u32int sym, u32int state, Keyres *res)
if(state & Relmask || !ctx->focused || hidden(ctx))
return 0;
sendrequest(ctx, Keypress, kget(sym), mget(state), res);
if(preowner != nil && preowner != ctx)
checkpreowner();
return 1;
}
@@ -488,10 +494,29 @@ emitpreedit(Ictx *ctx, const char *text)
dbus_message_iter_append_basic(&it, DBUS_TYPE_UINT32, &mode);
}
dbus_message_set_sender(sig, ibusowner);
dbus_connection_send(ctx->conn, sig, nil);
if(dbus_connection_send(ctx->conn, sig, nil)){
if(text[0] != '\0')
preowner = ctx;
else if(preowner == ctx)
preowner = nil;
}
dbus_message_unref(sig);
}
static void
checkpreowner(void)
{
Ictx *ctx;
Keyres res;
ctx = preowner;
if(ctx == nil)
return;
sendrequest(ctx, Keycap, 0, 0, &res);
if(!res.eaten)
emitpreedit(ctx, "");
}
static DBusHandlerResult
handlehello(DBusConnection *c, DBusMessage *m)
{
@@ -1183,5 +1208,6 @@ ibusthread(void *_)
while(dbus_connection_dispatch(conns[i]) == DBUS_DISPATCH_DATA_REMAINS)
;
pruneconns();
checkpreowner();
}
}