ipc, srv, gtk: the client's text goes over and a take-back comes back
The engine can reach a Hanja reading back into the text the client already holds, but only if the frontend hands that text over and can take some of it away again. GTK 3 has both: retrieve-surrounding brings the text around the cursor and delete-surrounding removes runes before it, and a widget that answers neither leaves the text empty, so nothing is ever reached into or taken from it. The wire grows a control frame for the text, sent like the caret only when it changes, and one byte in every response for the runes to take back. That byte moves the length fields along, so the version goes to 2: an old daemon and a new module, either way round, fail the handshake and the module falls through to GtkIMContextSimple rather than misread a frame. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
20
srv.c
20
srv.c
@@ -31,11 +31,17 @@ srvnote(void *v, char *note)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 0 for a request to make, 1 for a frame that only changes what rides
|
||||
* along with the requests after it, -1 for anything else.
|
||||
*/
|
||||
static int
|
||||
srvreadreq(int fd, Keyreq *kr, int *want)
|
||||
{
|
||||
uchar req[Ipccaretsz];
|
||||
char text[Ipcfieldmax];
|
||||
int valid;
|
||||
size_t n;
|
||||
int32_t x, y, h;
|
||||
|
||||
if(ipcreadn(fd, req, Ipcreqsz) < 0)
|
||||
@@ -62,6 +68,12 @@ srvreadreq(int fd, Keyreq *kr, int *want)
|
||||
kr->caret.y = y;
|
||||
kr->caret.h = h;
|
||||
return 0;
|
||||
case Ipcsurround:
|
||||
n = ipcsurroundlen(req);
|
||||
if(n > 0 && ipcreadn(fd, text, n) < 0)
|
||||
return -1;
|
||||
stail(&kr->surround, text, n);
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -78,7 +90,7 @@ clientthread(void *arg)
|
||||
Keyres res;
|
||||
uchar out[Ipcmaxresp], token;
|
||||
char commit[Maxutf], preedit[Maxutf];
|
||||
int fd, n, ncommit, npreedit, want;
|
||||
int fd, n, ncommit, npreedit, rv, want;
|
||||
|
||||
fd = (int)(uintptr)arg;
|
||||
threadsetname("client %d", fd);
|
||||
@@ -86,7 +98,9 @@ clientthread(void *arg)
|
||||
kr.reply = chancreate(sizeof(Keyres), 0);
|
||||
kr.owner = &fd;
|
||||
kr.clientpre = 1;
|
||||
while(srvreadreq(fd, &kr, &want) >= 0){
|
||||
while((rv = srvreadreq(fd, &kr, &want)) >= 0){
|
||||
if(rv != 0)
|
||||
continue;
|
||||
if(kr.op != Keycaret)
|
||||
kr.clientpre = want;
|
||||
chansend(keyc, &kr);
|
||||
@@ -97,7 +111,7 @@ clientthread(void *arg)
|
||||
npreedit = stoutf(&res.preedit, preedit, sizeof preedit);
|
||||
/* A capability reply is always eaten: it marks the extension. */
|
||||
n = ipcpackresp(out, sizeof out, kr.op == Keycap || res.eaten,
|
||||
commit, ncommit, preedit, npreedit, want);
|
||||
res.del, commit, ncommit, preedit, npreedit, want);
|
||||
if(n < 0 || ipcsend(fd, out, n) < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user