| 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 |
extern long const _Xevent_to_mask[]; |
| 33 |
#define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask) |
| 34 |
#define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\ |
| 35 |
Button4MotionMask|Button5MotionMask) |
| 36 |
|
| 37 |
/* |
| 38 |
* Check existing events in queue to find if any match. If so, return. |
| 39 |
* If not, flush buffer and see if any more events are readable. If one |
| 40 |
* matches, return. If all else fails, tell the user no events found. |
| 41 |
*/ |
| 42 |
|
| 43 |
Bool XCheckWindowEvent ( |
| 44 |
register Display *dpy, |
| 45 |
Window w, /* Selected window. */ |
| 46 |
long mask, /* Selected event mask. */ |
| 47 |
register XEvent *event) /* XEvent to be filled in. */ |
| 48 |
{ |
| 49 |
register _XQEvent *prev, *qelt; |
| 50 |
unsigned long qe_serial = 0; |
| 51 |
int n; /* time through count */ |
| 52 |
|
| 53 |
LockDisplay(dpy); |
| 54 |
|
| 55 |
/* Delete unclaimed cookies */ |
| 56 |
_XFreeEventCookies(dpy); |
| 57 |
|
| 58 |
prev = NULL; |
| 59 |
for (n = 3; --n >= 0;) { |
| 60 |
for (qelt = prev ? prev->next : dpy->head; |
| 61 |
qelt; |
| 62 |
prev = qelt, qelt = qelt->next) { |
| 63 |
if ((qelt->event.xany.window == w) && |
| 64 |
(qelt->event.type < GenericEvent) && |
| 65 |
(_Xevent_to_mask[qelt->event.type] & mask) && |
| 66 |
((qelt->event.type != MotionNotify) || |
| 67 |
(mask & AllPointers) || |
| 68 |
(mask & AllButtons & qelt->event.xmotion.state))) { |
| 69 |
*event = qelt->event; |
| 70 |
_XDeq(dpy, prev, qelt); |
| 71 |
UnlockDisplay(dpy); |
| 72 |
return True; |
| 73 |
} |
| 74 |
} |
| 75 |
if (prev) |
| 76 |
qe_serial = prev->qserial_num; |
| 77 |
switch (n) { |
| 78 |
case 2: |
| 79 |
_XEventsQueued(dpy, QueuedAfterReading); |
| 80 |
break; |
| 81 |
case 1: |
| 82 |
_XFlush(dpy); |
| 83 |
break; |
| 84 |
} |
| 85 |
if (prev && prev->qserial_num != qe_serial) |
| 86 |
/* another thread has snatched this event */ |
| 87 |
prev = NULL; |
| 88 |
} |
| 89 |
UnlockDisplay(dpy); |
| 90 |
return False; |
| 91 |
} |