xref: /OK3568_Linux_fs/external/xserver/hw/dmx/input/ChkNotMaskEv.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 1985, 1987, 1998  The Open Group
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission to use, copy, modify, distribute, and sell this software and its
5*4882a593Smuzhiyun  * documentation for any purpose is hereby granted without fee, provided that
6*4882a593Smuzhiyun  * the above copyright notice appear in all copies and that both that
7*4882a593Smuzhiyun  * copyright notice and this permission notice appear in supporting
8*4882a593Smuzhiyun  * documentation.
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * The above copyright notice and this permission notice shall be included in
11*4882a593Smuzhiyun  * all copies or substantial portions of the Software.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
16*4882a593Smuzhiyun  * OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
17*4882a593Smuzhiyun  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * Except as contained in this notice, the name of The Open Group shall not be
21*4882a593Smuzhiyun  * used in advertising or otherwise to promote the sale, use or other dealings
22*4882a593Smuzhiyun  * in this Software without prior written authorization from The Open Group.
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun /* $XFree86 */
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun  * Copyright 2002-2003 Red Hat Inc., Durham, North Carolina.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * All Rights Reserved.
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining
32*4882a593Smuzhiyun  * a copy of this software and associated documentation files (the
33*4882a593Smuzhiyun  * "Software"), to deal in the Software without restriction, including
34*4882a593Smuzhiyun  * without limitation on the rights to use, copy, modify, merge,
35*4882a593Smuzhiyun  * publish, distribute, sublicense, and/or sell copies of the Software,
36*4882a593Smuzhiyun  * and to permit persons to whom the Software is furnished to do so,
37*4882a593Smuzhiyun  * subject to the following conditions:
38*4882a593Smuzhiyun  *
39*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the
40*4882a593Smuzhiyun  * next paragraph) shall be included in all copies or substantial
41*4882a593Smuzhiyun  * portions of the Software.
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
44*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
46*4882a593Smuzhiyun  * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
47*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
48*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
49*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50*4882a593Smuzhiyun  * SOFTWARE.
51*4882a593Smuzhiyun  */
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /** \file
54*4882a593Smuzhiyun  * This file provides a #XCheckNotMaskEvent function that is derived
55*4882a593Smuzhiyun  * from the standard Xlib XCheckMaskEvent function. */
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun #ifdef HAVE_DMX_CONFIG_H
58*4882a593Smuzhiyun #include <dmx-config.h>
59*4882a593Smuzhiyun #endif
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun #include "dmx.h"
62*4882a593Smuzhiyun #include "ChkNotMaskEv.h"
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun extern long const _Xevent_to_mask[];
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /** Check existing events in queue to find if any match.  If so, return.
67*4882a593Smuzhiyun  * If not, flush buffer and see if any more events are readable. If one
68*4882a593Smuzhiyun  * matches, return.  If all else fails, tell the user no events found.
69*4882a593Smuzhiyun  */
70*4882a593Smuzhiyun Bool
XCheckNotMaskEvent(Display * dpy,long mask,XEvent * event)71*4882a593Smuzhiyun XCheckNotMaskEvent(Display * dpy, long mask, XEvent * event)
72*4882a593Smuzhiyun {
73*4882a593Smuzhiyun     register _XQEvent *prev, *qelt;
74*4882a593Smuzhiyun     unsigned long qe_serial = 0;
75*4882a593Smuzhiyun     int n;                      /* time through count */
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun     LockDisplay(dpy);
78*4882a593Smuzhiyun     prev = NULL;
79*4882a593Smuzhiyun     for (n = 3; --n >= 0;) {
80*4882a593Smuzhiyun         for (qelt = prev ? prev->next : dpy->head;
81*4882a593Smuzhiyun              qelt; prev = qelt, qelt = qelt->next) {
82*4882a593Smuzhiyun             if (qelt->event.type >= LASTEvent
83*4882a593Smuzhiyun                 || !(_Xevent_to_mask[qelt->event.type] & mask)) {
84*4882a593Smuzhiyun                 *event = qelt->event;
85*4882a593Smuzhiyun                 _XDeq(dpy, prev, qelt);
86*4882a593Smuzhiyun                 UnlockDisplay(dpy);
87*4882a593Smuzhiyun                 return True;
88*4882a593Smuzhiyun             }
89*4882a593Smuzhiyun         }
90*4882a593Smuzhiyun         if (prev)
91*4882a593Smuzhiyun             qe_serial = prev->qserial_num;
92*4882a593Smuzhiyun         switch (n) {
93*4882a593Smuzhiyun         case 2:
94*4882a593Smuzhiyun             _XEventsQueued(dpy, QueuedAfterReading);
95*4882a593Smuzhiyun             break;
96*4882a593Smuzhiyun         case 1:
97*4882a593Smuzhiyun             _XFlush(dpy);
98*4882a593Smuzhiyun             break;
99*4882a593Smuzhiyun         }
100*4882a593Smuzhiyun         if (prev && prev->qserial_num != qe_serial)
101*4882a593Smuzhiyun             /* another thread has snatched this event */
102*4882a593Smuzhiyun             prev = NULL;
103*4882a593Smuzhiyun     }
104*4882a593Smuzhiyun     UnlockDisplay(dpy);
105*4882a593Smuzhiyun     return False;
106*4882a593Smuzhiyun }
107