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

  1. /* $Header: xgrabdevk.c,v 1.8 91/05/05 18:29:28 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 a key on an extension device.
  30.  *
  31.  */
  32.  
  33. #define     NEED_EVENTS
  34. #define     NEED_REPLIES
  35. #include "X.h"                /* for inputstr.h    */
  36. #include "Xproto.h"            /* Request macro     */
  37. #include "inputstr.h"            /* DeviceIntPtr         */
  38. #include "windowstr.h"            /* window structure  */
  39. #include "XI.h"
  40. #include "XIproto.h"
  41.  
  42. extern    int         IReqCode;
  43. extern    int        BadClass;
  44. extern    int        BadDevice;
  45. extern    InputInfo    inputInfo;
  46. extern    void        (* ReplySwapVector[256]) ();
  47. DeviceIntPtr        LookupDeviceIntRec();
  48.  
  49. /***********************************************************************
  50.  *
  51.  * Handle requests from clients with a different byte order.
  52.  *
  53.  */
  54.  
  55. int
  56. SProcXGrabDeviceKey(client)
  57.     register ClientPtr client;
  58.     {
  59.     register char n;
  60.     register long *p;
  61.     register int i;
  62.  
  63.     REQUEST(xGrabDeviceKeyReq);
  64.     swaps(&stuff->length, n);
  65.     swapl(&stuff->grabWindow, n);
  66.     swaps(&stuff->modifiers, n);
  67.     swaps(&stuff->event_count, n);
  68.     p = (long *) &stuff[1];
  69.     for (i=0; i<stuff->event_count; i++)
  70.         {
  71.         swapl(p, n);
  72.     p++;
  73.         }
  74.     return(ProcXGrabDeviceKey(client));
  75.     }
  76.  
  77. /***********************************************************************
  78.  *
  79.  * Grab a key on an extension device.
  80.  *
  81.  */
  82.  
  83. int
  84. ProcXGrabDeviceKey(client)
  85.     ClientPtr client;
  86.     {
  87.     int            ret;
  88.     DeviceIntPtr     dev;
  89.     DeviceIntPtr     mdev;
  90.     XEventClass        *class;
  91.     struct tmask    tmp[EMASKSIZE];
  92.  
  93.     REQUEST(xGrabDeviceKeyReq);
  94.     REQUEST_AT_LEAST_SIZE(xGrabDeviceKeyReq);
  95.  
  96.     if (stuff->length !=(sizeof(xGrabDeviceKeyReq)>>2) + stuff->event_count)
  97.     {
  98.     SendErrorToClient (client, IReqCode, X_GrabDeviceKey, 0, BadLength);
  99.     return Success;
  100.     }
  101.  
  102.     dev = LookupDeviceIntRec (stuff->grabbed_device);
  103.     if (dev == NULL)
  104.     {
  105.     SendErrorToClient(client, IReqCode, X_GrabDeviceKey, 0, 
  106.         BadDevice);
  107.     return Success;
  108.     }
  109.  
  110.     if (stuff->modifier_device != UseXKeyboard)
  111.     {
  112.     mdev = LookupDeviceIntRec (stuff->modifier_device);
  113.     if (mdev == NULL)
  114.         {
  115.         SendErrorToClient(client, IReqCode, X_GrabDeviceKey, 0, 
  116.             BadDevice);
  117.         return Success;
  118.         }
  119.     if (mdev->key == NULL)
  120.         {
  121.         SendErrorToClient(client, IReqCode, X_GrabDeviceKey, 0, 
  122.         BadMatch);
  123.         return Success;
  124.         }
  125.     }
  126.     else
  127.     mdev = (DeviceIntPtr) LookupKeyboardDevice();
  128.  
  129.     class = (XEventClass *) (&stuff[1]);    /* first word of values */
  130.  
  131.     if ((ret = CreateMaskFromList (client, class, 
  132.     stuff->event_count, tmp, dev, X_GrabDeviceKey)) != Success)
  133.         return Success;
  134.  
  135.     ret = GrabKey(client, dev, stuff->this_device_mode, 
  136.     stuff->other_devices_mode, stuff->modifiers, mdev, stuff->key, 
  137.     stuff->grabWindow, stuff->ownerEvents, tmp[stuff->grabbed_device].mask);
  138.  
  139.     if (ret != Success)
  140.         {
  141.     SendErrorToClient(client, IReqCode, X_GrabDeviceKey, 0, ret);
  142.         return Success;
  143.         }
  144.  
  145.     return Success;
  146.     }
  147.