getkmap.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /************************************************************
  2. Copyright 1989, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Hewlett-Packard not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ********************************************************/
  36. /********************************************************************
  37. *
  38. * Get the key mapping for an extension device.
  39. *
  40. */
  41. #ifdef HAVE_DIX_CONFIG_H
  42. #include <dix-config.h>
  43. #endif
  44. #include "inputstr.h" /* DeviceIntPtr */
  45. #include <X11/extensions/XI.h>
  46. #include <X11/extensions/XIproto.h>
  47. #include "exglobals.h"
  48. #include "swaprep.h"
  49. #include "xkbsrv.h"
  50. #include "xkbstr.h"
  51. #include "getkmap.h"
  52. /***********************************************************************
  53. *
  54. * This procedure gets the key mapping for an extension device,
  55. * for clients on machines with a different byte ordering than the server.
  56. *
  57. */
  58. int
  59. SProcXGetDeviceKeyMapping(ClientPtr client)
  60. {
  61. REQUEST(xGetDeviceKeyMappingReq);
  62. swaps(&stuff->length);
  63. return (ProcXGetDeviceKeyMapping(client));
  64. }
  65. /***********************************************************************
  66. *
  67. * Get the device key mapping.
  68. *
  69. */
  70. int
  71. ProcXGetDeviceKeyMapping(ClientPtr client)
  72. {
  73. xGetDeviceKeyMappingReply rep;
  74. DeviceIntPtr dev;
  75. XkbDescPtr xkb;
  76. KeySymsPtr syms;
  77. int rc;
  78. REQUEST(xGetDeviceKeyMappingReq);
  79. REQUEST_SIZE_MATCH(xGetDeviceKeyMappingReq);
  80. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
  81. if (rc != Success)
  82. return rc;
  83. if (dev->key == NULL)
  84. return BadMatch;
  85. xkb = dev->key->xkbInfo->desc;
  86. if (stuff->firstKeyCode < xkb->min_key_code ||
  87. stuff->firstKeyCode > xkb->max_key_code) {
  88. client->errorValue = stuff->firstKeyCode;
  89. return BadValue;
  90. }
  91. if (stuff->firstKeyCode + stuff->count > xkb->max_key_code + 1) {
  92. client->errorValue = stuff->count;
  93. return BadValue;
  94. }
  95. syms = XkbGetCoreMap(dev);
  96. if (!syms)
  97. return BadAlloc;
  98. rep = (xGetDeviceKeyMappingReply) {
  99. .repType = X_Reply,
  100. .RepType = X_GetDeviceKeyMapping,
  101. .sequenceNumber = client->sequence,
  102. .keySymsPerKeyCode = syms->mapWidth,
  103. .length = (syms->mapWidth * stuff->count) /* KeySyms are 4 bytes */
  104. };
  105. WriteReplyToClient(client, sizeof(xGetDeviceKeyMappingReply), &rep);
  106. client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
  107. WriteSwappedDataToClient(client,
  108. syms->mapWidth * stuff->count * sizeof(KeySym),
  109. &syms->map[syms->mapWidth * (stuff->firstKeyCode -
  110. syms->minKeyCode)]);
  111. free(syms->map);
  112. free(syms);
  113. return Success;
  114. }
  115. /***********************************************************************
  116. *
  117. * This procedure writes the reply for the XGetDeviceKeyMapping function,
  118. * if the client and server have a different byte ordering.
  119. *
  120. */
  121. void
  122. SRepXGetDeviceKeyMapping(ClientPtr client, int size,
  123. xGetDeviceKeyMappingReply * rep)
  124. {
  125. swaps(&rep->sequenceNumber);
  126. swapl(&rep->length);
  127. WriteToClient(client, size, rep);
  128. }