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

  1. /* $XConsortium: xgetkmap.c,v 1.4 89/12/02 15:21:00 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.  *  Get the key mapping for an extension device.
  30.  *
  31.  */
  32.  
  33. #define     NEED_EVENTS            /* for inputstr.h    */
  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 key mapping for an extension device,
  49.  * for clients on machines with a different byte ordering than the server.
  50.  *
  51.  */
  52.  
  53. int
  54. SProcXGetDeviceKeyMapping(client)
  55.     register ClientPtr client;
  56.     {
  57.     register char n;
  58.  
  59.     REQUEST(xGetDeviceKeyMappingReq);
  60.     swaps(&stuff->length, n);
  61.     return(ProcXGetDeviceKeyMapping(client));
  62.     }
  63.  
  64. /***********************************************************************
  65.  *
  66.  * Get the device key mapping.
  67.  *
  68.  */
  69.  
  70. ProcXGetDeviceKeyMapping(client)
  71.     register ClientPtr client;
  72.     {
  73.     extern    void    CopySwap32Write();
  74.     xGetDeviceKeyMappingReply rep;
  75.     DeviceIntPtr dev;
  76.     KeySymsPtr    k;
  77.  
  78.     REQUEST(xGetDeviceKeyMappingReq);
  79.     REQUEST_SIZE_MATCH(xGetDeviceKeyMappingReq);
  80.  
  81.     dev = LookupDeviceIntRec (stuff->deviceid);
  82.     if (dev == NULL)
  83.     {
  84.     SendErrorToClient (client, IReqCode, X_GetDeviceKeyMapping, 0, 
  85.         BadDevice);
  86.     return Success;
  87.     }
  88.  
  89.     if (dev->key == NULL)
  90.     {
  91.     SendErrorToClient (client, IReqCode, X_GetDeviceKeyMapping, 0, 
  92.         BadMatch);
  93.     return Success;
  94.     }
  95.     k =  &dev->key->curKeySyms;
  96.  
  97.     if ((stuff->firstKeyCode < k->minKeyCode) ||
  98.         (stuff->firstKeyCode > k->maxKeyCode))
  99.         {
  100.     client->errorValue = stuff->firstKeyCode;
  101.     SendErrorToClient (client, IReqCode, X_GetDeviceKeyMapping, 0, 
  102.         BadValue);
  103.     return Success;
  104.         }
  105.  
  106.     if (stuff->firstKeyCode + stuff->count > k->maxKeyCode + 1)
  107.         {
  108.     client->errorValue = stuff->count;
  109.     SendErrorToClient (client, IReqCode, X_GetDeviceKeyMapping, 0, 
  110.         BadValue);
  111.     return Success;
  112.         }
  113.  
  114.     rep.repType = X_Reply;
  115.     rep.RepType = X_GetDeviceKeyMapping;
  116.     rep.sequenceNumber = client->sequence;
  117.     rep.keySymsPerKeyCode = k->mapWidth;
  118.     rep.length = (k->mapWidth * stuff->count); /* KeySyms are 4 bytes */
  119.     WriteReplyToClient(client, sizeof(xGetDeviceKeyMappingReply), &rep);
  120.  
  121.     client->pSwapReplyFunc = CopySwap32Write;
  122.     WriteSwappedDataToClient(
  123.     client,
  124.     k->mapWidth * stuff->count * sizeof(KeySym),
  125.     &k->map[stuff->firstKeyCode - k->minKeyCode]);
  126.  
  127.     return Success;
  128.     }
  129.  
  130. /***********************************************************************
  131.  *
  132.  * This procedure writes the reply for the XGetDeviceKeyMapping function,
  133.  * if the client and server have a different byte ordering.
  134.  *
  135.  */
  136.  
  137. SRepXGetDeviceKeyMapping (client, size, rep)
  138.     ClientPtr    client;
  139.     int        size;
  140.     xGetDeviceKeyMappingReply    *rep;
  141.     {
  142.     register char n;
  143.  
  144.     swaps(&rep->sequenceNumber, n);
  145.     swapl(&rep->length, n);
  146.     WriteToClient(client, size, rep);
  147.     }
  148.  
  149.