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