grabdev.c revision 6747b715
105b261ecSmrg/************************************************************ 205b261ecSmrg 305b261ecSmrgCopyright 1989, 1998 The Open Group 405b261ecSmrg 505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that 705b261ecSmrgthe above copyright notice appear in all copies and that both that 805b261ecSmrgcopyright notice and this permission notice appear in supporting 905b261ecSmrgdocumentation. 1005b261ecSmrg 1105b261ecSmrgThe above copyright notice and this permission notice shall be included in 1205b261ecSmrgall copies or substantial portions of the Software. 1305b261ecSmrg 1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2005b261ecSmrg 2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be 2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings 2305b261ecSmrgin this Software without prior written authorization from The Open Group. 2405b261ecSmrg 2505b261ecSmrgCopyright 1989 by Hewlett-Packard Company, Palo Alto, California. 2605b261ecSmrg 2705b261ecSmrg All Rights Reserved 2805b261ecSmrg 2905b261ecSmrgPermission to use, copy, modify, and distribute this software and its 3005b261ecSmrgdocumentation for any purpose and without fee is hereby granted, 3105b261ecSmrgprovided that the above copyright notice appear in all copies and that 3205b261ecSmrgboth that copyright notice and this permission notice appear in 3305b261ecSmrgsupporting documentation, and that the name of Hewlett-Packard not be 3405b261ecSmrgused in advertising or publicity pertaining to distribution of the 3505b261ecSmrgsoftware without specific, written prior permission. 3605b261ecSmrg 3705b261ecSmrgHEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 3805b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 3905b261ecSmrgHEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 4005b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 4105b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 4205b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 4305b261ecSmrgSOFTWARE. 4405b261ecSmrg 4505b261ecSmrg********************************************************/ 4605b261ecSmrg 4705b261ecSmrg/*********************************************************************** 4805b261ecSmrg * 4905b261ecSmrg * Extension function to grab an extension device. 5005b261ecSmrg * 5105b261ecSmrg */ 5205b261ecSmrg 5305b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 5405b261ecSmrg#include <dix-config.h> 5505b261ecSmrg#endif 5605b261ecSmrg 5705b261ecSmrg#include "inputstr.h" /* DeviceIntPtr */ 5805b261ecSmrg#include "windowstr.h" /* window structure */ 5905b261ecSmrg#include <X11/extensions/XI.h> 6005b261ecSmrg#include <X11/extensions/XIproto.h> 6105b261ecSmrg#include "exglobals.h" 6205b261ecSmrg#include "dixevents.h" /* GrabDevice */ 6305b261ecSmrg 6405b261ecSmrg#include "grabdev.h" 6505b261ecSmrg 6605b261ecSmrgextern XExtEventInfo EventInfo[]; 6705b261ecSmrgextern int ExtEventIndex; 6805b261ecSmrg 6905b261ecSmrg/*********************************************************************** 7005b261ecSmrg * 7105b261ecSmrg * Swap the request if the requestor has a different byte order than us. 7205b261ecSmrg * 7305b261ecSmrg */ 7405b261ecSmrg 7505b261ecSmrgint 7605b261ecSmrgSProcXGrabDevice(ClientPtr client) 7705b261ecSmrg{ 7805b261ecSmrg char n; 7905b261ecSmrg 8005b261ecSmrg REQUEST(xGrabDeviceReq); 8105b261ecSmrg swaps(&stuff->length, n); 8205b261ecSmrg REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); 8305b261ecSmrg swapl(&stuff->grabWindow, n); 8405b261ecSmrg swapl(&stuff->time, n); 8505b261ecSmrg swaps(&stuff->event_count, n); 8605b261ecSmrg 876747b715Smrg if (stuff->length != bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count) 8805b261ecSmrg return BadLength; 8905b261ecSmrg 9005b261ecSmrg SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count); 9105b261ecSmrg 9205b261ecSmrg return (ProcXGrabDevice(client)); 9305b261ecSmrg} 9405b261ecSmrg 9505b261ecSmrg/*********************************************************************** 9605b261ecSmrg * 9705b261ecSmrg * Grab an extension device. 9805b261ecSmrg * 9905b261ecSmrg */ 10005b261ecSmrg 10105b261ecSmrgint 10205b261ecSmrgProcXGrabDevice(ClientPtr client) 10305b261ecSmrg{ 1044642e01fSmrg int rc; 10505b261ecSmrg xGrabDeviceReply rep; 10605b261ecSmrg DeviceIntPtr dev; 1076747b715Smrg GrabMask mask; 10805b261ecSmrg struct tmask tmp[EMASKSIZE]; 10905b261ecSmrg 11005b261ecSmrg REQUEST(xGrabDeviceReq); 11105b261ecSmrg REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); 11205b261ecSmrg 1136747b715Smrg if (stuff->length != bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count) 1144642e01fSmrg return BadLength; 11505b261ecSmrg 11605b261ecSmrg rep.repType = X_Reply; 11705b261ecSmrg rep.RepType = X_GrabDevice; 11805b261ecSmrg rep.sequenceNumber = client->sequence; 11905b261ecSmrg rep.length = 0; 12005b261ecSmrg 1214642e01fSmrg rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess); 1224642e01fSmrg if (rc != Success) 1234642e01fSmrg return rc; 12405b261ecSmrg 1254642e01fSmrg if ((rc = CreateMaskFromList(client, (XEventClass *) & stuff[1], 1264642e01fSmrg stuff->event_count, tmp, dev, 1274642e01fSmrg X_GrabDevice)) != Success) 1284642e01fSmrg return rc; 12905b261ecSmrg 1306747b715Smrg mask.xi = tmp[stuff->deviceid].mask; 1316747b715Smrg 1326747b715Smrg rc = GrabDevice(client, dev, stuff->other_devices_mode, 1336747b715Smrg stuff->this_device_mode, stuff->grabWindow, 1344642e01fSmrg stuff->ownerEvents, stuff->time, 1356747b715Smrg &mask, GRABTYPE_XI, None, None, 1366747b715Smrg &rep.status); 1374642e01fSmrg 1384642e01fSmrg if (rc != Success) 1394642e01fSmrg return rc; 14005b261ecSmrg 14105b261ecSmrg WriteReplyToClient(client, sizeof(xGrabDeviceReply), &rep); 14205b261ecSmrg return Success; 14305b261ecSmrg} 14405b261ecSmrg 14505b261ecSmrg/*********************************************************************** 14605b261ecSmrg * 14705b261ecSmrg * This procedure creates an event mask from a list of XEventClasses. 14805b261ecSmrg * 1494642e01fSmrg * Procedure is as follows: 1504642e01fSmrg * An XEventClass is (deviceid << 8 | eventtype). For each entry in the list, 1514642e01fSmrg * get the device. Then run through all available event indices (those are 1524642e01fSmrg * set when XI starts up) and binary OR's the device's mask to whatever the 1534642e01fSmrg * event mask for the given event type was. 1544642e01fSmrg * If an error occurs, it is sent to the client. Errors are generated if 1554642e01fSmrg * - if the device given in the event classs is invalid 1564642e01fSmrg * - if the device in the class list is not the device given as parameter (no 1574642e01fSmrg * error if parameter is NULL) 1584642e01fSmrg * 1594642e01fSmrg * mask has to be size EMASKSIZE and pre-allocated. 1604642e01fSmrg * 1614642e01fSmrg * @param client The client to send the error to (if one occurs) 1624642e01fSmrg * @param list List of event classes as sent from the client. 1634642e01fSmrg * @param count Number of elements in list. 1644642e01fSmrg * @param mask Preallocated mask (size EMASKSIZE). 1654642e01fSmrg * @param dev The device we're creating masks for. 1664642e01fSmrg * @param req The request we're processing. Used to fill in error fields. 16705b261ecSmrg */ 16805b261ecSmrg 16905b261ecSmrgint 17005b261ecSmrgCreateMaskFromList(ClientPtr client, XEventClass * list, int count, 17105b261ecSmrg struct tmask *mask, DeviceIntPtr dev, int req) 17205b261ecSmrg{ 1734642e01fSmrg int rc, i, j; 17405b261ecSmrg int device; 17505b261ecSmrg DeviceIntPtr tdev; 17605b261ecSmrg 17705b261ecSmrg for (i = 0; i < EMASKSIZE; i++) { 17805b261ecSmrg mask[i].mask = 0; 17905b261ecSmrg mask[i].dev = NULL; 18005b261ecSmrg } 18105b261ecSmrg 18205b261ecSmrg for (i = 0; i < count; i++, list++) { 18305b261ecSmrg device = *list >> 8; 1846747b715Smrg if (device > 255) 18505b261ecSmrg return BadClass; 1864642e01fSmrg 1876747b715Smrg rc = dixLookupDevice(&tdev, device, client, DixUseAccess); 1884642e01fSmrg if (rc != BadDevice && rc != Success) 1894642e01fSmrg return rc; 1904642e01fSmrg if (rc == BadDevice || (dev != NULL && tdev != dev)) 19105b261ecSmrg return BadClass; 19205b261ecSmrg 19305b261ecSmrg for (j = 0; j < ExtEventIndex; j++) 19405b261ecSmrg if (EventInfo[j].type == (*list & 0xff)) { 19505b261ecSmrg mask[device].mask |= EventInfo[j].mask; 19605b261ecSmrg mask[device].dev = (Pointer) tdev; 19705b261ecSmrg break; 19805b261ecSmrg } 19905b261ecSmrg } 20005b261ecSmrg return Success; 20105b261ecSmrg} 20205b261ecSmrg 20305b261ecSmrg/*********************************************************************** 20405b261ecSmrg * 20505b261ecSmrg * This procedure writes the reply for the XGrabDevice function, 20605b261ecSmrg * if the client and server have a different byte ordering. 20705b261ecSmrg * 20805b261ecSmrg */ 20905b261ecSmrg 21005b261ecSmrgvoid 21105b261ecSmrgSRepXGrabDevice(ClientPtr client, int size, xGrabDeviceReply * rep) 21205b261ecSmrg{ 21305b261ecSmrg char n; 21405b261ecSmrg 21505b261ecSmrg swaps(&rep->sequenceNumber, n); 21605b261ecSmrg swapl(&rep->length, n); 21705b261ecSmrg WriteToClient(client, size, (char *)rep); 21805b261ecSmrg} 219