home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / server / xinput / xgetbmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-02  |  3.7 KB  |  126 lines

  1. /* $XConsortium: xgetbmap.c,v 1.4 89/12/02 15:20:53 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 return the version of the extension.
  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 "XI.h"
  39. #include "XIproto.h"
  40.  
  41. extern    int         IReqCode;
  42. extern    int         BadDevice;
  43. extern    void        (* ReplySwapVector[256]) ();
  44. DeviceIntPtr        LookupDeviceIntRec();
  45.  
  46. /***********************************************************************
  47.  *
  48.  * This procedure gets the button mapping for the specified device.
  49.  *
  50.  */
  51.  
  52. int
  53. SProcXGetDeviceButtonMapping(client)
  54.     register ClientPtr client;
  55.     {
  56.     register char n;
  57.  
  58.     REQUEST(xGetDeviceButtonMappingReq);
  59.     swaps(&stuff->length, n);
  60.     return(ProcXGetDeviceButtonMapping(client));
  61.     }
  62.  
  63. /***********************************************************************
  64.  *
  65.  * This procedure gets the button mapping for the specified device.
  66.  *
  67.  */
  68.  
  69. ProcXGetDeviceButtonMapping (client)
  70.     register ClientPtr client;
  71.     {
  72.     DeviceIntPtr    dev;
  73.     xGetDeviceButtonMappingReply    rep;
  74.     ButtonClassPtr    b;
  75.  
  76.     REQUEST(xGetDeviceButtonMappingReq);
  77.     REQUEST_SIZE_MATCH(xGetDeviceButtonMappingReq);
  78.  
  79.     rep.repType = X_Reply;
  80.     rep.RepType = X_GetDeviceButtonMapping;
  81.     rep.nElts = 0;
  82.     rep.length = 0;
  83.     rep.sequenceNumber = client->sequence;
  84.  
  85.     dev = LookupDeviceIntRec (stuff->deviceid);
  86.     if (dev == NULL)
  87.     {
  88.     SendErrorToClient(client, IReqCode, X_GetDeviceButtonMapping, 0, 
  89.         BadDevice);
  90.     return Success;
  91.     }
  92.  
  93.     b = dev->button;
  94.     if (b == NULL)
  95.     {
  96.     SendErrorToClient(client, IReqCode, X_GetDeviceButtonMapping, 0, 
  97.         BadMatch);
  98.     return Success;
  99.     }
  100.     rep.nElts = b->numButtons;
  101.     rep.length = (rep.nElts + (4-1))/4;
  102.     WriteReplyToClient (client, sizeof (xGetDeviceButtonMappingReply), &rep);
  103.     (void)WriteToClient(client, rep.nElts,
  104.             (char *)&b->map[1]);
  105.     return Success;
  106.     }
  107.  
  108. /***********************************************************************
  109.  *
  110.  * This procedure writes the reply for the XGetDeviceButtonMapping function,
  111.  * if the client and server have a different byte ordering.
  112.  *
  113.  */
  114.  
  115. SRepXGetDeviceButtonMapping (client, size, rep)
  116.     ClientPtr    client;
  117.     int        size;
  118.     xGetDeviceButtonMappingReply    *rep;
  119.     {
  120.     register char n;
  121.  
  122.     swaps(&rep->sequenceNumber, n);
  123.     swapl(&rep->length, n);
  124.     WriteToClient(client, size, rep);
  125.     }
  126.