chgdctl.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. * Change Device control attributes 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> /* control constants */
  47. #include "XIstubs.h"
  48. #include "exglobals.h"
  49. #include "exevents.h"
  50. #include "chgdctl.h"
  51. /***********************************************************************
  52. *
  53. * This procedure changes the control attributes for an extension device,
  54. * for clients on machines with a different byte ordering than the server.
  55. *
  56. */
  57. int
  58. SProcXChangeDeviceControl(ClientPtr client)
  59. {
  60. xDeviceCtl *ctl;
  61. REQUEST(xChangeDeviceControlReq);
  62. swaps(&stuff->length);
  63. REQUEST_AT_LEAST_EXTRA_SIZE(xChangeDeviceControlReq, sizeof(xDeviceCtl));
  64. swaps(&stuff->control);
  65. ctl = (xDeviceCtl *) &stuff[1];
  66. swaps(&ctl->control);
  67. swaps(&ctl->length);
  68. switch (stuff->control) {
  69. case DEVICE_ABS_CALIB:
  70. case DEVICE_ABS_AREA:
  71. case DEVICE_CORE:
  72. case DEVICE_ENABLE:
  73. case DEVICE_RESOLUTION:
  74. /* hmm. beer. *drool* */
  75. break;
  76. }
  77. return (ProcXChangeDeviceControl(client));
  78. }
  79. /***********************************************************************
  80. *
  81. * Change the control attributes.
  82. *
  83. */
  84. int
  85. ProcXChangeDeviceControl(ClientPtr client)
  86. {
  87. unsigned len;
  88. int i, status, ret = BadValue;
  89. DeviceIntPtr dev;
  90. xDeviceResolutionCtl *r;
  91. xChangeDeviceControlReply rep;
  92. AxisInfoPtr a;
  93. CARD32 *resolution;
  94. xDeviceEnableCtl *e;
  95. REQUEST(xChangeDeviceControlReq);
  96. REQUEST_AT_LEAST_EXTRA_SIZE(xChangeDeviceControlReq, sizeof(xDeviceCtl));
  97. len = stuff->length - bytes_to_int32(sizeof(xChangeDeviceControlReq));
  98. ret = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess);
  99. if (ret != Success)
  100. goto out;
  101. /* XTest devices are special, none of the below apply to them anyway */
  102. if (IsXTestDevice(dev, NULL)) {
  103. ret = BadMatch;
  104. goto out;
  105. }
  106. rep = (xChangeDeviceControlReply) {
  107. .repType = X_Reply,
  108. .RepType = X_ChangeDeviceControl,
  109. .sequenceNumber = client->sequence,
  110. .length = 0,
  111. .status = Success,
  112. };
  113. switch (stuff->control) {
  114. case DEVICE_RESOLUTION:
  115. r = (xDeviceResolutionCtl *) &stuff[1];
  116. if ((len < bytes_to_int32(sizeof(xDeviceResolutionCtl))) ||
  117. (len !=
  118. bytes_to_int32(sizeof(xDeviceResolutionCtl)) + r->num_valuators)) {
  119. ret = BadLength;
  120. goto out;
  121. }
  122. if (!dev->valuator) {
  123. ret = BadMatch;
  124. goto out;
  125. }
  126. if ((dev->deviceGrab.grab) && !SameClient(dev->deviceGrab.grab, client)) {
  127. rep.status = AlreadyGrabbed;
  128. ret = Success;
  129. goto out;
  130. }
  131. resolution = (CARD32 *) (r + 1);
  132. if (r->first_valuator + r->num_valuators > dev->valuator->numAxes) {
  133. ret = BadValue;
  134. goto out;
  135. }
  136. status = ChangeDeviceControl(client, dev, (xDeviceCtl *) r);
  137. if (status == Success) {
  138. a = &dev->valuator->axes[r->first_valuator];
  139. for (i = 0; i < r->num_valuators; i++)
  140. if (*(resolution + i) < (a + i)->min_resolution ||
  141. *(resolution + i) > (a + i)->max_resolution)
  142. return BadValue;
  143. for (i = 0; i < r->num_valuators; i++)
  144. (a++)->resolution = *resolution++;
  145. ret = Success;
  146. }
  147. else if (status == DeviceBusy) {
  148. rep.status = DeviceBusy;
  149. ret = Success;
  150. }
  151. else {
  152. ret = BadMatch;
  153. }
  154. break;
  155. case DEVICE_ABS_CALIB:
  156. case DEVICE_ABS_AREA:
  157. /* Calibration is now done through properties, and never had any effect
  158. * on anything (in the open-source world). Thus, be honest. */
  159. ret = BadMatch;
  160. break;
  161. case DEVICE_CORE:
  162. /* Sorry, no device core switching no more. If you want a device to
  163. * send core events, attach it to a master device */
  164. ret = BadMatch;
  165. break;
  166. case DEVICE_ENABLE:
  167. e = (xDeviceEnableCtl *) &stuff[1];
  168. if ((len != bytes_to_int32(sizeof(xDeviceEnableCtl)))) {
  169. ret = BadLength;
  170. goto out;
  171. }
  172. if (IsXTestDevice(dev, NULL))
  173. status = !Success;
  174. else
  175. status = ChangeDeviceControl(client, dev, (xDeviceCtl *) e);
  176. if (status == Success) {
  177. if (e->enable)
  178. EnableDevice(dev, TRUE);
  179. else
  180. DisableDevice(dev, TRUE);
  181. ret = Success;
  182. }
  183. else if (status == DeviceBusy) {
  184. rep.status = DeviceBusy;
  185. ret = Success;
  186. }
  187. else {
  188. ret = BadMatch;
  189. }
  190. break;
  191. default:
  192. ret = BadValue;
  193. }
  194. out:
  195. if (ret == Success) {
  196. devicePresenceNotify dpn = {
  197. .type = DevicePresenceNotify,
  198. .time = currentTime.milliseconds,
  199. .devchange = DeviceControlChanged,
  200. .deviceid = dev->id,
  201. .control = stuff->control
  202. };
  203. SendEventToAllWindows(dev, DevicePresenceNotifyMask,
  204. (xEvent *) &dpn, 1);
  205. WriteReplyToClient(client, sizeof(xChangeDeviceControlReply), &rep);
  206. }
  207. return ret;
  208. }
  209. /***********************************************************************
  210. *
  211. * This procedure writes the reply for the xChangeDeviceControl function,
  212. * if the client and server have a different byte ordering.
  213. *
  214. */
  215. void
  216. SRepXChangeDeviceControl(ClientPtr client, int size,
  217. xChangeDeviceControlReply * rep)
  218. {
  219. swaps(&rep->sequenceNumber);
  220. swapl(&rep->length);
  221. WriteToClient(client, size, rep);
  222. }