grabdev.c revision ed6184df
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 5735c4bbdfSmrg#include "inputstr.h" /* DeviceIntPtr */ 5835c4bbdfSmrg#include "windowstr.h" /* window structure */ 5905b261ecSmrg#include <X11/extensions/XI.h> 6005b261ecSmrg#include <X11/extensions/XIproto.h> 6105b261ecSmrg#include "exglobals.h" 6235c4bbdfSmrg#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 751b5d61b8Smrgint _X_COLD 7605b261ecSmrgSProcXGrabDevice(ClientPtr client) 7705b261ecSmrg{ 7805b261ecSmrg REQUEST(xGrabDeviceReq); 7935c4bbdfSmrg swaps(&stuff->length); 8005b261ecSmrg REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); 8135c4bbdfSmrg swapl(&stuff->grabWindow); 8235c4bbdfSmrg swapl(&stuff->time); 8335c4bbdfSmrg swaps(&stuff->event_count); 8435c4bbdfSmrg 8535c4bbdfSmrg if (stuff->length != 8635c4bbdfSmrg bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count) 8735c4bbdfSmrg return BadLength; 8805b261ecSmrg 8905b261ecSmrg SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count); 9005b261ecSmrg 9105b261ecSmrg return (ProcXGrabDevice(client)); 9205b261ecSmrg} 9305b261ecSmrg 9405b261ecSmrg/*********************************************************************** 9505b261ecSmrg * 9605b261ecSmrg * Grab an extension device. 9705b261ecSmrg * 9805b261ecSmrg */ 9905b261ecSmrg 10005b261ecSmrgint 10105b261ecSmrgProcXGrabDevice(ClientPtr client) 10205b261ecSmrg{ 1034642e01fSmrg int rc; 10405b261ecSmrg xGrabDeviceReply rep; 10505b261ecSmrg DeviceIntPtr dev; 1066747b715Smrg GrabMask mask; 10705b261ecSmrg struct tmask tmp[EMASKSIZE]; 10805b261ecSmrg 10905b261ecSmrg REQUEST(xGrabDeviceReq); 11005b261ecSmrg REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); 11105b261ecSmrg 11235c4bbdfSmrg if (stuff->length != 11335c4bbdfSmrg bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count) 11435c4bbdfSmrg return BadLength; 11505b261ecSmrg 11635c4bbdfSmrg rep = (xGrabDeviceReply) { 11735c4bbdfSmrg .repType = X_Reply, 11835c4bbdfSmrg .RepType = X_GrabDevice, 11935c4bbdfSmrg .sequenceNumber = client->sequence, 12035c4bbdfSmrg .length = 0, 12135c4bbdfSmrg }; 12205b261ecSmrg 1234642e01fSmrg rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess); 1244642e01fSmrg if (rc != Success) 12535c4bbdfSmrg return rc; 12605b261ecSmrg 12735c4bbdfSmrg if ((rc = CreateMaskFromList(client, (XEventClass *) &stuff[1], 12835c4bbdfSmrg stuff->event_count, tmp, dev, 12935c4bbdfSmrg X_GrabDevice)) != Success) 13035c4bbdfSmrg return rc; 13105b261ecSmrg 1326747b715Smrg mask.xi = tmp[stuff->deviceid].mask; 1336747b715Smrg 1346747b715Smrg rc = GrabDevice(client, dev, stuff->other_devices_mode, 1356747b715Smrg stuff->this_device_mode, stuff->grabWindow, 13635c4bbdfSmrg stuff->ownerEvents, stuff->time, 13735c4bbdfSmrg &mask, XI, None, None, &rep.status); 1384642e01fSmrg 1394642e01fSmrg if (rc != Success) 14035c4bbdfSmrg return rc; 14105b261ecSmrg 14205b261ecSmrg WriteReplyToClient(client, sizeof(xGrabDeviceReply), &rep); 14305b261ecSmrg return Success; 14405b261ecSmrg} 14505b261ecSmrg 14605b261ecSmrg/*********************************************************************** 14705b261ecSmrg * 14805b261ecSmrg * This procedure creates an event mask from a list of XEventClasses. 14905b261ecSmrg * 1504642e01fSmrg * Procedure is as follows: 1514642e01fSmrg * An XEventClass is (deviceid << 8 | eventtype). For each entry in the list, 1524642e01fSmrg * get the device. Then run through all available event indices (those are 1534642e01fSmrg * set when XI starts up) and binary OR's the device's mask to whatever the 1544642e01fSmrg * event mask for the given event type was. 1554642e01fSmrg * If an error occurs, it is sent to the client. Errors are generated if 156ed6184dfSmrg * - if the device given in the event class is invalid 1574642e01fSmrg * - if the device in the class list is not the device given as parameter (no 1584642e01fSmrg * error if parameter is NULL) 1594642e01fSmrg * 1604642e01fSmrg * mask has to be size EMASKSIZE and pre-allocated. 1614642e01fSmrg * 1624642e01fSmrg * @param client The client to send the error to (if one occurs) 1634642e01fSmrg * @param list List of event classes as sent from the client. 1644642e01fSmrg * @param count Number of elements in list. 1654642e01fSmrg * @param mask Preallocated mask (size EMASKSIZE). 1664642e01fSmrg * @param dev The device we're creating masks for. 1674642e01fSmrg * @param req The request we're processing. Used to fill in error fields. 16805b261ecSmrg */ 16905b261ecSmrg 17005b261ecSmrgint 17105b261ecSmrgCreateMaskFromList(ClientPtr client, XEventClass * list, int count, 17235c4bbdfSmrg struct tmask *mask, DeviceIntPtr dev, int req) 17305b261ecSmrg{ 1744642e01fSmrg int rc, i, j; 17505b261ecSmrg int device; 17605b261ecSmrg DeviceIntPtr tdev; 17705b261ecSmrg 17835c4bbdfSmrg memset(mask, 0, EMASKSIZE * sizeof(struct tmask)); 17905b261ecSmrg 18005b261ecSmrg for (i = 0; i < count; i++, list++) { 18135c4bbdfSmrg device = *list >> 8; 18235c4bbdfSmrg if (device > 255) 18335c4bbdfSmrg return BadClass; 18435c4bbdfSmrg 18535c4bbdfSmrg rc = dixLookupDevice(&tdev, device, client, DixUseAccess); 18635c4bbdfSmrg if (rc != BadDevice && rc != Success) 18735c4bbdfSmrg return rc; 18835c4bbdfSmrg if (rc == BadDevice || (dev != NULL && tdev != dev)) 18935c4bbdfSmrg return BadClass; 19035c4bbdfSmrg 19135c4bbdfSmrg for (j = 0; j < ExtEventIndex; j++) 19235c4bbdfSmrg if (EventInfo[j].type == (*list & 0xff)) { 19335c4bbdfSmrg mask[device].mask |= EventInfo[j].mask; 19435c4bbdfSmrg mask[device].dev = (void *) tdev; 19535c4bbdfSmrg break; 19635c4bbdfSmrg } 19705b261ecSmrg } 19805b261ecSmrg return Success; 19905b261ecSmrg} 20005b261ecSmrg 20105b261ecSmrg/*********************************************************************** 20205b261ecSmrg * 20305b261ecSmrg * This procedure writes the reply for the XGrabDevice function, 20405b261ecSmrg * if the client and server have a different byte ordering. 20505b261ecSmrg * 20605b261ecSmrg */ 20705b261ecSmrg 2081b5d61b8Smrgvoid _X_COLD 20905b261ecSmrgSRepXGrabDevice(ClientPtr client, int size, xGrabDeviceReply * rep) 21005b261ecSmrg{ 21135c4bbdfSmrg swaps(&rep->sequenceNumber); 21235c4bbdfSmrg swapl(&rep->length); 21335c4bbdfSmrg WriteToClient(client, size, rep); 21405b261ecSmrg} 215