imDefLkup: Commit first info in XimCommitInfo

Xic.private.proto.commit_info can receive multiple XimCommitInfo
when typing keys very quickly like an bar code scanner (or evemu-play)
and the first info in XimCommitInfo should be committed to keep
the typing key order.

Fixes: #198
This commit is contained in:
Takao Fujiwara 2024-01-31 20:27:57 +09:00
parent 024d229fdf
commit 041b5291f0
No known key found for this signature in database
GPG key ID: B2F99ED770DC79EC

View file

@ -640,22 +640,47 @@ _XimRegCommitInfo(
} }
static void static void
_XimUnregCommitInfo( _XimUnregRealCommitInfo(
Xic ic) Xic ic,
Bool reverse)
{ {
XimCommitInfo info; XimCommitInfo info;
XimCommitInfo prev_info = NULL;
if (!(info = ic->private.proto.commit_info)) info = ic->private.proto.commit_info;
while (reverse && info) {
if (!info->next)
break;
prev_info = info;
info = info->next;
}
if (!info)
return; return;
Xfree(info->string); Xfree(info->string);
Xfree(info->keysym); Xfree(info->keysym);
ic->private.proto.commit_info = info->next; if (prev_info)
prev_info->next = info->next;
else
ic->private.proto.commit_info = info->next;
Xfree(info); Xfree(info);
return; return;
} }
static void
_XimUnregCommitInfo(
Xic ic)
{
_XimUnregRealCommitInfo(ic, False);
}
static void
_XimUnregFirstCommitInfo(
Xic ic)
{
_XimUnregRealCommitInfo(ic, True);
}
void void
_XimFreeCommitInfo( _XimFreeCommitInfo(
Xic ic) Xic ic)
@ -665,6 +690,19 @@ _XimFreeCommitInfo(
return; return;
} }
static XimCommitInfo
_XimFirstCommitInfo(
Xic ic)
{
XimCommitInfo info = ic->private.proto.commit_info;
while (info) {
if (!info->next)
break;
info = info->next;
}
return info;
}
static Bool static Bool
_XimProcKeySym( _XimProcKeySym(
Xic ic, Xic ic,
@ -1059,7 +1097,7 @@ _XimProtoMbLookupString(
state = &tmp_state; state = &tmp_state;
if ((ev->type == KeyPress) && (ev->keycode == 0)) { /* Filter function */ if ((ev->type == KeyPress) && (ev->keycode == 0)) { /* Filter function */
if (!(info = ic->private.proto.commit_info)) { if (!(info = _XimFirstCommitInfo(ic))) {
*state = XLookupNone; *state = XLookupNone;
return 0; return 0;
} }
@ -1075,7 +1113,7 @@ _XimProtoMbLookupString(
else else
*state = XLookupKeySym; *state = XLookupKeySym;
} }
_XimUnregCommitInfo(ic); _XimUnregFirstCommitInfo(ic);
} else if (ev->type == KeyPress) { } else if (ev->type == KeyPress) {
ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL); ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL);
@ -1122,7 +1160,7 @@ _XimProtoWcLookupString(
state = &tmp_state; state = &tmp_state;
if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */ if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
if (!(info = ic->private.proto.commit_info)) { if (!(info = _XimFirstCommitInfo(ic))) {
*state = XLookupNone; *state = XLookupNone;
return 0; return 0;
} }
@ -1138,7 +1176,7 @@ _XimProtoWcLookupString(
else else
*state = XLookupKeySym; *state = XLookupKeySym;
} }
_XimUnregCommitInfo(ic); _XimUnregFirstCommitInfo(ic);
} else if (ev->type == KeyPress) { } else if (ev->type == KeyPress) {
ret = _XimLookupWCText(ic, ev, buffer, bytes, keysym, NULL); ret = _XimLookupWCText(ic, ev, buffer, bytes, keysym, NULL);
@ -1185,7 +1223,7 @@ _XimProtoUtf8LookupString(
state = &tmp_state; state = &tmp_state;
if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */ if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
if (!(info = ic->private.proto.commit_info)) { if (!(info = _XimFirstCommitInfo(ic))) {
*state = XLookupNone; *state = XLookupNone;
return 0; return 0;
} }
@ -1201,7 +1239,7 @@ _XimProtoUtf8LookupString(
else else
*state = XLookupKeySym; *state = XLookupKeySym;
} }
_XimUnregCommitInfo(ic); _XimUnregFirstCommitInfo(ic);
} else if (ev->type == KeyPress) { } else if (ev->type == KeyPress) {
ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL); ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL);