home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / server / xinput / xgrabdev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-18  |  5.1 KB  |  199 lines

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