| 1 |
/* |
| 2 |
|
| 3 |
Copyright 1985, 1987, 1998 The Open Group |
| 4 |
|
| 5 |
Permission to use, copy, modify, distribute, and sell this software and its |
| 6 |
documentation for any purpose is hereby granted without fee, provided that |
| 7 |
the above copyright notice appear in all copies and that both that |
| 8 |
copyright notice and this permission notice appear in supporting |
| 9 |
documentation. |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be included in |
| 12 |
all copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 18 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 |
|
| 21 |
Except as contained in this notice, the name of The Open Group shall not be |
| 22 |
used in advertising or otherwise to promote the sale, use or other dealings |
| 23 |
in this Software without prior written authorization from The Open Group. |
| 24 |
|
| 25 |
*/ |
| 26 |
|
| 27 |
#ifdef HAVE_CONFIG_H |
| 28 |
#include <config.h> |
| 29 |
#endif |
| 30 |
#include "Xlibint.h" |
| 31 |
|
| 32 |
/* |
| 33 |
* Check existing events in queue to find if any match. If so, return. |
| 34 |
* If not, flush buffer and see if any more events are readable. If one |
| 35 |
* matches, return. If all else fails, tell the user no events found. |
| 36 |
*/ |
| 37 |
|
| 38 |
Bool XCheckIfEvent ( |
| 39 |
register Display *dpy, |
| 40 |
register XEvent *event, /* XEvent to be filled in. */ |
| 41 |
Bool (*predicate)( |
| 42 |
Display* /* display */, |
| 43 |
XEvent* /* event */, |
| 44 |
char* /* arg */ |
| 45 |
), /* function to call */ |
| 46 |
char *arg) |
| 47 |
{ |
| 48 |
register _XQEvent *prev, *qelt; |
| 49 |
unsigned long qe_serial = 0; |
| 50 |
int n; /* time through count */ |
| 51 |
|
| 52 |
LockDisplay(dpy); |
| 53 |
prev = NULL; |
| 54 |
for (n = 3; --n >= 0;) { |
| 55 |
for (qelt = prev ? prev->next : dpy->head; |
| 56 |
qelt; |
| 57 |
prev = qelt, qelt = qelt->next) { |
| 58 |
if(qelt->qserial_num > qe_serial |
| 59 |
&& (*predicate)(dpy, &qelt->event, arg)) { |
| 60 |
*event = qelt->event; |
| 61 |
_XDeq(dpy, prev, qelt); |
| 62 |
_XStoreEventCookie(dpy, event); |
| 63 |
UnlockDisplay(dpy); |
| 64 |
return True; |
| 65 |
} |
| 66 |
} |
| 67 |
if (prev) |
| 68 |
qe_serial = prev->qserial_num; |
| 69 |
switch (n) { |
| 70 |
case 2: |
| 71 |
_XEventsQueued(dpy, QueuedAfterReading); |
| 72 |
break; |
| 73 |
case 1: |
| 74 |
_XFlush(dpy); |
| 75 |
break; |
| 76 |
} |
| 77 |
if (prev && prev->qserial_num != qe_serial) |
| 78 |
/* another thread has snatched this event */ |
| 79 |
prev = NULL; |
| 80 |
} |
| 81 |
UnlockDisplay(dpy); |
| 82 |
return False; |
| 83 |
} |
| 84 |
|
| 85 |
#ifdef NX_TRANS_SOCKET |
| 86 |
|
| 87 |
/* |
| 88 |
* This is just like XCheckIfEvent() but doesn't |
| 89 |
* flush the output buffer if it can't read new |
| 90 |
* events. |
| 91 |
*/ |
| 92 |
|
| 93 |
Bool XCheckIfEventNoFlush ( |
| 94 |
register Display *dpy, |
| 95 |
register XEvent *event, /* XEvent to be filled in. */ |
| 96 |
Bool (*predicate)( |
| 97 |
Display* /* display */, |
| 98 |
XEvent* /* event */, |
| 99 |
char* /* arg */ |
| 100 |
), /* function to call */ |
| 101 |
char *arg) |
| 102 |
|
| 103 |
{ |
| 104 |
register _XQEvent *prev, *qelt; |
| 105 |
unsigned long qe_serial = 0; |
| 106 |
int n; /* time through count */ |
| 107 |
|
| 108 |
LockDisplay(dpy); |
| 109 |
prev = NULL; |
| 110 |
for (n = 2; --n >= 0;) { |
| 111 |
for (qelt = prev ? prev->next : dpy->head; |
| 112 |
qelt; |
| 113 |
prev = qelt, qelt = qelt->next) { |
| 114 |
if(qelt->qserial_num > qe_serial |
| 115 |
&& (*predicate)(dpy, &qelt->event, arg)) { |
| 116 |
*event = qelt->event; |
| 117 |
_XDeq(dpy, prev, qelt); |
| 118 |
_XStoreEventCookie(dpy, event); |
| 119 |
UnlockDisplay(dpy); |
| 120 |
return True; |
| 121 |
} |
| 122 |
} |
| 123 |
if (prev) |
| 124 |
qe_serial = prev->qserial_num; |
| 125 |
switch (n) { |
| 126 |
case 1: |
| 127 |
_XEventsQueued(dpy, QueuedAfterReading); |
| 128 |
break; |
| 129 |
} |
| 130 |
if (prev && prev->qserial_num != qe_serial) |
| 131 |
/* another thread has snatched this event */ |
| 132 |
prev = NULL; |
| 133 |
} |
| 134 |
UnlockDisplay(dpy); |
| 135 |
return False; |
| 136 |
} |
| 137 |
|
| 138 |
#endif |