xfixes.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  3. * Copyright 2010 Red Hat, Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Copyright © 2002 Keith Packard
  25. *
  26. * Permission to use, copy, modify, distribute, and sell this software and its
  27. * documentation for any purpose is hereby granted without fee, provided that
  28. * the above copyright notice appear in all copies and that both that
  29. * copyright notice and this permission notice appear in supporting
  30. * documentation, and that the name of Keith Packard not be used in
  31. * advertising or publicity pertaining to distribution of the software without
  32. * specific, written prior permission. Keith Packard makes no
  33. * representations about the suitability of this software for any purpose. It
  34. * is provided "as is" without express or implied warranty.
  35. *
  36. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  37. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  38. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  39. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  40. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  41. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  42. * PERFORMANCE OF THIS SOFTWARE.
  43. */
  44. #ifdef HAVE_DIX_CONFIG_H
  45. #include <dix-config.h>
  46. #endif
  47. #include "xfixesint.h"
  48. /*
  49. * Must use these instead of the constants from xfixeswire.h. They advertise
  50. * what we implement, not what the protocol headers define.
  51. */
  52. #define SERVER_XFIXES_MAJOR 4
  53. #define SERVER_XFIXES_MINOR 0
  54. unsigned char XFixesReqCode;
  55. int XFixesEventBase;
  56. int XFixesErrorBase;
  57. int XFixesClientPrivateIndex;
  58. static int
  59. ProcXFixesQueryVersion(ClientPtr client)
  60. {
  61. XFixesClientPtr pXFixesClient = GetXFixesClient(client);
  62. xXFixesQueryVersionReply rep;
  63. REQUEST(xXFixesQueryVersionReq);
  64. REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
  65. rep.type = X_Reply;
  66. rep.length = 0;
  67. rep.sequenceNumber = client->sequence;
  68. if (stuff->majorVersion < SERVER_XFIXES_MAJOR) {
  69. rep.majorVersion = stuff->majorVersion;
  70. rep.minorVersion = stuff->minorVersion;
  71. }
  72. else {
  73. rep.majorVersion = SERVER_XFIXES_MAJOR;
  74. if (stuff->majorVersion == SERVER_XFIXES_MAJOR &&
  75. stuff->minorVersion < SERVER_XFIXES_MINOR)
  76. rep.minorVersion = stuff->minorVersion;
  77. else
  78. rep.minorVersion = SERVER_XFIXES_MINOR;
  79. }
  80. pXFixesClient->major_version = rep.majorVersion;
  81. pXFixesClient->minor_version = rep.minorVersion;
  82. if (client->swapped) {
  83. swaps(&rep.sequenceNumber);
  84. swapl(&rep.length);
  85. swapl(&rep.majorVersion);
  86. swapl(&rep.minorVersion);
  87. }
  88. WriteToClient(client, sizeof(xXFixesQueryVersionReply), (char *) &rep);
  89. return (client->noClientException);
  90. }
  91. /* Major version controls available requests */
  92. static const int version_requests[] = {
  93. X_XFixesQueryVersion, /* before client sends QueryVersion */
  94. X_XFixesGetCursorImage, /* Version 1 */
  95. X_XFixesChangeCursorByName, /* Version 2 */
  96. X_XFixesExpandRegion, /* Version 3 */
  97. X_XFixesShowCursor, /* Version 4 */
  98. };
  99. #define NUM_VERSION_REQUESTS (sizeof (version_requests) / sizeof (version_requests[0]))
  100. int (*ProcXFixesVector[XFixesNumberRequests]) (ClientPtr) = {
  101. /*************** Version 1 ******************/
  102. ProcXFixesQueryVersion,
  103. ProcXFixesChangeSaveSet,
  104. ProcXFixesSelectSelectionInput,
  105. ProcXFixesSelectCursorInput, ProcXFixesGetCursorImage,
  106. /*************** Version 2 ******************/
  107. ProcXFixesCreateRegion,
  108. ProcXFixesCreateRegionFromBitmap,
  109. ProcXFixesCreateRegionFromWindow,
  110. ProcXFixesCreateRegionFromGC,
  111. ProcXFixesCreateRegionFromPicture,
  112. ProcXFixesDestroyRegion,
  113. ProcXFixesSetRegion,
  114. ProcXFixesCopyRegion,
  115. ProcXFixesCombineRegion,
  116. ProcXFixesCombineRegion,
  117. ProcXFixesCombineRegion,
  118. ProcXFixesInvertRegion,
  119. ProcXFixesTranslateRegion,
  120. ProcXFixesRegionExtents,
  121. ProcXFixesFetchRegion,
  122. ProcXFixesSetGCClipRegion,
  123. ProcXFixesSetWindowShapeRegion,
  124. ProcXFixesSetPictureClipRegion,
  125. ProcXFixesSetCursorName,
  126. ProcXFixesGetCursorName,
  127. ProcXFixesGetCursorImageAndName,
  128. ProcXFixesChangeCursor, ProcXFixesChangeCursorByName,
  129. /*************** Version 3 ******************/
  130. ProcXFixesExpandRegion,
  131. /*************** Version 4 ****************/
  132. ProcXFixesHideCursor, ProcXFixesShowCursor,};
  133. static int
  134. ProcXFixesDispatch(ClientPtr client)
  135. {
  136. REQUEST(xXFixesReq);
  137. XFixesClientPtr pXFixesClient = GetXFixesClient(client);
  138. if (pXFixesClient->major_version >= NUM_VERSION_REQUESTS)
  139. return BadRequest;
  140. if (stuff->xfixesReqType > version_requests[pXFixesClient->major_version])
  141. return BadRequest;
  142. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  143. }
  144. static int
  145. SProcXFixesQueryVersion(ClientPtr client)
  146. {
  147. REQUEST(xXFixesQueryVersionReq);
  148. swaps(&stuff->length);
  149. swapl(&stuff->majorVersion);
  150. swapl(&stuff->minorVersion);
  151. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  152. }
  153. int (*SProcXFixesVector[XFixesNumberRequests]) (ClientPtr) = {
  154. /*************** Version 1 ******************/
  155. SProcXFixesQueryVersion,
  156. SProcXFixesChangeSaveSet,
  157. SProcXFixesSelectSelectionInput,
  158. SProcXFixesSelectCursorInput, SProcXFixesGetCursorImage,
  159. /*************** Version 2 ******************/
  160. SProcXFixesCreateRegion,
  161. SProcXFixesCreateRegionFromBitmap,
  162. SProcXFixesCreateRegionFromWindow,
  163. SProcXFixesCreateRegionFromGC,
  164. SProcXFixesCreateRegionFromPicture,
  165. SProcXFixesDestroyRegion,
  166. SProcXFixesSetRegion,
  167. SProcXFixesCopyRegion,
  168. SProcXFixesCombineRegion,
  169. SProcXFixesCombineRegion,
  170. SProcXFixesCombineRegion,
  171. SProcXFixesInvertRegion,
  172. SProcXFixesTranslateRegion,
  173. SProcXFixesRegionExtents,
  174. SProcXFixesFetchRegion,
  175. SProcXFixesSetGCClipRegion,
  176. SProcXFixesSetWindowShapeRegion,
  177. SProcXFixesSetPictureClipRegion,
  178. SProcXFixesSetCursorName,
  179. SProcXFixesGetCursorName,
  180. SProcXFixesGetCursorImageAndName,
  181. SProcXFixesChangeCursor, SProcXFixesChangeCursorByName,
  182. /*************** Version 3 ******************/
  183. SProcXFixesExpandRegion,
  184. /*************** Version 4 ****************/
  185. SProcXFixesHideCursor, SProcXFixesShowCursor,};
  186. static int
  187. SProcXFixesDispatch(ClientPtr client)
  188. {
  189. REQUEST(xXFixesReq);
  190. if (stuff->xfixesReqType >= XFixesNumberRequests)
  191. return BadRequest;
  192. return (*SProcXFixesVector[stuff->xfixesReqType]) (client);
  193. }
  194. static void
  195. XFixesClientCallback(CallbackListPtr *list, pointer closure, pointer data)
  196. {
  197. NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
  198. ClientPtr pClient = clientinfo->client;
  199. XFixesClientPtr pXFixesClient = GetXFixesClient(pClient);
  200. pXFixesClient->major_version = 0;
  201. pXFixesClient->minor_version = 0;
  202. }
  203. /*ARGSUSED*/ static void
  204. XFixesResetProc(ExtensionEntry * extEntry)
  205. {
  206. DeleteCallback(&ClientStateCallback, XFixesClientCallback, 0);
  207. }
  208. void
  209. XFixesExtensionInit(void)
  210. {
  211. ExtensionEntry *extEntry;
  212. XFixesClientPrivateIndex = AllocateClientPrivateIndex();
  213. if (!AllocateClientPrivate(XFixesClientPrivateIndex,
  214. sizeof(XFixesClientRec)))
  215. return;
  216. if (!AddCallback(&ClientStateCallback, XFixesClientCallback, 0))
  217. return;
  218. if (XFixesSelectionInit() && XFixesCursorInit() && XFixesRegionInit() &&
  219. (extEntry = AddExtension(XFIXES_NAME, XFixesNumberEvents,
  220. XFixesNumberErrors,
  221. ProcXFixesDispatch, SProcXFixesDispatch,
  222. XFixesResetProc, StandardMinorOpcode)) != 0) {
  223. XFixesReqCode = (unsigned char) extEntry->base;
  224. XFixesEventBase = extEntry->eventBase;
  225. XFixesErrorBase = extEntry->errorBase;
  226. EventSwapVector[XFixesEventBase + XFixesSelectionNotify] =
  227. (EventSwapPtr) SXFixesSelectionNotifyEvent;
  228. EventSwapVector[XFixesEventBase + XFixesCursorNotify] =
  229. (EventSwapPtr) SXFixesCursorNotifyEvent;
  230. }
  231. }