1706f2543Smrg/************************************************************ 2706f2543Smrg 3706f2543SmrgCopyright 1989, 1998 The Open Group 4706f2543Smrg 5706f2543SmrgPermission to use, copy, modify, distribute, and sell this software and its 6706f2543Smrgdocumentation for any purpose is hereby granted without fee, provided that 7706f2543Smrgthe above copyright notice appear in all copies and that both that 8706f2543Smrgcopyright notice and this permission notice appear in supporting 9706f2543Smrgdocumentation. 10706f2543Smrg 11706f2543SmrgThe above copyright notice and this permission notice shall be included in 12706f2543Smrgall copies or substantial portions of the Software. 13706f2543Smrg 14706f2543SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15706f2543SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16706f2543SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17706f2543SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18706f2543SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19706f2543SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20706f2543Smrg 21706f2543SmrgExcept as contained in this notice, the name of The Open Group shall not be 22706f2543Smrgused in advertising or otherwise to promote the sale, use or other dealings 23706f2543Smrgin this Software without prior written authorization from The Open Group. 24706f2543Smrg 25706f2543SmrgCopyright 1989 by Hewlett-Packard Company, Palo Alto, California. 26706f2543Smrg 27706f2543Smrg All Rights Reserved 28706f2543Smrg 29706f2543SmrgPermission to use, copy, modify, and distribute this software and its 30706f2543Smrgdocumentation for any purpose and without fee is hereby granted, 31706f2543Smrgprovided that the above copyright notice appear in all copies and that 32706f2543Smrgboth that copyright notice and this permission notice appear in 33706f2543Smrgsupporting documentation, and that the name of Hewlett-Packard not be 34706f2543Smrgused in advertising or publicity pertaining to distribution of the 35706f2543Smrgsoftware without specific, written prior permission. 36706f2543Smrg 37706f2543SmrgHEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 38706f2543SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 39706f2543SmrgHEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 40706f2543SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 41706f2543SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 42706f2543SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 43706f2543SmrgSOFTWARE. 44706f2543Smrg 45706f2543Smrg********************************************************/ 46706f2543Smrg 47706f2543Smrg/*********************************************************************** 48706f2543Smrg * 49706f2543Smrg * Extension function to grab an extension device. 50706f2543Smrg * 51706f2543Smrg */ 52706f2543Smrg 53706f2543Smrg#ifdef HAVE_DIX_CONFIG_H 54706f2543Smrg#include <dix-config.h> 55706f2543Smrg#endif 56706f2543Smrg 57706f2543Smrg#include "inputstr.h" /* DeviceIntPtr */ 58706f2543Smrg#include "windowstr.h" /* window structure */ 59706f2543Smrg#include <X11/extensions/XI.h> 60706f2543Smrg#include <X11/extensions/XIproto.h> 61706f2543Smrg#include "exglobals.h" 62706f2543Smrg#include "dixevents.h" /* GrabDevice */ 63706f2543Smrg 64706f2543Smrg#include "grabdev.h" 65706f2543Smrg 66706f2543Smrgextern XExtEventInfo EventInfo[]; 67706f2543Smrgextern int ExtEventIndex; 68706f2543Smrg 69706f2543Smrg/*********************************************************************** 70706f2543Smrg * 71706f2543Smrg * Swap the request if the requestor has a different byte order than us. 72706f2543Smrg * 73706f2543Smrg */ 74706f2543Smrg 75706f2543Smrgint 76706f2543SmrgSProcXGrabDevice(ClientPtr client) 77706f2543Smrg{ 78706f2543Smrg char n; 79706f2543Smrg 80706f2543Smrg REQUEST(xGrabDeviceReq); 81706f2543Smrg swaps(&stuff->length, n); 82706f2543Smrg REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); 83706f2543Smrg swapl(&stuff->grabWindow, n); 84706f2543Smrg swapl(&stuff->time, n); 85706f2543Smrg swaps(&stuff->event_count, n); 86706f2543Smrg 87706f2543Smrg if (stuff->length != bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count) 88706f2543Smrg return BadLength; 89706f2543Smrg 90706f2543Smrg SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count); 91706f2543Smrg 92706f2543Smrg return (ProcXGrabDevice(client)); 93706f2543Smrg} 94706f2543Smrg 95706f2543Smrg/*********************************************************************** 96706f2543Smrg * 97706f2543Smrg * Grab an extension device. 98706f2543Smrg * 99706f2543Smrg */ 100706f2543Smrg 101706f2543Smrgint 102706f2543SmrgProcXGrabDevice(ClientPtr client) 103706f2543Smrg{ 104706f2543Smrg int rc; 105706f2543Smrg xGrabDeviceReply rep; 106706f2543Smrg DeviceIntPtr dev; 107706f2543Smrg GrabMask mask; 108706f2543Smrg struct tmask tmp[EMASKSIZE]; 109706f2543Smrg 110706f2543Smrg REQUEST(xGrabDeviceReq); 111706f2543Smrg REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); 112706f2543Smrg 113706f2543Smrg if (stuff->length != bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count) 114706f2543Smrg return BadLength; 115706f2543Smrg 116706f2543Smrg rep.repType = X_Reply; 117706f2543Smrg rep.RepType = X_GrabDevice; 118706f2543Smrg rep.sequenceNumber = client->sequence; 119706f2543Smrg rep.length = 0; 120706f2543Smrg 121706f2543Smrg rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess); 122706f2543Smrg if (rc != Success) 123706f2543Smrg return rc; 124706f2543Smrg 125706f2543Smrg if ((rc = CreateMaskFromList(client, (XEventClass *) & stuff[1], 126706f2543Smrg stuff->event_count, tmp, dev, 127706f2543Smrg X_GrabDevice)) != Success) 128706f2543Smrg return rc; 129706f2543Smrg 130706f2543Smrg mask.xi = tmp[stuff->deviceid].mask; 131706f2543Smrg 132706f2543Smrg rc = GrabDevice(client, dev, stuff->other_devices_mode, 133706f2543Smrg stuff->this_device_mode, stuff->grabWindow, 134706f2543Smrg stuff->ownerEvents, stuff->time, 135706f2543Smrg &mask, GRABTYPE_XI, None, None, 136706f2543Smrg &rep.status); 137706f2543Smrg 138706f2543Smrg if (rc != Success) 139706f2543Smrg return rc; 140706f2543Smrg 141706f2543Smrg WriteReplyToClient(client, sizeof(xGrabDeviceReply), &rep); 142706f2543Smrg return Success; 143706f2543Smrg} 144706f2543Smrg 145706f2543Smrg/*********************************************************************** 146706f2543Smrg * 147706f2543Smrg * This procedure creates an event mask from a list of XEventClasses. 148706f2543Smrg * 149706f2543Smrg * Procedure is as follows: 150706f2543Smrg * An XEventClass is (deviceid << 8 | eventtype). For each entry in the list, 151706f2543Smrg * get the device. Then run through all available event indices (those are 152706f2543Smrg * set when XI starts up) and binary OR's the device's mask to whatever the 153706f2543Smrg * event mask for the given event type was. 154706f2543Smrg * If an error occurs, it is sent to the client. Errors are generated if 155706f2543Smrg * - if the device given in the event classs is invalid 156706f2543Smrg * - if the device in the class list is not the device given as parameter (no 157706f2543Smrg * error if parameter is NULL) 158706f2543Smrg * 159706f2543Smrg * mask has to be size EMASKSIZE and pre-allocated. 160706f2543Smrg * 161706f2543Smrg * @param client The client to send the error to (if one occurs) 162706f2543Smrg * @param list List of event classes as sent from the client. 163706f2543Smrg * @param count Number of elements in list. 164706f2543Smrg * @param mask Preallocated mask (size EMASKSIZE). 165706f2543Smrg * @param dev The device we're creating masks for. 166706f2543Smrg * @param req The request we're processing. Used to fill in error fields. 167706f2543Smrg */ 168706f2543Smrg 169706f2543Smrgint 170706f2543SmrgCreateMaskFromList(ClientPtr client, XEventClass * list, int count, 171706f2543Smrg struct tmask *mask, DeviceIntPtr dev, int req) 172706f2543Smrg{ 173706f2543Smrg int rc, i, j; 174706f2543Smrg int device; 175706f2543Smrg DeviceIntPtr tdev; 176706f2543Smrg 177706f2543Smrg for (i = 0; i < EMASKSIZE; i++) { 178706f2543Smrg mask[i].mask = 0; 179706f2543Smrg mask[i].dev = NULL; 180706f2543Smrg } 181706f2543Smrg 182706f2543Smrg for (i = 0; i < count; i++, list++) { 183706f2543Smrg device = *list >> 8; 184706f2543Smrg if (device > 255) 185706f2543Smrg return BadClass; 186706f2543Smrg 187706f2543Smrg rc = dixLookupDevice(&tdev, device, client, DixUseAccess); 188706f2543Smrg if (rc != BadDevice && rc != Success) 189706f2543Smrg return rc; 190706f2543Smrg if (rc == BadDevice || (dev != NULL && tdev != dev)) 191706f2543Smrg return BadClass; 192706f2543Smrg 193706f2543Smrg for (j = 0; j < ExtEventIndex; j++) 194706f2543Smrg if (EventInfo[j].type == (*list & 0xff)) { 195706f2543Smrg mask[device].mask |= EventInfo[j].mask; 196706f2543Smrg mask[device].dev = (Pointer) tdev; 197706f2543Smrg break; 198706f2543Smrg } 199706f2543Smrg } 200706f2543Smrg return Success; 201706f2543Smrg} 202706f2543Smrg 203706f2543Smrg/*********************************************************************** 204706f2543Smrg * 205706f2543Smrg * This procedure writes the reply for the XGrabDevice function, 206706f2543Smrg * if the client and server have a different byte ordering. 207706f2543Smrg * 208706f2543Smrg */ 209706f2543Smrg 210706f2543Smrgvoid 211706f2543SmrgSRepXGrabDevice(ClientPtr client, int size, xGrabDeviceReply * rep) 212706f2543Smrg{ 213706f2543Smrg char n; 214706f2543Smrg 215706f2543Smrg swaps(&rep->sequenceNumber, n); 216706f2543Smrg swapl(&rep->length, n); 217706f2543Smrg WriteToClient(client, size, (char *)rep); 218706f2543Smrg} 219