| 1 |
/* |
| 2 |
* Copyright © 2009 Red Hat, Inc. |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice (including the next |
| 12 |
* paragraph) shall be included in all copies or substantial portions of the |
| 13 |
* Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 |
* DEALINGS IN THE SOFTWARE. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
#if HAVE_CONFIG_H |
| 26 |
#include <config.h> |
| 27 |
#endif |
| 28 |
|
| 29 |
#include <stdint.h> |
| 30 |
#include <X11/Xlibint.h> |
| 31 |
#include <X11/extensions/XI2proto.h> |
| 32 |
#include <X11/extensions/XInput2.h> |
| 33 |
#include <X11/extensions/extutil.h> |
| 34 |
#include "XIint.h" |
| 35 |
|
| 36 |
/* for GetRequest() to work */ |
| 37 |
#define X_XI2_2AllowEvents X_XIAllowEvents |
| 38 |
|
| 39 |
static Status |
| 40 |
_XIAllowEvents(Display *dpy, int deviceid, int event_mode, Time time, |
| 41 |
unsigned int touchid, Window grab_window) |
| 42 |
{ |
| 43 |
Bool have_XI22 = False; |
| 44 |
xXIAllowEventsReq *req; |
| 45 |
xXI2_2AllowEventsReq *req_XI22; |
| 46 |
|
| 47 |
XExtDisplayInfo *extinfo = XInput_find_display(dpy); |
| 48 |
|
| 49 |
LockDisplay(dpy); |
| 50 |
if (_XiCheckExtInit(dpy, XInput_2_0, extinfo) == -1) |
| 51 |
return (NoSuchExtension); |
| 52 |
|
| 53 |
if (_XiCheckVersion(extinfo, XInput_2_2) >= 0) |
| 54 |
have_XI22 = True; |
| 55 |
|
| 56 |
if (have_XI22) |
| 57 |
{ |
| 58 |
GetReq(XI2_2AllowEvents, req_XI22); |
| 59 |
req = (xXIAllowEventsReq*)req_XI22; |
| 60 |
} else |
| 61 |
GetReq(XIAllowEvents, req); |
| 62 |
|
| 63 |
req->reqType = extinfo->codes->major_opcode; |
| 64 |
req->ReqType = X_XIAllowEvents; |
| 65 |
req->deviceid = deviceid; |
| 66 |
req->mode = event_mode; |
| 67 |
req->time = time; |
| 68 |
|
| 69 |
if (have_XI22) { |
| 70 |
req_XI22->touchid = touchid; |
| 71 |
req_XI22->grab_window = grab_window; |
| 72 |
} |
| 73 |
|
| 74 |
UnlockDisplay(dpy); |
| 75 |
SyncHandle(); |
| 76 |
return Success; |
| 77 |
} |
| 78 |
|
| 79 |
Status |
| 80 |
XIAllowEvents(Display *dpy, int deviceid, int event_mode, Time time) |
| 81 |
{ |
| 82 |
return _XIAllowEvents(dpy, deviceid, event_mode, time, 0, None); |
| 83 |
} |
| 84 |
|
| 85 |
Status |
| 86 |
XIAllowTouchEvents(Display *dpy, int deviceid, unsigned int touchid, |
| 87 |
Window grab_window, int event_mode) |
| 88 |
{ |
| 89 |
XExtDisplayInfo *extinfo = XInput_find_display(dpy); |
| 90 |
|
| 91 |
LockDisplay(dpy); |
| 92 |
if (_XiCheckExtInit(dpy, XInput_2_2, extinfo) == -1) |
| 93 |
return (NoSuchExtension); |
| 94 |
UnlockDisplay(dpy); |
| 95 |
|
| 96 |
return _XIAllowEvents(dpy, deviceid, event_mode, CurrentTime, touchid, grab_window); |
| 97 |
} |