| 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 | * Author: Peter Hutterer |
| 24 | */ |
| 25 | |
| 26 | /*********************************************************************** |
| 27 | * |
| 28 | * Request to allow some device events. |
| 29 | * |
| 30 | */ |
| 31 | |
| 32 | #ifdef HAVE_DIX_CONFIG_H |
| 33 | #include <dix-config.h> |
| 34 | #endif |
| 35 | |
| 36 | #include "inputstr.h" /* DeviceIntPtr */ |
| 37 | #include "windowstr.h" /* window structure */ |
| 38 | #include "mi.h" |
| 39 | #include "eventstr.h" |
| 40 | #include <X11/extensions/XI2.h> |
| 41 | #include <X11/extensions/XI2proto.h> |
| 42 | |
| 43 | #include "exglobals.h" /* BadDevice */ |
| 44 | #include "exevents.h" |
| 45 | #include "xiallowev.h" |
| 46 | |
| 47 | int |
| 48 | SProcXIAllowEvents(ClientPtr client) |
| 49 | { |
| 50 | REQUEST(xXIAllowEventsReq); |
| 51 | |
| 52 | swaps(&stuff->length); |
| 53 | swaps(&stuff->deviceid); |
| 54 | swapl(&stuff->time); |
| 55 | if (stuff->length > 3) { |
| 56 | xXI2_2AllowEventsReq *req_xi22 = (xXI2_2AllowEventsReq *) stuff; |
| 57 | |
| 58 | swapl(&req_xi22->touchid); |
| 59 | swapl(&req_xi22->grab_window); |
| 60 | } |
| 61 | |
| 62 | return ProcXIAllowEvents(client); |
| 63 | } |
| 64 | |
| 65 | int |
| 66 | ProcXIAllowEvents(ClientPtr client) |
| 67 | { |
| 68 | TimeStamp time; |
| 69 | DeviceIntPtr dev; |
| 70 | int ret = Success; |
| 71 | XIClientPtr xi_client; |
| 72 | Bool have_xi22 = FALSE; |
| 73 | |
| 74 | REQUEST(xXI2_2AllowEventsReq); |
| 75 | |
| 76 | xi_client = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey); |
| 77 | |
| 78 | if (version_compare(xi_client->major_version, |
| 79 | xi_client->minor_version, 2, 2) >= 0) { |
| 80 | REQUEST_AT_LEAST_SIZE(xXI2_2AllowEventsReq); |
| 81 | have_xi22 = TRUE; |
| 82 | } |
| 83 | else { |
| 84 | REQUEST_AT_LEAST_SIZE(xXIAllowEventsReq); |
| 85 | } |
| 86 | |
| 87 | ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess); |
| 88 | if (ret != Success) |
| 89 | return ret; |
| 90 | |
| 91 | time = ClientTimeToServerTime(stuff->time); |
| 92 | |
| 93 | switch (stuff->mode) { |
| 94 | case XIReplayDevice: |
| 95 | AllowSome(client, time, dev, NOT_GRABBED); |
| 96 | break; |
| 97 | case XISyncDevice: |
| 98 | AllowSome(client, time, dev, FREEZE_NEXT_EVENT); |
| 99 | break; |
| 100 | case XIAsyncDevice: |
| 101 | AllowSome(client, time, dev, THAWED); |
| 102 | break; |
| 103 | case XIAsyncPairedDevice: |
| 104 | if (IsMaster(dev)) |
| 105 | AllowSome(client, time, dev, THAW_OTHERS); |
| 106 | break; |
| 107 | case XISyncPair: |
| 108 | if (IsMaster(dev)) |
| 109 | AllowSome(client, time, dev, FREEZE_BOTH_NEXT_EVENT); |
| 110 | break; |
| 111 | case XIAsyncPair: |
| 112 | if (IsMaster(dev)) |
| 113 | AllowSome(client, time, dev, THAWED_BOTH); |
| 114 | break; |
| 115 | case XIRejectTouch: |
| 116 | case XIAcceptTouch: |
| 117 | { |
| 118 | int rc; |
| 119 | WindowPtr win; |
| 120 | |
| 121 | if (!have_xi22) |
| 122 | return BadValue; |
| 123 | |
| 124 | rc = dixLookupWindow(&win, stuff->grab_window, client, DixReadAccess); |
| 125 | if (rc != Success) |
| 126 | return rc; |
| 127 | |
| 128 | ret = TouchAcceptReject(client, dev, stuff->mode, stuff->touchid, |
| 129 | stuff->grab_window, &client->errorValue); |
| 130 | } |
| 131 | break; |
| 132 | default: |
| 133 | client->errorValue = stuff->mode; |
| 134 | ret = BadValue; |
| 135 | } |
| 136 | |
| 137 | return ret; |
| 138 | } |