ibus: cover context ownership through the engine
This commit is contained in:
52
ibus.c
52
ibus.c
@@ -316,6 +316,38 @@ dropcontext(Ictx *ctx)
|
||||
memset(ctx, 0, sizeof *ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
dropconncontexts(DBusConnection *conn)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < nelem(contexts); i++)
|
||||
if(contexts[i].conn == conn)
|
||||
dropcontext(&contexts[i]);
|
||||
}
|
||||
|
||||
static int
|
||||
processkey(Ictx *ctx, u32int sym, u32int state, Keyres *res)
|
||||
{
|
||||
if(state & Relmask || !ctx->focused)
|
||||
return 0;
|
||||
sendrequest(ctx, Keypress, kget(sym), mget(state), res);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
setcursor(Ictx *ctx, int x, int y, int h)
|
||||
{
|
||||
Keyres res;
|
||||
|
||||
ctx->caret.valid = 1;
|
||||
ctx->caret.x = x;
|
||||
ctx->caret.y = y;
|
||||
ctx->caret.h = h;
|
||||
if(ctx->focused)
|
||||
sendrequest(ctx, Keycaret, 0, 0, &res);
|
||||
}
|
||||
|
||||
static void
|
||||
appendibustext(DBusMessageIter *it, const char *s)
|
||||
{
|
||||
@@ -458,7 +490,6 @@ handlekey(DBusConnection *c, DBusMessage *m, Ictx *ctx)
|
||||
dbus_uint32_t sym, code, state;
|
||||
Keyres res;
|
||||
char commit[Maxutf], preedit[Maxutf];
|
||||
u32int ks, mod;
|
||||
|
||||
dbus_error_init(&err);
|
||||
if(!dbus_message_get_args(m, &err,
|
||||
@@ -470,11 +501,8 @@ handlekey(DBusConnection *c, DBusMessage *m, Ictx *ctx)
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
}
|
||||
USED(code);
|
||||
if(state & Relmask || !ctx->focused)
|
||||
if(!processkey(ctx, sym, state, &res))
|
||||
return handlebool(c, m, 0);
|
||||
ks = kget(sym);
|
||||
mod = mget(state);
|
||||
sendrequest(ctx, Keypress, ks, mod, &res);
|
||||
stoutf(&res.commit, commit, sizeof commit);
|
||||
stoutf(&res.preedit, preedit, sizeof preedit);
|
||||
if(commit[0] != '\0')
|
||||
@@ -531,7 +559,6 @@ handlecursor(DBusConnection *c, DBusMessage *m, Ictx *ctx)
|
||||
{
|
||||
DBusError err;
|
||||
dbus_int32_t x, y, w, h;
|
||||
Keyres res;
|
||||
|
||||
dbus_error_init(&err);
|
||||
if(!dbus_message_get_args(m, &err,
|
||||
@@ -545,12 +572,7 @@ handlecursor(DBusConnection *c, DBusMessage *m, Ictx *ctx)
|
||||
if(w < 0 || h < 0)
|
||||
return handleerror(c, m, DBUS_ERROR_INVALID_ARGS,
|
||||
"cursor dimensions must not be negative");
|
||||
ctx->caret.valid = 1;
|
||||
ctx->caret.x = x;
|
||||
ctx->caret.y = y;
|
||||
ctx->caret.h = h;
|
||||
if(ctx->focused)
|
||||
sendrequest(ctx, Keycaret, 0, 0, &res);
|
||||
setcursor(ctx, x, y, h);
|
||||
return handlenoop(c, m);
|
||||
}
|
||||
|
||||
@@ -671,7 +693,7 @@ newconn(DBusServer *s, DBusConnection *c, void *_)
|
||||
static void
|
||||
pruneconns(void)
|
||||
{
|
||||
int i, j, k;
|
||||
int i, j;
|
||||
|
||||
j = 0;
|
||||
for(i = 0; i < nconns; i++){
|
||||
@@ -679,9 +701,7 @@ pruneconns(void)
|
||||
conns[j++] = conns[i];
|
||||
continue;
|
||||
}
|
||||
for(k = 0; k < nelem(contexts); k++)
|
||||
if(contexts[k].conn == conns[i])
|
||||
dropcontext(&contexts[k]);
|
||||
dropconncontexts(conns[i]);
|
||||
dbus_connection_unref(conns[i]);
|
||||
}
|
||||
nconns = j;
|
||||
|
||||
Reference in New Issue
Block a user