diff --git a/modules/im/ximcp/imDefFlt.c b/modules/im/ximcp/imDefFlt.c index f89d2cb..44cc688 100644 --- a/modules/im/ximcp/imDefFlt.c +++ b/modules/im/ximcp/imDefFlt.c @@ -142,7 +142,7 @@ _XimProtoKeypressFilter( { Xim im = (Xim)ic->core.im; - if ((ev->keycode == 0) || IS_FABRICATED(im)) { + if (IS_FABRICATED(im)) { _XimPendingFilter(ic); UNMARK_FABRICATED(im); return NOTFILTERD; diff --git a/modules/im/ximcp/imDefFlt.c.dont-forward-keycode-0 b/modules/im/ximcp/imDefFlt.c.dont-forward-keycode-0 deleted file mode 100644 index 44cc688..0000000 --- a/modules/im/ximcp/imDefFlt.c.dont-forward-keycode-0 +++ /dev/null @@ -1,413 +0,0 @@ -/****************************************************************** - - Copyright 1992, 1993, 1994 by FUJITSU LIMITED - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and -that both that copyright notice and this permission notice appear -in supporting documentation, and that the name of FUJITSU LIMITED -not be used in advertising or publicity pertaining to distribution -of the software without specific, written prior permission. -FUJITSU LIMITED makes no representations about the suitability of -this software for any purpose. -It is provided "as is" without express or implied warranty. - -FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - - Author: Takashi Fujiwara FUJITSU LIMITED - fujiwara@a80.tech.yk.fujitsu.co.jp - -******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include "Xlibint.h" -#include "Xutil.h" -#include "Xlcint.h" -#include "Ximint.h" - -static long -_XimTriggerCheck( - Xim im, - XKeyEvent *ev, - INT32 len, - CARD32 *keylist) -{ - register long i; - KeySym keysym; - CARD32 buf32[BUFSIZE/4]; - char *buf = (char *)buf32; - int modifier; - int modifier_mask; - CARD32 min_len = sizeof(CARD32) /* sizeof keysym */ - + sizeof(CARD32) /* sizeof modifier */ - + sizeof(CARD32); /* sizeof modifier mask */ - - XLookupString(ev, buf, BUFSIZE, &keysym, NULL); - if (!keysym) - return -1; - - for (i = 0; len >= min_len; i += 3, len -= min_len) { - modifier = keylist[i + 1]; - modifier_mask = keylist[i + 2]; - if (((KeySym)keylist[i] == keysym) - && ((ev->state & modifier_mask) == modifier)) - return i; - } - return -1; -} - -static long -_XimTriggerOnCheck( - Xim im, - XKeyEvent *ev) -{ - return _XimTriggerCheck(im, ev, (INT32)im->private.proto.im_onkeylist[0], - &im->private.proto.im_onkeylist[1]); -} - -static long -_XimTriggerOffCheck( - Xim im, - XKeyEvent *ev) -{ - return _XimTriggerCheck(im, ev, (INT32)im->private.proto.im_offkeylist[0], - &im->private.proto.im_offkeylist[1]); -} - -static Bool -_XimOnKeysCheck( - Xic ic, - XKeyEvent *ev) -{ - Xim im = (Xim)ic->core.im; - long idx; - - if (IS_DYNAMIC_EVENT_FLOW(ic->core.im) && - im->private.proto.im_onkeylist && - im->private.proto.im_onkeylist[0]) { - if ((idx = _XimTriggerOnCheck(im, ev)) >= 0) { - (void)_XimTriggerNotify(im, ic, 0, (CARD32)idx); /* Trigger on */ - return True; - } - } - return False; -} - -static Bool -_XimOffKeysCheck( - Xic ic, - XKeyEvent *ev) -{ - Xim im = (Xim)ic->core.im; - long idx; - - if (IS_DYNAMIC_EVENT_FLOW(ic->core.im) && - im->private.proto.im_offkeylist && - im->private.proto.im_offkeylist[0]) { - if ((idx = _XimTriggerOffCheck(im, ev)) >= 0) { - _XimTriggerNotify(im, ic, 1, (CARD32)idx); /* Trigger off */ - return True; - } - } - return False; -} - -static void -_XimPendingFilter( - Xic ic) -{ - Xim im = (Xim)ic->core.im; - - if (IS_NEED_SYNC_REPLY(im)) { - (void)_XimProcSyncReply(im, ic); - UNMARK_NEED_SYNC_REPLY(im); - } - return; -} - -static Bool -_XimProtoKeypressFilter( - Xic ic, - XKeyEvent *ev) -{ - Xim im = (Xim)ic->core.im; - - if (IS_FABRICATED(im)) { - _XimPendingFilter(ic); - UNMARK_FABRICATED(im); - return NOTFILTERD; - } - - if (IS_NEGLECT_EVENT(ic, KeyPressMask)) - return FILTERD; - -#ifdef XIM_CONNECTABLE - if (!IS_IC_CONNECTED(ic)) { - if (IS_CONNECTABLE(im)) { - if (_XimConnectServer(im)) { - if (!_XimReCreateIC(ic)) { - _XimDelayModeSetAttr(im); - return NOTFILTERD; - } - } else { - return NOTFILTERD; - } - } else { - return NOTFILTERD; - } - } -#else - if (!IS_IC_CONNECTED(ic)) - return NOTFILTERD; -#endif /* XIM_CONNECTABLE */ - - if (!IS_FORWARD_EVENT(ic, KeyPressMask)) { - if (_XimOnKeysCheck(ic, ev)) - return FILTERD; - return NOTFILTERD; - } - if (_XimOffKeysCheck(ic, ev)) - return FILTERD; - - if (_XimForwardEvent(ic, (XEvent *)ev, - IS_SYNCHRONOUS_EVENT(ic, KeyPressMask))) - return FILTERD; - - return NOTFILTERD; -} - -static Bool -_XimFilterKeypress( - Display *d, - Window w, - XEvent *ev, - XPointer client_data) -{ - return _XimProtoKeypressFilter((Xic)client_data, (XKeyEvent *)ev ); -} - -static Bool -_XimProtoKeyreleaseFilter( - Xic ic, - XKeyEvent *ev) -{ - Xim im = (Xim)ic->core.im; - - if (IS_FABRICATED(im)) { - _XimPendingFilter(ic); - UNMARK_FABRICATED(im); - return NOTFILTERD; - } - - if (IS_NEGLECT_EVENT(ic, KeyReleaseMask)) - return FILTERD; - -#ifdef XIM_CONNECTABLE - if (!IS_IC_CONNECTED(ic)) { - if (IS_CONNECTABLE(im)) { - if (_XimConnectServer(im)) { - if (!_XimReCreateIC(ic)) { - _XimDelayModeSetAttr(im); - return NOTFILTERD; - } - } else { - return NOTFILTERD; - } - } else { - return NOTFILTERD; - } - } -#else - if (!IS_IC_CONNECTED(ic)) - return NOTFILTERD; -#endif /* XIM_CONNECTABLE */ - - if (!IS_FORWARD_EVENT(ic, KeyReleaseMask)) { - if (_XimOnKeysCheck(ic, ev)) - return FILTERD; - return NOTFILTERD; - } - if (_XimOffKeysCheck(ic, ev)) - return FILTERD; - - if (_XimForwardEvent(ic, (XEvent *)ev, - IS_SYNCHRONOUS_EVENT(ic, KeyPressMask))) - return FILTERD; - - return NOTFILTERD; -} - -static Bool -_XimFilterKeyrelease( - Display *d, - Window w, - XEvent *ev, - XPointer client_data) -{ - return _XimProtoKeyreleaseFilter((Xic)client_data, (XKeyEvent *)ev); -} - -static void -_XimRegisterKeyPressFilter( - Xic ic) -{ - if (ic->core.focus_window) { - if (!(ic->private.proto.registed_filter_event & KEYPRESS_MASK)) { - _XRegisterFilterByType (ic->core.im->core.display, - ic->core.focus_window, - KeyPress, KeyPress, - _XimFilterKeypress, - (XPointer)ic); - ic->private.proto.registed_filter_event |= KEYPRESS_MASK; - } - } - return; -} - -static void -_XimRegisterKeyReleaseFilter( - Xic ic) -{ - if (ic->core.focus_window) { - if (!(ic->private.proto.registed_filter_event & KEYRELEASE_MASK)) { - _XRegisterFilterByType (ic->core.im->core.display, - ic->core.focus_window, - KeyRelease, KeyRelease, - _XimFilterKeyrelease, - (XPointer)ic); - ic->private.proto.registed_filter_event |= KEYRELEASE_MASK; - } - } - return; -} - -static void -_XimUnregisterKeyPressFilter( - Xic ic) -{ - if (ic->core.focus_window) { - if (ic->private.proto.registed_filter_event & KEYPRESS_MASK) { - _XUnregisterFilter (ic->core.im->core.display, - ic->core.focus_window, - _XimFilterKeypress, - (XPointer)ic); - ic->private.proto.registed_filter_event &= ~KEYPRESS_MASK; - } - } - return; -} - -static void -_XimUnregisterKeyReleaseFilter( - Xic ic) -{ - if (ic->core.focus_window) { - if (ic->private.proto.registed_filter_event & KEYRELEASE_MASK) { - _XUnregisterFilter (ic->core.im->core.display, - ic->core.focus_window, - _XimFilterKeyrelease, - (XPointer)ic); - ic->private.proto.registed_filter_event &= ~KEYRELEASE_MASK; - } - } - return; -} - -void -_XimRegisterFilter( - Xic ic) -{ - _XimRegisterKeyPressFilter(ic); - if (IS_FORWARD_EVENT(ic, KeyReleaseMask)) - _XimRegisterKeyReleaseFilter(ic); - return; -} - -void -_XimUnregisterFilter( - Xic ic) -{ - _XimUnregisterKeyPressFilter(ic); - _XimUnregisterKeyReleaseFilter(ic); - return; -} - -void -_XimReregisterFilter( - Xic ic) -{ - if (IS_FORWARD_EVENT(ic, KeyReleaseMask)) - _XimRegisterKeyReleaseFilter(ic); - else - _XimUnregisterKeyReleaseFilter(ic); - - return; -} - -static Bool -_XimFilterServerDestroy( - Display *d, - Window w, - XEvent *ev, - XPointer client_data) -{ - Xim im = (Xim)client_data; - - if (ev->type == DestroyNotify) { - UNMARK_SERVER_CONNECTED(im); -#ifdef XIM_CONNECTABLE - if (!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) { - _XimServerReconectableDestroy(); - return True; - } -#endif /* XIM_CONNECTABLE */ - _XimServerDestroy(im); - } - return True; -} - -void -_XimRegisterServerFilter( - Xim im) -{ - if (im->private.proto.im_window) { - if (!(im->private.proto.registed_filter_event & DESTROYNOTIFY_MASK)) { - _XRegisterFilterByMask(im->core.display, - im->private.proto.im_window, - StructureNotifyMask, - _XimFilterServerDestroy, - (XPointer)im); - XSelectInput(im->core.display, im->private.proto.im_window, - StructureNotifyMask); - im->private.proto.registed_filter_event |= DESTROYNOTIFY_MASK; - } - } - return; -} - -void -_XimUnregisterServerFilter( - Xim im) -{ - if (im->private.proto.im_window) { - if (im->private.proto.registed_filter_event & DESTROYNOTIFY_MASK) { - _XUnregisterFilter(im->core.display, - im->private.proto.im_window, - _XimFilterServerDestroy, - (XPointer)im); - im->private.proto.registed_filter_event &= ~DESTROYNOTIFY_MASK; - } - } - return; -} - diff --git a/modules/im/ximcp/imDefLkup.c b/modules/im/ximcp/imDefLkup.c index 18289a8..dea7f66 100644 --- a/modules/im/ximcp/imDefLkup.c +++ b/modules/im/ximcp/imDefLkup.c @@ -332,17 +332,6 @@ _XimForwardEvent( XEvent *ev, Bool sync) { - /* - * Don't forward a key event which has keycode=0. - * keycode=0 is reserved for special purpose to let Xmb/wcLookupString() - * functions know that there is a commited string available from IM. - */ - if (((ev->type == KeyPress) || (ev->type == KeyRelease))) { - if (((XKeyEvent *)ev)->keycode == 0) { - return True; - } - } - #ifdef EXT_FORWARD if (((ev->type == KeyPress) || (ev->type == KeyRelease))) if (_XimExtForwardKeyEvent(ic, (XKeyEvent *)ev, sync)) @@ -615,19 +604,6 @@ _XimUnregCommitInfo( Xfree(info->keysym); ic->private.proto.commit_info = info->next; Xfree(info); - - /* - * "Commit" uses fabricated flag to process a commited string - * from IM engine. - * Turn off the fabricated flag here (unregister the commited - * information function). Otherwise, next regular key press - * event will be ignored at _XimProtoKeypressFilter() and it - * will not be passed to IM engine. - */ - if (IS_FABRICATED(ic)) { - UNMARK_FABRICATED(ic); - } - return; } diff --git a/modules/im/ximcp/imDefLkup.c.dont-forward-keycode-0 b/modules/im/ximcp/imDefLkup.c.dont-forward-keycode-0 deleted file mode 100644 index dea7f66..0000000 --- a/modules/im/ximcp/imDefLkup.c.dont-forward-keycode-0 +++ /dev/null @@ -1,1178 +0,0 @@ -/****************************************************************** - - Copyright 1992, 1993, 1994 by FUJITSU LIMITED - -Permission to use, copy, modify, distribute, and sell this software -and its documentation for any purpose is hereby granted without fee, -provided that the above copyright notice appear in all copies and -that both that copyright notice and this permission notice appear -in supporting documentation, and that the name of FUJITSU LIMITED -not be used in advertising or publicity pertaining to distribution -of the software without specific, written prior permission. -FUJITSU LIMITED makes no representations about the suitability of -this software for any purpose. -It is provided "as is" without express or implied warranty. - -FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - - Author: Takashi Fujiwara FUJITSU LIMITED - fujiwara@a80.tech.yk.fujitsu.co.jp - -******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include "Xlibint.h" -#include "Xlcint.h" -#include "Ximint.h" - -Xic -_XimICOfXICID( - Xim im, - XICID icid) -{ - Xic pic; - - for (pic = (Xic)im->core.ic_chain; pic; pic = (Xic)pic->core.next) { - if (pic->private.proto.icid == icid) - return pic; - } - return (Xic)0; -} - -static void -_XimProcIMSetEventMask( - Xim im, - XPointer buf) -{ - EVENTMASK *buf_l = (EVENTMASK *)buf; - - im->private.proto.forward_event_mask = buf_l[0]; - im->private.proto.synchronous_event_mask = buf_l[1]; - return; -} - -static void -_XimProcICSetEventMask( - Xic ic, - XPointer buf) -{ - EVENTMASK *buf_l = (EVENTMASK *)buf; - - ic->private.proto.forward_event_mask = buf_l[0]; - ic->private.proto.synchronous_event_mask = buf_l[1]; - _XimReregisterFilter(ic); - return; -} - -Bool -_XimSetEventMaskCallback( - Xim xim, - INT16 len, - XPointer data, - XPointer call_data) -{ - CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE); - XIMID imid = buf_s[0]; - XICID icid = buf_s[1]; - Xim im = (Xim)call_data; - Xic ic; - - if (imid == im->private.proto.imid) { - if (icid) { - ic = _XimICOfXICID(im, icid); - _XimProcICSetEventMask(ic, (XPointer)&buf_s[2]); - } else { - _XimProcIMSetEventMask(im, (XPointer)&buf_s[2]); - } - return True; - } - return False; -} - -static Bool -_XimSyncCheck( - Xim im, - INT16 len, - XPointer data, - XPointer arg) -{ - Xic ic = (Xic)arg; - CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE); - CARD8 major_opcode = *((CARD8 *)data); - CARD8 minor_opcode = *((CARD8 *)data + 1); - XIMID imid = buf_s[0]; - XICID icid = buf_s[1]; - - if ((major_opcode == XIM_SYNC_REPLY) - && (minor_opcode == 0) - && (imid == im->private.proto.imid) - && (icid == ic->private.proto.icid)) - return True; - if ((major_opcode == XIM_ERROR) - && (minor_opcode == 0) - && (buf_s[2] & XIM_IMID_VALID) - && (imid == im->private.proto.imid) - && (buf_s[2] & XIM_ICID_VALID) - && (icid == ic->private.proto.icid)) - return True; - return False; -} - -Bool -_XimSync( - Xim im, - Xic ic) -{ - CARD32 buf32[BUFSIZE/4]; - CARD8 *buf = (CARD8 *)buf32; - CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; - INT16 len; - CARD32 reply32[BUFSIZE/4]; - char *reply = (char *)reply32; - XPointer preply; - int buf_size; - int ret_code; - - buf_s[0] = im->private.proto.imid; /* imid */ - buf_s[1] = ic->private.proto.icid; /* icid */ - - len = sizeof(CARD16) /* sizeof imid */ - + sizeof(CARD16); /* sizeof icid */ - - _XimSetHeader((XPointer)buf, XIM_SYNC, 0, &len); - if (!(_XimWrite(im, len, (XPointer)buf))) - return False; - _XimFlush(im); - buf_size = BUFSIZE; - ret_code = _XimRead(im, &len, (XPointer)reply, buf_size, - _XimSyncCheck, (XPointer)ic); - if(ret_code == XIM_TRUE) { - preply = reply; - } else if(ret_code == XIM_OVERFLOW) { - if(len <= 0) { - preply = reply; - } else { - buf_size = len; - preply = Xmalloc(len); - ret_code = _XimRead(im, &len, preply, buf_size, - _XimSyncCheck, (XPointer)ic); - if(ret_code != XIM_TRUE) { - Xfree(preply); - return False; - } - } - } else { - return False; - } - buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE); - if (*((CARD8 *)preply) == XIM_ERROR) { - _XimProcError(im, 0, (XPointer)&buf_s[3]); - if(reply != preply) - Xfree(preply); - return False; - } - if(reply != preply) - Xfree(preply); - return True; -} - -Bool -_XimProcSyncReply( - Xim im, - Xic ic) -{ - CARD32 buf32[BUFSIZE/4]; - CARD8 *buf = (CARD8 *)buf32; - CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; - INT16 len; - - buf_s[0] = im->private.proto.imid; /* imid */ - buf_s[1] = ic->private.proto.icid; /* icid */ - - len = sizeof(CARD16) /* sizeof imid */ - + sizeof(CARD16); /* sizeof icid */ - - _XimSetHeader((XPointer)buf, XIM_SYNC_REPLY, 0, &len); - if (!(_XimWrite(im, len, (XPointer)buf))) - return False; - _XimFlush(im); - return True; -} - -Bool -_XimRespSyncReply( - Xic ic, - BITMASK16 mode) -{ - if (mode & XimSYNCHRONUS) /* SYNC Request */ - MARK_NEED_SYNC_REPLY(ic->core.im); - - return True; -} - -Bool -_XimSyncCallback( - Xim xim, - INT16 len, - XPointer data, - XPointer call_data) -{ - CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE); - XIMID imid = buf_s[0]; - XICID icid = buf_s[1]; - Xim im = (Xim)call_data; - Xic ic; - - if ((imid == im->private.proto.imid) - && (ic = _XimICOfXICID(im, icid))) { - (void)_XimProcSyncReply(im, ic); - return True; - } - return False; -} - -static INT16 -_XimSetEventToWire( - XEvent *ev, - xEvent *event) -{ - if (!(_XimProtoEventToWire(ev, event, False))) - return 0; - event->u.u.sequenceNumber = - ((XAnyEvent *)ev)->serial & (unsigned long)0xffff; - return sz_xEvent; -} - -static Bool -_XimForwardEventCore( - Xic ic, - XEvent *ev, - Bool sync) -{ - Xim im = (Xim)ic->core.im; - CARD32 buf32[BUFSIZE/4]; - CARD8 *buf = (CARD8 *)buf32; - CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; - CARD32 reply32[BUFSIZE/4]; - char *reply = (char *)reply32; - XPointer preply; - int buf_size; - int ret_code; - INT16 len; - - bzero(buf32, sizeof(buf32)); /* valgrind noticed uninitialized memory use! */ - - if (!(len = _XimSetEventToWire(ev, (xEvent *)&buf_s[4]))) - return False; /* X event */ - - buf_s[0] = im->private.proto.imid; /* imid */ - buf_s[1] = ic->private.proto.icid; /* icid */ - buf_s[2] = sync ? XimSYNCHRONUS : 0; /* flag */ - buf_s[3] = - (CARD16)((((XAnyEvent *)ev)->serial & ~((unsigned long)0xffff)) >> 16); - /* serial number */ - - len += sizeof(CARD16) /* sizeof imid */ - + sizeof(CARD16) /* sizeof icid */ - + sizeof(BITMASK16) /* sizeof flag */ - + sizeof(CARD16); /* sizeof serila number */ - - _XimSetHeader((XPointer)buf, XIM_FORWARD_EVENT, 0, &len); - if (!(_XimWrite(im, len, (XPointer)buf))) - return False; - _XimFlush(im); - - if (sync) { - buf_size = BUFSIZE; - ret_code = _XimRead(im, &len, (XPointer)reply, buf_size, - _XimSyncCheck, (XPointer)ic); - if(ret_code == XIM_TRUE) { - preply = reply; - } else if(ret_code == XIM_OVERFLOW) { - if(len <= 0) { - preply = reply; - } else { - buf_size = len; - preply = Xmalloc(len); - ret_code = _XimRead(im, &len, preply, buf_size, - _XimSyncCheck, (XPointer)ic); - if(ret_code != XIM_TRUE) { - Xfree(preply); - return False; - } - } - } else { - return False; - } - buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE); - if (*((CARD8 *)preply) == XIM_ERROR) { - _XimProcError(im, 0, (XPointer)&buf_s[3]); - if(reply != preply) - Xfree(preply); - return False; - } - if(reply != preply) - Xfree(preply); - } - return True; -} - -Bool -_XimForwardEvent( - Xic ic, - XEvent *ev, - Bool sync) -{ -#ifdef EXT_FORWARD - if (((ev->type == KeyPress) || (ev->type == KeyRelease))) - if (_XimExtForwardKeyEvent(ic, (XKeyEvent *)ev, sync)) - return True; -#endif - return _XimForwardEventCore(ic, ev, sync); -} - -static void -_XimProcEvent( - Display *d, - Xic ic, - XEvent *ev, - CARD16 *buf) -{ - INT16 serial = buf[0]; - xEvent *xev = (xEvent *)&buf[1]; - - _XimProtoWireToEvent(ev, xev, False); - ev->xany.serial |= serial << 16; - ev->xany.send_event = False; - ev->xany.display = d; - MARK_FABRICATED(ic->core.im); - return; -} - -static Bool -_XimForwardEventRecv( - Xim im, - Xic ic, - XPointer buf) -{ - CARD16 *buf_s = (CARD16 *)buf; - Display *d = im->core.display; - XEvent ev; - - _XimProcEvent(d, ic, &ev, &buf_s[1]); - - (void)_XimRespSyncReply(ic, buf_s[0]); - - XPutBackEvent(d, &ev); - - return True; -} - -Bool -_XimForwardEventCallback( - Xim xim, - INT16 len, - XPointer data, - XPointer call_data) -{ - CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE); - XIMID imid = buf_s[0]; - XICID icid = buf_s[1]; - Xim im = (Xim)call_data; - Xic ic; - - if ((imid == im->private.proto.imid) - && (ic = _XimICOfXICID(im, icid))) { - (void)_XimForwardEventRecv(im, ic, (XPointer)&buf_s[2]); - return True; - } - return False; -} - -static Bool -_XimRegisterTriggerkey( - Xim im, - XPointer buf) -{ - CARD32 *buf_l = (CARD32 *)buf; - CARD32 len; - CARD32 *key; - - if (IS_DYNAMIC_EVENT_FLOW(im)) /* already Dynamic event flow mode */ - return True; - - /* - * register onkeylist - */ - - len = buf_l[0]; /* length of on-keys */ - len += sizeof(INT32); /* sizeof length of on-keys */ - - if (!(key = Xmalloc(len))) { - _XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); - return False; - } - memcpy((char *)key, (char *)buf_l, len); - im->private.proto.im_onkeylist = key; - - MARK_DYNAMIC_EVENT_FLOW(im); - - /* - * register offkeylist - */ - - buf_l = (CARD32 *)((char *)buf + len); - len = buf_l[0]; /* length of off-keys */ - len += sizeof(INT32); /* sizeof length of off-keys */ - - if (!(key = Xmalloc(len))) { - _XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); - return False; - } - - memcpy((char *)key, (char *)buf_l, len); - im->private.proto.im_offkeylist = key; - - return True; -} - -Bool -_XimRegisterTriggerKeysCallback( - Xim xim, - INT16 len, - XPointer data, - XPointer call_data) -{ - CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE); - Xim im = (Xim)call_data; - - (void )_XimRegisterTriggerkey(im, (XPointer)&buf_s[2]); - return True; -} - -EVENTMASK -_XimGetWindowEventmask( - Xic ic) -{ - Xim im = (Xim )ic->core.im; - XWindowAttributes atr; - - if (!XGetWindowAttributes(im->core.display, ic->core.focus_window, &atr)) - return 0; - return (EVENTMASK)atr.your_event_mask; -} - - -static Bool -_XimTriggerNotifyCheck( - Xim im, - INT16 len, - XPointer data, - XPointer arg) -{ - Xic ic = (Xic)arg; - CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE); - CARD8 major_opcode = *((CARD8 *)data); - CARD8 minor_opcode = *((CARD8 *)data + 1); - XIMID imid = buf_s[0]; - XICID icid = buf_s[1]; - - if ((major_opcode == XIM_TRIGGER_NOTIFY_REPLY) - && (minor_opcode == 0) - && (imid == im->private.proto.imid) - && (icid == ic->private.proto.icid)) - return True; - if ((major_opcode == XIM_ERROR) - && (minor_opcode == 0) - && (buf_s[2] & XIM_IMID_VALID) - && (imid == im->private.proto.imid) - && (buf_s[2] & XIM_ICID_VALID) - && (icid == ic->private.proto.icid)) - return True; - return False; -} - -Bool -_XimTriggerNotify( - Xim im, - Xic ic, - int mode, - CARD32 idx) -{ - CARD32 buf32[BUFSIZE/4]; - CARD8 *buf = (CARD8 *)buf32; - CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; - CARD32 *buf_l = (CARD32 *)&buf[XIM_HEADER_SIZE]; - CARD32 reply32[BUFSIZE/4]; - char *reply = (char *)reply32; - XPointer preply; - int buf_size; - int ret_code; - INT16 len; - EVENTMASK mask = _XimGetWindowEventmask(ic); - - buf_s[0] = im->private.proto.imid; /* imid */ - buf_s[1] = ic->private.proto.icid; /* icid */ - buf_l[1] = mode; /* flag */ - buf_l[2] = idx; /* index of keys list */ - buf_l[3] = mask; /* select-event-mask */ - - len = sizeof(CARD16) /* sizeof imid */ - + sizeof(CARD16) /* sizeof icid */ - + sizeof(CARD32) /* sizeof flag */ - + sizeof(CARD32) /* sizeof index of key list */ - + sizeof(EVENTMASK); /* sizeof select-event-mask */ - - _XimSetHeader((XPointer)buf, XIM_TRIGGER_NOTIFY, 0, &len); - if (!(_XimWrite(im, len, (XPointer)buf))) - return False; - _XimFlush(im); - buf_size = BUFSIZE; - ret_code = _XimRead(im, &len, (XPointer)reply, buf_size, - _XimTriggerNotifyCheck, (XPointer)ic); - if(ret_code == XIM_TRUE) { - preply = reply; - } else if(ret_code == XIM_OVERFLOW) { - if(len <= 0) { - preply = reply; - } else { - buf_size = len; - preply = Xmalloc(len); - ret_code = _XimRead(im, &len, (XPointer)reply, buf_size, - _XimTriggerNotifyCheck, (XPointer)ic); - if(ret_code != XIM_TRUE) { - Xfree(preply); - return False; - } - } - } else { - return False; - } - buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE); - if (*((CARD8 *)preply) == XIM_ERROR) { - _XimProcError(im, 0, (XPointer)&buf_s[3]); - if(reply != preply) - Xfree(preply); - return False; - } - if(reply != preply) - Xfree(preply); - return True; -} - -static Bool -_XimRegCommitInfo( - Xic ic, - char *string, - int string_len, - KeySym *keysym, - int keysym_len) -{ - XimCommitInfo info; - - if (!(info = Xmalloc(sizeof(XimCommitInfoRec)))) - return False; - info->string = string; - info->string_len = string_len; - info->keysym = keysym; - info->keysym_len = keysym_len; - info->next = ic->private.proto.commit_info; - ic->private.proto.commit_info = info; - return True; -} - -static void -_XimUnregCommitInfo( - Xic ic) -{ - XimCommitInfo info; - - if (!(info = ic->private.proto.commit_info)) - return; - - - Xfree(info->string); - Xfree(info->keysym); - ic->private.proto.commit_info = info->next; - Xfree(info); - return; -} - -void -_XimFreeCommitInfo( - Xic ic) -{ - while (ic->private.proto.commit_info) - _XimUnregCommitInfo(ic); - return; -} - -static Bool -_XimProcKeySym( - Xic ic, - CARD32 sym, - KeySym **xim_keysym, - int *xim_keysym_len) -{ - Xim im = (Xim)ic->core.im; - - if (!(*xim_keysym = Xmalloc(sizeof(KeySym)))) { - _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); - return False; - } - - **xim_keysym = (KeySym)sym; - *xim_keysym_len = 1; - - return True; -} - -static Bool -_XimProcCommit( - Xic ic, - BYTE *buf, - int len, - char **xim_string, - int *xim_string_len) -{ - Xim im = (Xim)ic->core.im; - char *string; - - if (!(string = Xmalloc(len + 1))) { - _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); - return False; - } - - (void)memcpy(string, (char *)buf, len); - string[len] = '\0'; - - *xim_string = string; - *xim_string_len = len; - return True; -} - -static Bool -_XimCommitRecv( - Xim im, - Xic ic, - XPointer buf) -{ - CARD16 *buf_s = (CARD16 *)buf; - BITMASK16 flag = buf_s[0]; - XKeyEvent ev; - char *string = NULL; - int string_len = 0; - KeySym *keysym = NULL; - int keysym_len = 0; - - if ((flag & XimLookupBoth) == XimLookupChars) { - if (!(_XimProcCommit(ic, (BYTE *)&buf_s[2], - (int)buf_s[1], &string, &string_len))) - return False; - - } else if ((flag & XimLookupBoth) == XimLookupKeySym) { - if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len))) - return False; - - } else if ((flag & XimLookupBoth) == XimLookupBoth) { - if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len))) - return False; - - if (!(_XimProcCommit(ic, (BYTE *)&buf_s[5], - (int)buf_s[4], &string, &string_len))) { - Xfree(keysym); - return False; - } - } - - if (!(_XimRegCommitInfo(ic, string, string_len, keysym, keysym_len))) { - Xfree(string); - Xfree(keysym); - _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); - return False; - } - - (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; - ev.send_event = False; - ev.display = im->core.display; - ev.window = ic->core.focus_window; - ev.keycode = 0; - ev.state = 0; - - ev.time = 0L; - ev.serial = LastKnownRequestProcessed(im->core.display); - /* FIXME : - I wish there were COMMENTs (!) about the data passed around. - */ -#if 0 - fprintf(stderr,"%s,%d: putback k press FIXED ev.time=0 ev.serial=%lu\n", __FILE__, __LINE__, ev.serial); -#endif - - XPutBackEvent(im->core.display, (XEvent *)&ev); - - return True; -} - -Bool -_XimCommitCallback( - Xim xim, - INT16 len, - XPointer data, - XPointer call_data) -{ - CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE); - XIMID imid = buf_s[0]; - XICID icid = buf_s[1]; - Xim im = (Xim)call_data; - Xic ic; - - if ((imid == im->private.proto.imid) - && (ic = _XimICOfXICID(im, icid))) { - (void)_XimCommitRecv(im, ic, (XPointer)&buf_s[2]); - return True; - } - return False; -} - -void -_XimProcError( - Xim im, - Xic ic, - XPointer data) -{ - return; -} - -Bool -_XimErrorCallback( - Xim xim, - INT16 len, - XPointer data, - XPointer call_data) -{ - CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE); - BITMASK16 flag = buf_s[2]; - XIMID imid; - XICID icid; - Xim im = (Xim)call_data; - Xic ic = NULL; - - if (flag & XIM_IMID_VALID) { - imid = buf_s[0]; - if (imid != im->private.proto.imid) - return False; - } - if (flag & XIM_ICID_VALID) { - icid = buf_s[1]; - if (!(ic = _XimICOfXICID(im, icid))) - return False; - } - _XimProcError(im, ic, (XPointer)&buf_s[3]); - - return True; -} - -Bool -_XimError( - Xim im, - Xic ic, - CARD16 error_code, - INT16 detail_length, - CARD16 type, - char *detail) -{ - CARD32 buf32[BUFSIZE/4]; - CARD8 *buf = (CARD8 *)buf32; - CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; - INT16 len = 0; - - buf_s[0] = im->private.proto.imid; /* imid */ - buf_s[2] = XIM_IMID_VALID; /* flag */ - if (ic) { - buf_s[1] = ic->private.proto.icid; /* icid */ - buf_s[2] |= XIM_ICID_VALID; /* flag */ - } - buf_s[3] = error_code; /* Error Code */ - buf_s[4] = detail_length; /* length of error detail */ - buf_s[5] = type; /* type of error detail */ - - if (detail_length && detail) { - len = detail_length; - memcpy((char *)&buf_s[6], detail, len); - XIM_SET_PAD(&buf_s[6], len); - } - - len += sizeof(CARD16) /* sizeof imid */ - + sizeof(CARD16) /* sizeof icid */ - + sizeof(BITMASK16) /* sizeof flag */ - + sizeof(CARD16) /* sizeof error_code */ - + sizeof(INT16) /* sizeof length of detail */ - + sizeof(CARD16); /* sizeof type */ - - _XimSetHeader((XPointer)buf, XIM_ERROR, 0, &len); - if (!(_XimWrite(im, len, (XPointer)buf))) - return False; - _XimFlush(im); - return True; -} - -static int -_Ximctsconvert( - XlcConv conv, - char *from, - int from_len, - char *to, - int to_len, - Status *state) -{ - int from_left; - int to_left; - int from_savelen; - int to_savelen; - int from_cnvlen; - int to_cnvlen; - char *from_buf; - char *to_buf; - char scratchbuf[BUFSIZ]; - Status tmp_state; - - if (!state) - state = &tmp_state; - - if (!conv || !from || !from_len) { - *state = XLookupNone; - return 0; - } - - /* Reset the converter. The CompoundText at 'from' starts in - initial state. */ - _XlcResetConverter(conv); - - from_left = from_len; - to_left = BUFSIZ; - from_cnvlen = 0; - to_cnvlen = 0; - for (;;) { - from_buf = &from[from_cnvlen]; - from_savelen = from_left; - to_buf = &scratchbuf[to_cnvlen]; - to_savelen = to_left; - if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left, - (XPointer *)&to_buf, &to_left, NULL, 0) < 0) { - *state = XLookupNone; - return 0; - } - from_cnvlen += (from_savelen - from_left); - to_cnvlen += (to_savelen - to_left); - if (from_left == 0) { - if (!to_cnvlen) { - *state = XLookupNone; - return 0; - } - break; - } - } - - if (!to || !to_len || (to_len < to_cnvlen)) { - *state = XBufferOverflow; - } else { - memcpy(to, scratchbuf, to_cnvlen); - *state = XLookupChars; - } - return to_cnvlen; -} - -int -_Ximctstombs(XIM xim, char *from, int from_len, - char *to, int to_len, Status *state) -{ - return _Ximctsconvert(((Xim)xim)->private.proto.ctom_conv, - from, from_len, to, to_len, state); -} - -int -_Ximctstowcs( - XIM xim, - char *from, - int from_len, - wchar_t *to, - int to_len, - Status *state) -{ - Xim im = (Xim)xim; - XlcConv conv = im->private.proto.ctow_conv; - int from_left; - int to_left; - int from_savelen; - int to_savelen; - int from_cnvlen; - int to_cnvlen; - char *from_buf; - wchar_t *to_buf; - wchar_t scratchbuf[BUFSIZ]; - Status tmp_state; - - if (!state) - state = &tmp_state; - - if (!conv || !from || !from_len) { - *state = XLookupNone; - return 0; - } - - /* Reset the converter. The CompoundText at 'from' starts in - initial state. */ - _XlcResetConverter(conv); - - from_left = from_len; - to_left = BUFSIZ; - from_cnvlen = 0; - to_cnvlen = 0; - for (;;) { - from_buf = &from[from_cnvlen]; - from_savelen = from_left; - to_buf = &scratchbuf[to_cnvlen]; - to_savelen = to_left; - if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left, - (XPointer *)&to_buf, &to_left, NULL, 0) < 0) { - *state = XLookupNone; - return 0; - } - from_cnvlen += (from_savelen - from_left); - to_cnvlen += (to_savelen - to_left); - if (from_left == 0) { - if (!to_cnvlen){ - *state = XLookupNone; - return 0; - } - break; - } - } - - if (!to || !to_len || (to_len < to_cnvlen)) { - *state = XBufferOverflow; - } else { - memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t)); - *state = XLookupChars; - } - return to_cnvlen; -} - -int -_Ximctstoutf8( - XIM xim, - char *from, - int from_len, - char *to, - int to_len, - Status *state) -{ - return _Ximctsconvert(((Xim)xim)->private.proto.ctoutf8_conv, - from, from_len, to, to_len, state); -} - -int -_XimProtoMbLookupString( - XIC xic, - XKeyEvent *ev, - char *buffer, - int bytes, - KeySym *keysym, - Status *state) -{ - Xic ic = (Xic)xic; - Xim im = (Xim)ic->core.im; - int ret; - Status tmp_state; - XimCommitInfo info; - - if (!IS_SERVER_CONNECTED(im)) - return 0; - - if (!state) - state = &tmp_state; - - if ((ev->type == KeyPress) && (ev->keycode == 0)) { /* Filter function */ - if (!(info = ic->private.proto.commit_info)) { - *state = XLookupNone; - return 0; - } - - ret = im->methods->ctstombs((XIM)im, info->string, - info->string_len, buffer, bytes, state); - if (*state == XBufferOverflow) - return ret; - if (keysym && (info->keysym && *(info->keysym))) { - *keysym = *(info->keysym); - if (*state == XLookupChars) - *state = XLookupBoth; - else - *state = XLookupKeySym; - } - _XimUnregCommitInfo(ic); - - } else if (ev->type == KeyPress) { - ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL); - if (ret > 0) { - if (ret > bytes) - *state = XBufferOverflow; - else if (keysym && *keysym != NoSymbol) - *state = XLookupBoth; - else - *state = XLookupChars; - } else { - if (keysym && *keysym != NoSymbol) - *state = XLookupKeySym; - else - *state = XLookupNone; - } - } else { - *state = XLookupNone; - ret = 0; - } - - return ret; -} - -int -_XimProtoWcLookupString( - XIC xic, - XKeyEvent *ev, - wchar_t *buffer, - int bytes, - KeySym *keysym, - Status *state) -{ - Xic ic = (Xic)xic; - Xim im = (Xim)ic->core.im; - int ret; - Status tmp_state; - XimCommitInfo info; - - if (!IS_SERVER_CONNECTED(im)) - return 0; - - if (!state) - state = &tmp_state; - - if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */ - if (!(info = ic->private.proto.commit_info)) { - *state = XLookupNone; - return 0; - } - - ret = im->methods->ctstowcs((XIM)im, info->string, - info->string_len, buffer, bytes, state); - if (*state == XBufferOverflow) - return ret; - if (keysym && (info->keysym && *(info->keysym))) { - *keysym = *(info->keysym); - if (*state == XLookupChars) - *state = XLookupBoth; - else - *state = XLookupKeySym; - } - _XimUnregCommitInfo(ic); - - } else if (ev->type == KeyPress) { - ret = _XimLookupWCText(ic, ev, buffer, bytes, keysym, NULL); - if (ret > 0) { - if (ret > bytes) - *state = XBufferOverflow; - else if (keysym && *keysym != NoSymbol) - *state = XLookupBoth; - else - *state = XLookupChars; - } else { - if (keysym && *keysym != NoSymbol) - *state = XLookupKeySym; - else - *state = XLookupNone; - } - } else { - *state = XLookupNone; - ret = 0; - } - - return ret; -} - -int -_XimProtoUtf8LookupString( - XIC xic, - XKeyEvent *ev, - char *buffer, - int bytes, - KeySym *keysym, - Status *state) -{ - Xic ic = (Xic)xic; - Xim im = (Xim)ic->core.im; - int ret; - Status tmp_state; - XimCommitInfo info; - - if (!IS_SERVER_CONNECTED(im)) - return 0; - - if (!state) - state = &tmp_state; - - if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */ - if (!(info = ic->private.proto.commit_info)) { - *state = XLookupNone; - return 0; - } - - ret = im->methods->ctstoutf8((XIM)im, info->string, - info->string_len, buffer, bytes, state); - if (*state == XBufferOverflow) - return ret; - if (keysym && (info->keysym && *(info->keysym))) { - *keysym = *(info->keysym); - if (*state == XLookupChars) - *state = XLookupBoth; - else - *state = XLookupKeySym; - } - _XimUnregCommitInfo(ic); - - } else if (ev->type == KeyPress) { - ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL); - if (ret > 0) { - if (ret > bytes) - *state = XBufferOverflow; - else if (keysym && *keysym != NoSymbol) - *state = XLookupBoth; - else - *state = XLookupChars; - } else { - if (keysym && *keysym != NoSymbol) - *state = XLookupKeySym; - else - *state = XLookupNone; - } - } else { - *state = XLookupNone; - ret = 0; - } - - return ret; -} diff --git a/src/CopyCmap.c b/src/CopyCmap.c index b37aba7..b4954b0 100644 --- a/src/CopyCmap.c +++ b/src/CopyCmap.c @@ -53,11 +53,6 @@ Colormap XCopyColormapAndFree( mid = req->mid = XAllocID(dpy); req->srcCmap = src_cmap; - /* re-lock the display to keep XID handling in sync */ - UnlockDisplay(dpy); - SyncHandle(); - LockDisplay(dpy); - #if XCMS _XcmsCopyCmapRecAndFree(dpy, src_cmap, mid); #endif diff --git a/src/CopyCmap.c.copycolormapandfree b/src/CopyCmap.c.copycolormapandfree deleted file mode 100644 index b4954b0..0000000 --- a/src/CopyCmap.c.copycolormapandfree +++ /dev/null @@ -1,64 +0,0 @@ -/* - -Copyright 1986, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - -*/ - -#ifdef HAVE_CONFIG_H -#include -#else -#define XCMS 1 -#endif -#include "Xlibint.h" - -#if XCMS -#include "Xcmsint.h" - -/* cmsCmap.c */ -extern XcmsCmapRec * _XcmsCopyCmapRecAndFree(Display *dpy, - Colormap src_cmap, - Colormap copy_cmap); -#endif - -Colormap XCopyColormapAndFree( - register Display *dpy, - Colormap src_cmap) -{ - Colormap mid; - register xCopyColormapAndFreeReq *req; - - LockDisplay(dpy); - GetReq(CopyColormapAndFree, req); - - mid = req->mid = XAllocID(dpy); - req->srcCmap = src_cmap; - -#if XCMS - _XcmsCopyCmapRecAndFree(dpy, src_cmap, mid); -#endif - - UnlockDisplay(dpy); - SyncHandle(); - - return(mid); -} diff --git a/src/xcb_io.c b/src/xcb_io.c index 2aacbda..6a12d15 100644 --- a/src/xcb_io.c +++ b/src/xcb_io.c @@ -201,10 +201,12 @@ static int handle_error(Display *dpy, xError *err, Bool in_XReply) } /* Widen a 32-bit sequence number into a 64bit (uint64_t) sequence number. + * Treating the comparison as a 1 and shifting it avoids a conditional branch. */ static void widen(uint64_t *wide, unsigned int narrow) { - *wide += (int32_t) (narrow - *wide); + uint64_t new = (*wide & ~((uint64_t)0xFFFFFFFFUL)) | narrow; + *wide = new + (((uint64_t)(new < *wide)) << 32); } /* Thread-safety rules: diff --git a/src/xcb_io.c.race b/src/xcb_io.c.race deleted file mode 100644 index 6a12d15..0000000 --- a/src/xcb_io.c.race +++ /dev/null @@ -1,793 +0,0 @@ -/* Copyright (C) 2003-2006 Jamey Sharp, Josh Triplett - * This file is licensed under the MIT license. See the file COPYING. */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "Xlibint.h" -#include "locking.h" -#include "Xprivate.h" -#include "Xxcbint.h" -#include - -#include -#ifdef HAVE_INTTYPES_H -#include -#endif -#include -#include -#include -#include -#include -#ifdef HAVE_SYS_SELECT_H -#include -#endif - -#define xcb_fail_assert(_message, _var) { \ - unsigned int _var = 1; \ - fprintf(stderr, "[xcb] Aborting, sorry about that.\n"); \ - assert(!_var); \ -} - -#define throw_thread_fail_assert(_message, _var) { \ - fprintf(stderr, "[xcb] " _message "\n"); \ - fprintf(stderr, "[xcb] Most likely this is a multi-threaded client " \ - "and XInitThreads has not been called\n"); \ - xcb_fail_assert(_message, _var); \ -} - -/* XXX: It would probably be most useful if we stored the last-processed - * request, so we could find the offender from the message. */ -#define throw_extlib_fail_assert(_message, _var) { \ - fprintf(stderr, "[xcb] " _message "\n"); \ - fprintf(stderr, "[xcb] This is most likely caused by a broken X " \ - "extension library\n"); \ - xcb_fail_assert(_message, _var); \ -} - -static void return_socket(void *closure) -{ - Display *dpy = closure; - InternalLockDisplay(dpy, /* don't skip user locks */ 0); - _XSend(dpy, NULL, 0); - dpy->bufmax = dpy->buffer; - UnlockDisplay(dpy); -} - -static void require_socket(Display *dpy) -{ - if(dpy->bufmax == dpy->buffer) - { - uint64_t sent; - int flags = 0; - /* if we don't own the event queue, we have to ask XCB - * to set our errors aside for us. */ - if(dpy->xcb->event_owner != XlibOwnsEventQueue) - flags = XCB_REQUEST_CHECKED; - if(!xcb_take_socket(dpy->xcb->connection, return_socket, dpy, - flags, &sent)) - _XIOError(dpy); - dpy->xcb->last_flushed = sent; - X_DPY_SET_REQUEST(dpy, sent); - dpy->bufmax = dpy->xcb->real_bufmax; - } -} - -/* Call internal connection callbacks for any fds that are currently - * ready to read. This function will not block unless one of the - * callbacks blocks. - * - * This code borrowed from _XWaitForReadable. Inverse call tree: - * _XRead - * _XWaitForWritable - * _XFlush - * _XSend - * _XEventsQueued - * _XReadEvents - * _XRead[0-9]+ - * _XAllocIDs - * _XReply - * _XEatData - * _XReadPad - */ -static void check_internal_connections(Display *dpy) -{ - struct _XConnectionInfo *ilist; - fd_set r_mask; - struct timeval tv; - int result; - int highest_fd = -1; - - if(dpy->flags & XlibDisplayProcConni || !dpy->im_fd_info) - return; - - FD_ZERO(&r_mask); - for(ilist = dpy->im_fd_info; ilist; ilist = ilist->next) - { - assert(ilist->fd >= 0); - FD_SET(ilist->fd, &r_mask); - if(ilist->fd > highest_fd) - highest_fd = ilist->fd; - } - assert(highest_fd >= 0); - - tv.tv_sec = 0; - tv.tv_usec = 0; - result = select(highest_fd + 1, &r_mask, NULL, NULL, &tv); - - if(result == -1) - { - if(errno == EINTR) - return; - _XIOError(dpy); - } - - for(ilist = dpy->im_fd_info; result && ilist; ilist = ilist->next) - if(FD_ISSET(ilist->fd, &r_mask)) - { - _XProcessInternalConnection(dpy, ilist); - --result; - } -} - -static PendingRequest *append_pending_request(Display *dpy, uint64_t sequence) -{ - PendingRequest *node = malloc(sizeof(PendingRequest)); - assert(node); - node->next = NULL; - node->sequence = sequence; - node->reply_waiter = 0; - if(dpy->xcb->pending_requests_tail) - { - if (XLIB_SEQUENCE_COMPARE(dpy->xcb->pending_requests_tail->sequence, - >=, node->sequence)) - throw_thread_fail_assert("Unknown sequence number " - "while appending request", - xcb_xlib_unknown_seq_number); - if (dpy->xcb->pending_requests_tail->next != NULL) - throw_thread_fail_assert("Unknown request in queue " - "while appending request", - xcb_xlib_unknown_req_pending); - dpy->xcb->pending_requests_tail->next = node; - } - else - dpy->xcb->pending_requests = node; - dpy->xcb->pending_requests_tail = node; - return node; -} - -static void dequeue_pending_request(Display *dpy, PendingRequest *req) -{ - if (req != dpy->xcb->pending_requests) - throw_thread_fail_assert("Unknown request in queue while " - "dequeuing", - xcb_xlib_unknown_req_in_deq); - - dpy->xcb->pending_requests = req->next; - if(!dpy->xcb->pending_requests) - { - if (req != dpy->xcb->pending_requests_tail) - throw_thread_fail_assert("Unknown request in queue " - "while dequeuing", - xcb_xlib_unknown_req_in_deq); - dpy->xcb->pending_requests_tail = NULL; - } - else if (XLIB_SEQUENCE_COMPARE(req->sequence, >=, - dpy->xcb->pending_requests->sequence)) - throw_thread_fail_assert("Unknown sequence number while " - "dequeuing request", - xcb_xlib_threads_sequence_lost); - - free(req); -} - -static int handle_error(Display *dpy, xError *err, Bool in_XReply) -{ - _XExtension *ext; - int ret_code; - /* Oddly, Xlib only allows extensions to suppress errors when - * those errors were seen by _XReply. */ - if(in_XReply) - /* - * we better see if there is an extension who may - * want to suppress the error. - */ - for(ext = dpy->ext_procs; ext; ext = ext->next) - if(ext->error && (*ext->error)(dpy, err, &ext->codes, &ret_code)) - return ret_code; - _XError(dpy, err); - return 0; -} - -/* Widen a 32-bit sequence number into a 64bit (uint64_t) sequence number. - * Treating the comparison as a 1 and shifting it avoids a conditional branch. - */ -static void widen(uint64_t *wide, unsigned int narrow) -{ - uint64_t new = (*wide & ~((uint64_t)0xFFFFFFFFUL)) | narrow; - *wide = new + (((uint64_t)(new < *wide)) << 32); -} - -/* Thread-safety rules: - * - * At most one thread can be reading from XCB's event queue at a time. - * If you are not the current event-reading thread and you need to find - * out if an event is available, you must wait. - * - * The same rule applies for reading replies. - * - * A single thread cannot be both the the event-reading and the - * reply-reading thread at the same time. - * - * We always look at both the current event and the first pending reply - * to decide which to process next. - * - * We always process all responses in sequence-number order, which may - * mean waiting for another thread (either the event_waiter or the - * reply_waiter) to handle an earlier response before we can process or - * return a later one. If so, we wait on the corresponding condition - * variable for that thread to process the response and wake us up. - */ - -static xcb_generic_reply_t *poll_for_event(Display *dpy, Bool queued_only) -{ - /* Make sure the Display's sequence numbers are valid */ - require_socket(dpy); - - /* Precondition: This thread can safely get events from XCB. */ - assert(dpy->xcb->event_owner == XlibOwnsEventQueue && !dpy->xcb->event_waiter); - - if(!dpy->xcb->next_event) { - if(queued_only) - dpy->xcb->next_event = xcb_poll_for_queued_event(dpy->xcb->connection); - else - dpy->xcb->next_event = xcb_poll_for_event(dpy->xcb->connection); - } - - if(dpy->xcb->next_event) - { - PendingRequest *req = dpy->xcb->pending_requests; - xcb_generic_event_t *event = dpy->xcb->next_event; - uint64_t event_sequence = X_DPY_GET_LAST_REQUEST_READ(dpy); - widen(&event_sequence, event->full_sequence); - if(!req || XLIB_SEQUENCE_COMPARE(event_sequence, <, req->sequence) - || (event->response_type != X_Error && event_sequence == req->sequence)) - { - uint64_t request = X_DPY_GET_REQUEST(dpy); - if (XLIB_SEQUENCE_COMPARE(event_sequence, >, request)) - { - throw_thread_fail_assert("Unknown sequence " - "number while " - "processing queue", - xcb_xlib_threads_sequence_lost); - } - X_DPY_SET_LAST_REQUEST_READ(dpy, event_sequence); - dpy->xcb->next_event = NULL; - return (xcb_generic_reply_t *) event; - } - } - return NULL; -} - -static xcb_generic_reply_t *poll_for_response(Display *dpy) -{ - void *response; - xcb_generic_error_t *error; - PendingRequest *req; - while(!(response = poll_for_event(dpy, False)) && - (req = dpy->xcb->pending_requests) && - !req->reply_waiter) - { - uint64_t request; - - if(!xcb_poll_for_reply64(dpy->xcb->connection, req->sequence, - &response, &error)) { - /* xcb_poll_for_reply64 may have read events even if - * there is no reply. */ - response = poll_for_event(dpy, True); - break; - } - - request = X_DPY_GET_REQUEST(dpy); - if(XLIB_SEQUENCE_COMPARE(req->sequence, >, request)) - { - throw_thread_fail_assert("Unknown sequence number " - "while awaiting reply", - xcb_xlib_threads_sequence_lost); - } - X_DPY_SET_LAST_REQUEST_READ(dpy, req->sequence); - if(response) - break; - dequeue_pending_request(dpy, req); - if(error) - return (xcb_generic_reply_t *) error; - } - return response; -} - -static void handle_response(Display *dpy, xcb_generic_reply_t *response, Bool in_XReply) -{ - _XAsyncHandler *async, *next; - switch(response->response_type) - { - case X_Reply: - for(async = dpy->async_handlers; async; async = next) - { - next = async->next; - if(async->handler(dpy, (xReply *) response, (char *) response, sizeof(xReply) + (response->length << 2), async->data)) - break; - } - break; - - case X_Error: - handle_error(dpy, (xError *) response, in_XReply); - break; - - default: /* event */ - /* GenericEvents may be > 32 bytes. In this case, the - * event struct is trailed by the additional bytes. the - * xcb_generic_event_t struct uses 4 bytes for internal - * numbering, so we need to shift the trailing data to - * be after the first 32 bytes. */ - if(response->response_type == GenericEvent && ((xcb_ge_event_t *) response)->length) - { - xcb_ge_event_t *event = (xcb_ge_event_t *) response; - memmove(&event->full_sequence, &event[1], event->length * 4); - } - _XEnq(dpy, (xEvent *) response); - break; - } - free(response); -} - -int _XEventsQueued(Display *dpy, int mode) -{ - xcb_generic_reply_t *response; - if(dpy->flags & XlibDisplayIOError) - return 0; - if(dpy->xcb->event_owner != XlibOwnsEventQueue) - return 0; - - if(mode == QueuedAfterFlush) - _XSend(dpy, NULL, 0); - else - check_internal_connections(dpy); - - /* If another thread is blocked waiting for events, then we must - * let that thread pick up the next event. Since it blocked, we - * can reasonably claim there are no new events right now. */ - if(!dpy->xcb->event_waiter) - { - while((response = poll_for_response(dpy))) - handle_response(dpy, response, False); - if(xcb_connection_has_error(dpy->xcb->connection)) - _XIOError(dpy); - } - return dpy->qlen; -} - -/* _XReadEvents - Flush the output queue, - * then read as many events as possible (but at least 1) and enqueue them - */ -void _XReadEvents(Display *dpy) -{ - xcb_generic_reply_t *response; - unsigned long serial; - - if(dpy->flags & XlibDisplayIOError) - return; - _XSend(dpy, NULL, 0); - if(dpy->xcb->event_owner != XlibOwnsEventQueue) - return; - check_internal_connections(dpy); - - serial = dpy->next_event_serial_num; - while(serial == dpy->next_event_serial_num || dpy->qlen == 0) - { - if(dpy->xcb->event_waiter) - { - ConditionWait(dpy, dpy->xcb->event_notify); - /* Maybe the other thread got us an event. */ - continue; - } - - if(!dpy->xcb->next_event) - { - xcb_generic_event_t *event; - dpy->xcb->event_waiter = 1; - UnlockDisplay(dpy); - event = xcb_wait_for_event(dpy->xcb->connection); - /* It appears that classic Xlib respected user - * locks when waking up after waiting for - * events. However, if this thread did not have - * any user locks, and another thread takes a - * user lock and tries to read events, then we'd - * deadlock. So we'll choose to let the thread - * that got in first consume events, despite the - * later thread's user locks. */ - InternalLockDisplay(dpy, /* ignore user locks */ 1); - dpy->xcb->event_waiter = 0; - ConditionBroadcast(dpy, dpy->xcb->event_notify); - if(!event) - _XIOError(dpy); - dpy->xcb->next_event = event; - } - - /* We've established most of the conditions for - * poll_for_response to return non-NULL. The exceptions - * are connection shutdown, and finding that another - * thread is waiting for the next reply we'd like to - * process. */ - - response = poll_for_response(dpy); - if(response) - handle_response(dpy, response, False); - else if(dpy->xcb->pending_requests->reply_waiter) - { /* need braces around ConditionWait */ - ConditionWait(dpy, dpy->xcb->reply_notify); - } - else - _XIOError(dpy); - } - - /* The preceding loop established that there is no - * event_waiter--unless we just called ConditionWait because of - * a reply_waiter, in which case another thread may have become - * the event_waiter while we slept unlocked. */ - if(!dpy->xcb->event_waiter) - while((response = poll_for_response(dpy))) - handle_response(dpy, response, False); - if(xcb_connection_has_error(dpy->xcb->connection)) - _XIOError(dpy); -} - -/* - * _XSend - Flush the buffer and send the client data. 32 bit word aligned - * transmission is used, if size is not 0 mod 4, extra bytes are transmitted. - * - * Note that the connection must not be read from once the data currently - * in the buffer has been written. - */ -void _XSend(Display *dpy, const char *data, long size) -{ - static const xReq dummy_request; - static char const pad[3]; - struct iovec vec[3]; - uint64_t requests; - uint64_t dpy_request; - _XExtension *ext; - xcb_connection_t *c = dpy->xcb->connection; - if(dpy->flags & XlibDisplayIOError) - return; - - if(dpy->bufptr == dpy->buffer && !size) - return; - - /* append_pending_request does not alter the dpy request number - * therefore we can get it outside of the loop and the if - */ - dpy_request = X_DPY_GET_REQUEST(dpy); - /* iff we asked XCB to set aside errors, we must pick those up - * eventually. iff there are async handlers, we may have just - * issued requests that will generate replies. in either case, - * we need to remember to check later. */ - if(dpy->xcb->event_owner != XlibOwnsEventQueue || dpy->async_handlers) - { - uint64_t sequence; - for(sequence = dpy->xcb->last_flushed + 1; sequence <= dpy_request; ++sequence) - append_pending_request(dpy, sequence); - } - requests = dpy_request - dpy->xcb->last_flushed; - dpy->xcb->last_flushed = dpy_request; - - vec[0].iov_base = dpy->buffer; - vec[0].iov_len = dpy->bufptr - dpy->buffer; - vec[1].iov_base = (char *)data; - vec[1].iov_len = size; - vec[2].iov_base = (char *)pad; - vec[2].iov_len = -size & 3; - - for(ext = dpy->flushes; ext; ext = ext->next_flush) - { - int i; - for(i = 0; i < 3; ++i) - if(vec[i].iov_len) - ext->before_flush(dpy, &ext->codes, vec[i].iov_base, vec[i].iov_len); - } - - if(xcb_writev(c, vec, 3, requests) < 0) - _XIOError(dpy); - dpy->bufptr = dpy->buffer; - dpy->last_req = (char *) &dummy_request; - - check_internal_connections(dpy); - - _XSetSeqSyncFunction(dpy); -} - -/* - * _XFlush - Flush the X request buffer. If the buffer is empty, no - * action is taken. - */ -void _XFlush(Display *dpy) -{ - require_socket(dpy); - _XSend(dpy, NULL, 0); - - _XEventsQueued(dpy, QueuedAfterReading); -} - -static const XID inval_id = ~0UL; - -void _XIDHandler(Display *dpy) -{ - if (dpy->xcb->next_xid == inval_id) - _XAllocIDs(dpy, &dpy->xcb->next_xid, 1); -} - -/* _XAllocID - resource ID allocation routine. */ -XID _XAllocID(Display *dpy) -{ - XID ret = dpy->xcb->next_xid; - assert (ret != inval_id); - dpy->xcb->next_xid = inval_id; - _XSetPrivSyncFunction(dpy); - return ret; -} - -/* _XAllocIDs - multiple resource ID allocation routine. */ -void _XAllocIDs(Display *dpy, XID *ids, int count) -{ - int i; -#ifdef XTHREADS - if (dpy->lock) - (*dpy->lock->user_lock_display)(dpy); - UnlockDisplay(dpy); -#endif - for (i = 0; i < count; i++) - ids[i] = xcb_generate_id(dpy->xcb->connection); -#ifdef XTHREADS - InternalLockDisplay(dpy, /* don't skip user locks */ 0); - if (dpy->lock) - (*dpy->lock->user_unlock_display)(dpy); -#endif -} - -static void _XFreeReplyData(Display *dpy, Bool force) -{ - if(!force && dpy->xcb->reply_consumed < dpy->xcb->reply_length) - return; - free(dpy->xcb->reply_data); - dpy->xcb->reply_data = NULL; -} - -/* - * _XReply - Wait for a reply packet and copy its contents into the - * specified rep. - * extra: number of 32-bit words expected after the reply - * discard: should I discard data following "extra" words? - */ -Status _XReply(Display *dpy, xReply *rep, int extra, Bool discard) -{ - xcb_generic_error_t *error; - xcb_connection_t *c = dpy->xcb->connection; - char *reply; - PendingRequest *current; - uint64_t dpy_request; - - if (dpy->xcb->reply_data) - throw_extlib_fail_assert("Extra reply data still left in queue", - xcb_xlib_extra_reply_data_left); - - if(dpy->flags & XlibDisplayIOError) - return 0; - - _XSend(dpy, NULL, 0); - dpy_request = X_DPY_GET_REQUEST(dpy); - if(dpy->xcb->pending_requests_tail - && dpy->xcb->pending_requests_tail->sequence == dpy_request) - current = dpy->xcb->pending_requests_tail; - else - current = append_pending_request(dpy, dpy_request); - /* Don't let any other thread get this reply. */ - current->reply_waiter = 1; - - while(1) - { - PendingRequest *req = dpy->xcb->pending_requests; - xcb_generic_reply_t *response; - - if(req != current && req->reply_waiter) - { - ConditionWait(dpy, dpy->xcb->reply_notify); - /* Another thread got this reply. */ - continue; - } - req->reply_waiter = 1; - UnlockDisplay(dpy); - response = xcb_wait_for_reply64(c, req->sequence, &error); - /* Any user locks on another thread must have been taken - * while we slept in xcb_wait_for_reply64. Classic Xlib - * ignored those user locks in this case, so we do too. */ - InternalLockDisplay(dpy, /* ignore user locks */ 1); - - /* We have the response we're looking for. Now, before - * letting anyone else process this sequence number, we - * need to process any events that should have come - * earlier. */ - - if(dpy->xcb->event_owner == XlibOwnsEventQueue) - { - xcb_generic_reply_t *event; - /* If some thread is already waiting for events, - * it will get the first one. That thread must - * process that event before we can continue. */ - /* FIXME: That event might be after this reply, - * and might never even come--or there might be - * multiple threads trying to get events. */ - while(dpy->xcb->event_waiter) - { /* need braces around ConditionWait */ - ConditionWait(dpy, dpy->xcb->event_notify); - } - while((event = poll_for_event(dpy, True))) - handle_response(dpy, event, True); - } - - req->reply_waiter = 0; - ConditionBroadcast(dpy, dpy->xcb->reply_notify); - dpy_request = X_DPY_GET_REQUEST(dpy); - if(XLIB_SEQUENCE_COMPARE(req->sequence, >, dpy_request)) { - throw_thread_fail_assert("Unknown sequence number " - "while processing reply", - xcb_xlib_threads_sequence_lost); - } - X_DPY_SET_LAST_REQUEST_READ(dpy, req->sequence); - if(!response) - dequeue_pending_request(dpy, req); - - if(req == current) - { - reply = (char *) response; - break; - } - - if(error) - handle_response(dpy, (xcb_generic_reply_t *) error, True); - else if(response) - handle_response(dpy, response, True); - } - check_internal_connections(dpy); - - if(dpy->xcb->next_event && dpy->xcb->next_event->response_type == X_Error) - { - xcb_generic_event_t *event = dpy->xcb->next_event; - uint64_t last_request_read = X_DPY_GET_LAST_REQUEST_READ(dpy); - uint64_t event_sequence = last_request_read; - widen(&event_sequence, event->full_sequence); - if(event_sequence == last_request_read) - { - error = (xcb_generic_error_t *) event; - dpy->xcb->next_event = NULL; - } - } - - if(error) - { - int ret_code; - - /* Xlib is evil and assumes that even errors will be - * copied into rep. */ - memcpy(rep, error, 32); - - /* do not die on "no such font", "can't allocate", - "can't grab" failures */ - switch(error->error_code) - { - case BadName: - switch(error->major_code) - { - case X_LookupColor: - case X_AllocNamedColor: - free(error); - return 0; - } - break; - case BadFont: - if(error->major_code == X_QueryFont) { - free(error); - return 0; - } - break; - case BadAlloc: - case BadAccess: - free(error); - return 0; - } - - ret_code = handle_error(dpy, (xError *) error, True); - free(error); - return ret_code; - } - - /* it's not an error, but we don't have a reply, so it's an I/O - * error. */ - if(!reply) - _XIOError(dpy); - - /* there's no error and we have a reply. */ - dpy->xcb->reply_data = reply; - dpy->xcb->reply_consumed = sizeof(xReply) + (extra * 4); - dpy->xcb->reply_length = sizeof(xReply); - if(dpy->xcb->reply_data[0] == 1) - dpy->xcb->reply_length += (((xcb_generic_reply_t *) dpy->xcb->reply_data)->length * 4); - - /* error: Xlib asks too much. give them what we can anyway. */ - if(dpy->xcb->reply_length < dpy->xcb->reply_consumed) - dpy->xcb->reply_consumed = dpy->xcb->reply_length; - - memcpy(rep, dpy->xcb->reply_data, dpy->xcb->reply_consumed); - _XFreeReplyData(dpy, discard); - return 1; -} - -int _XRead(Display *dpy, char *data, long size) -{ - assert(size >= 0); - if(size == 0) - return 0; - if(dpy->xcb->reply_data == NULL || - dpy->xcb->reply_consumed + size > dpy->xcb->reply_length) - throw_extlib_fail_assert("Too much data requested from _XRead", - xcb_xlib_too_much_data_requested); - memcpy(data, dpy->xcb->reply_data + dpy->xcb->reply_consumed, size); - dpy->xcb->reply_consumed += size; - _XFreeReplyData(dpy, False); - return 0; -} - -/* - * _XReadPad - Read bytes from the socket taking into account incomplete - * reads. If the number of bytes is not 0 mod 4, read additional pad - * bytes. - */ -void _XReadPad(Display *dpy, char *data, long size) -{ - _XRead(dpy, data, size); - dpy->xcb->reply_consumed += -size & 3; - _XFreeReplyData(dpy, False); -} - -/* Read and discard "n" 8-bit bytes of data */ -void _XEatData(Display *dpy, unsigned long n) -{ - dpy->xcb->reply_consumed += n; - _XFreeReplyData(dpy, False); -} - -/* - * Read and discard "n" 32-bit words of data - * Matches the units of the length field in X protocol replies, and provides - * a single implementation of overflow checking to avoid having to replicate - * those checks in every caller. - */ -void _XEatDataWords(Display *dpy, unsigned long n) -{ - if (n < ((INT_MAX - dpy->xcb->reply_consumed) >> 2)) - dpy->xcb->reply_consumed += (n << 2); - else - /* Overflow would happen, so just eat the rest of the reply */ - dpy->xcb->reply_consumed = dpy->xcb->reply_length; - _XFreeReplyData(dpy, False); -} - -unsigned long -_XNextRequest(Display *dpy) -{ - /* This will update dpy->request. The assumption is that the next thing - * that the application will do is make a request so there's little - * overhead. - */ - require_socket(dpy); - return NextRequest(dpy); -}