grabdev.c revision 05b261ec
1/************************************************************ 2 3Copyright 1989, 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 25Copyright 1989 by Hewlett-Packard Company, Palo Alto, California. 26 27 All Rights Reserved 28 29Permission to use, copy, modify, and distribute this software and its 30documentation for any purpose and without fee is hereby granted, 31provided that the above copyright notice appear in all copies and that 32both that copyright notice and this permission notice appear in 33supporting documentation, and that the name of Hewlett-Packard not be 34used in advertising or publicity pertaining to distribution of the 35software without specific, written prior permission. 36 37HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 38ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 39HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 40ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 41WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 42ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 43SOFTWARE. 44 45********************************************************/ 46 47/*********************************************************************** 48 * 49 * Extension function to grab an extension device. 50 * 51 */ 52 53#define NEED_EVENTS 54#define NEED_REPLIES 55#ifdef HAVE_DIX_CONFIG_H 56#include <dix-config.h> 57#endif 58 59#include <X11/X.h> /* for inputstr.h */ 60#include <X11/Xproto.h> /* Request macro */ 61#include "inputstr.h" /* DeviceIntPtr */ 62#include "windowstr.h" /* window structure */ 63#include <X11/extensions/XI.h> 64#include <X11/extensions/XIproto.h> 65#include "extnsionst.h" 66#include "extinit.h" /* LookupDeviceIntRec */ 67#include "exglobals.h" 68#include "dixevents.h" /* GrabDevice */ 69 70#include "grabdev.h" 71 72extern XExtEventInfo EventInfo[]; 73extern int ExtEventIndex; 74 75/*********************************************************************** 76 * 77 * Swap the request if the requestor has a different byte order than us. 78 * 79 */ 80 81int 82SProcXGrabDevice(ClientPtr client) 83{ 84 char n; 85 86 REQUEST(xGrabDeviceReq); 87 swaps(&stuff->length, n); 88 REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); 89 swapl(&stuff->grabWindow, n); 90 swapl(&stuff->time, n); 91 swaps(&stuff->event_count, n); 92 93 if (stuff->length != (sizeof(xGrabDeviceReq) >> 2) + stuff->event_count) 94 return BadLength; 95 96 SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count); 97 98 return (ProcXGrabDevice(client)); 99} 100 101/*********************************************************************** 102 * 103 * Grab an extension device. 104 * 105 */ 106 107int 108ProcXGrabDevice(ClientPtr client) 109{ 110 int error; 111 xGrabDeviceReply rep; 112 DeviceIntPtr dev; 113 struct tmask tmp[EMASKSIZE]; 114 115 REQUEST(xGrabDeviceReq); 116 REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); 117 118 if (stuff->length != (sizeof(xGrabDeviceReq) >> 2) + stuff->event_count) { 119 SendErrorToClient(client, IReqCode, X_GrabDevice, 0, BadLength); 120 return Success; 121 } 122 123 rep.repType = X_Reply; 124 rep.RepType = X_GrabDevice; 125 rep.sequenceNumber = client->sequence; 126 rep.length = 0; 127 128 dev = LookupDeviceIntRec(stuff->deviceid); 129 if (dev == NULL) { 130 SendErrorToClient(client, IReqCode, X_GrabDevice, 0, BadDevice); 131 return Success; 132 } 133 134 if (CreateMaskFromList(client, (XEventClass *) & stuff[1], 135 stuff->event_count, tmp, dev, 136 X_GrabDevice) != Success) 137 return Success; 138 139 error = GrabDevice(client, dev, stuff->this_device_mode, 140 stuff->other_devices_mode, stuff->grabWindow, 141 stuff->ownerEvents, stuff->time, 142 tmp[stuff->deviceid].mask, &rep.status); 143 144 if (error != Success) { 145 SendErrorToClient(client, IReqCode, X_GrabDevice, 0, error); 146 return Success; 147 } 148 WriteReplyToClient(client, sizeof(xGrabDeviceReply), &rep); 149 return Success; 150} 151 152/*********************************************************************** 153 * 154 * This procedure creates an event mask from a list of XEventClasses. 155 * 156 */ 157 158int 159CreateMaskFromList(ClientPtr client, XEventClass * list, int count, 160 struct tmask *mask, DeviceIntPtr dev, int req) 161{ 162 int i, j; 163 int device; 164 DeviceIntPtr tdev; 165 166 for (i = 0; i < EMASKSIZE; i++) { 167 mask[i].mask = 0; 168 mask[i].dev = NULL; 169 } 170 171 for (i = 0; i < count; i++, list++) { 172 device = *list >> 8; 173 if (device > 255) { 174 SendErrorToClient(client, IReqCode, req, 0, BadClass); 175 return BadClass; 176 } 177 tdev = LookupDeviceIntRec(device); 178 if (tdev == NULL || (dev != NULL && tdev != dev)) { 179 SendErrorToClient(client, IReqCode, req, 0, BadClass); 180 return BadClass; 181 } 182 183 for (j = 0; j < ExtEventIndex; j++) 184 if (EventInfo[j].type == (*list & 0xff)) { 185 mask[device].mask |= EventInfo[j].mask; 186 mask[device].dev = (Pointer) tdev; 187 break; 188 } 189 } 190 return Success; 191} 192 193/*********************************************************************** 194 * 195 * This procedure writes the reply for the XGrabDevice function, 196 * if the client and server have a different byte ordering. 197 * 198 */ 199 200void 201SRepXGrabDevice(ClientPtr client, int size, xGrabDeviceReply * rep) 202{ 203 char n; 204 205 swaps(&rep->sequenceNumber, n); 206 swapl(&rep->length, n); 207 WriteToClient(client, size, (char *)rep); 208} 209