1/* 2 3Copyright 1985, 1987, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in 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 38Bool XCheckTypedWindowEvent ( 39 register Display *dpy, 40 Window w, /* Selected window. */ 41 int type, /* Selected event type. */ 42 register XEvent *event) /* XEvent to be filled in. */ 43{ 44 register _XQEvent *prev, *qelt; 45 unsigned long qe_serial = 0; 46 int n; /* time through count */ 47 48 LockDisplay(dpy); 49 50 /* Delete unclaimed cookies */ 51 _XFreeEventCookies(dpy); 52 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->event.xany.window == w) && 59 (qelt->event.type == type)) { 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