sync with OpenBSD -current

This commit is contained in:
purplerain 2024-08-06 22:23:11 +00:00
parent acb2a22980
commit 455fea1627
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
229 changed files with 25075 additions and 13981 deletions

View file

@ -341,6 +341,93 @@ _XimForwardEvent(
return _XimForwardEventCore(ic, ev, sync);
}
Bool
_XimFabricateSerial(
Xim im,
XKeyEvent *event)
{
/* GTK2 XIM module sets serial=0. */
if (!event->serial || !im->private.proto.enable_fabricated_order) {
MARK_FABRICATED(im);
return True;
}
if (event->serial == im->private.proto.fabricated_serial) {
fprintf(stderr, "%s,%d: The key event is already fabricated.\n", __FILE__, __LINE__);
return False;
}
if (im->private.proto.fabricated_serial)
fprintf(stderr, "%s,%d: Tried to fabricate a wrong key event.\n", __FILE__, __LINE__);
MARK_FABRICATED(im);
im->private.proto.fabricated_serial = event->serial;
im->private.proto.fabricated_time = event->time;
return True;
}
Bool
_XimUnfabricateSerial(
Xim im,
Xic ic,
XKeyEvent *event)
{
if (!im->private.proto.enable_fabricated_order) {
UNMARK_FABRICATED(im);
return True;
}
/* GTK2 XIM module sets serial=0. */
if (!event->serial) {
/* _XimCommitRecv() sets event->serial and call _XimFabricateSerial()
* but GTK2 XIM always reset event->serial=0 with XFilterEvent().
*/
if (ic && ic->private.proto.commit_info)
im->private.proto.fabricated_serial = 0;
UNMARK_FABRICATED(im);
return True;
}
if (!im->private.proto.fabricated_serial) {
fprintf(stderr, "%s,%d: The key event is already unfabricated.\n", __FILE__, __LINE__);
return False;
}
if (event->serial != im->private.proto.fabricated_serial)
fprintf(stderr, "%s,%d: Tried to unfabricate a wrong key event.\n", __FILE__, __LINE__);
im->private.proto.fabricated_serial = 0;
im->private.proto.fabricated_time = 0;
UNMARK_FABRICATED(im);
return True;
}
Bool
_XimIsFabricatedSerial(
Xim im,
XKeyEvent *event)
{
/* GTK2 XIM module sets serial=0. */
if (!event->serial || !im->private.proto.enable_fabricated_order)
return IS_FABRICATED(im) ? True : False;
if (event->serial == im->private.proto.fabricated_serial)
return True;
if (!im->private.proto.fabricated_serial)
return False;
/* Rotate time */
if (event->time < im->private.proto.fabricated_time) {
if (event->time >= 1000)
im->private.proto.fabricated_time = 0;
} else if (event->time - im->private.proto.fabricated_time > 1000) {
fprintf(stderr,
"%s,%d: The application disposed a key event with %ld serial.\n",
__FILE__, __LINE__,
im->private.proto.fabricated_serial);
im->private.proto.enable_fabricated_order = False;
if (IS_FABRICATED(im)) {
if (event->serial)
im->private.proto.fabricated_serial = event->serial;
return True;
}
}
return False;
}
static void
_XimProcEvent(
Display *d,
@ -355,7 +442,7 @@ _XimProcEvent(
ev->xany.serial |= serial << 16;
ev->xany.send_event = False;
ev->xany.display = d;
MARK_FABRICATED(ic->core.im);
_XimFabricateSerial((Xim)ic->core.im, &ev->xkey);
return;
}
@ -548,7 +635,7 @@ _XimTriggerNotify(
} else {
buf_size = len;
preply = Xmalloc(len);
ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
ret_code = _XimRead(im, &len, preply, buf_size,
_XimTriggerNotifyCheck, (XPointer)ic);
if(ret_code != XIM_TRUE) {
Xfree(preply);
@ -592,22 +679,47 @@ _XimRegCommitInfo(
}
static void
_XimUnregCommitInfo(
Xic ic)
_XimUnregRealCommitInfo(
Xic ic,
Bool reverse)
{
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;
Xfree(info->string);
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);
return;
}
static void
_XimUnregCommitInfo(
Xic ic)
{
_XimUnregRealCommitInfo(ic, False);
}
static void
_XimUnregFirstCommitInfo(
Xic ic)
{
_XimUnregRealCommitInfo(ic, True);
}
void
_XimFreeCommitInfo(
Xic ic)
@ -617,6 +729,19 @@ _XimFreeCommitInfo(
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
_XimProcKeySym(
Xic ic,
@ -704,10 +829,6 @@ _XimCommitRecv(
(void)_XimRespSyncReply(ic, flag);
if (ic->private.proto.registed_filter_event
& (KEYPRESS_MASK | KEYRELEASE_MASK))
MARK_FABRICATED(im);
bzero(&ev, sizeof(ev)); /* uninitialized : found when running kterm under valgrind */
ev.type = KeyPress;
@ -719,6 +840,10 @@ _XimCommitRecv(
ev.time = 0L;
ev.serial = LastKnownRequestProcessed(im->core.display);
if (ic->private.proto.registed_filter_event
& (KEYPRESS_MASK | KEYRELEASE_MASK))
_XimFabricateSerial(im, &ev);
/* FIXME :
I wish there were COMMENTs (!) about the data passed around.
*/
@ -1011,7 +1136,7 @@ _XimProtoMbLookupString(
state = &tmp_state;
if ((ev->type == KeyPress) && (ev->keycode == 0)) { /* Filter function */
if (!(info = ic->private.proto.commit_info)) {
if (!(info = _XimFirstCommitInfo(ic))) {
*state = XLookupNone;
return 0;
}
@ -1027,7 +1152,7 @@ _XimProtoMbLookupString(
else
*state = XLookupKeySym;
}
_XimUnregCommitInfo(ic);
_XimUnregFirstCommitInfo(ic);
} else if (ev->type == KeyPress) {
ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL);
@ -1074,7 +1199,7 @@ _XimProtoWcLookupString(
state = &tmp_state;
if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
if (!(info = ic->private.proto.commit_info)) {
if (!(info = _XimFirstCommitInfo(ic))) {
*state = XLookupNone;
return 0;
}
@ -1090,7 +1215,7 @@ _XimProtoWcLookupString(
else
*state = XLookupKeySym;
}
_XimUnregCommitInfo(ic);
_XimUnregFirstCommitInfo(ic);
} else if (ev->type == KeyPress) {
ret = _XimLookupWCText(ic, ev, buffer, bytes, keysym, NULL);
@ -1137,7 +1262,7 @@ _XimProtoUtf8LookupString(
state = &tmp_state;
if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
if (!(info = ic->private.proto.commit_info)) {
if (!(info = _XimFirstCommitInfo(ic))) {
*state = XLookupNone;
return 0;
}
@ -1153,7 +1278,7 @@ _XimProtoUtf8LookupString(
else
*state = XLookupKeySym;
}
_XimUnregCommitInfo(ic);
_XimUnregFirstCommitInfo(ic);
} else if (ev->type == KeyPress) {
ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL);