gtmotion.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. * Request to get the motion history from 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 "exevents.h"
  48. #include "exglobals.h"
  49. #include "gtmotion.h"
  50. /***********************************************************************
  51. *
  52. * Swap the request if server and client have different byte ordering.
  53. *
  54. */
  55. int
  56. SProcXGetDeviceMotionEvents(ClientPtr client)
  57. {
  58. REQUEST(xGetDeviceMotionEventsReq);
  59. swaps(&stuff->length);
  60. REQUEST_SIZE_MATCH(xGetDeviceMotionEventsReq);
  61. swapl(&stuff->start);
  62. swapl(&stuff->stop);
  63. return (ProcXGetDeviceMotionEvents(client));
  64. }
  65. /****************************************************************************
  66. *
  67. * Get the motion history for an extension pointer devices.
  68. *
  69. */
  70. int
  71. ProcXGetDeviceMotionEvents(ClientPtr client)
  72. {
  73. INT32 *coords = NULL, *bufptr;
  74. xGetDeviceMotionEventsReply rep;
  75. unsigned long i;
  76. int rc, num_events, axes, size = 0;
  77. unsigned long nEvents;
  78. DeviceIntPtr dev;
  79. TimeStamp start, stop;
  80. int length = 0;
  81. ValuatorClassPtr v;
  82. REQUEST(xGetDeviceMotionEventsReq);
  83. REQUEST_SIZE_MATCH(xGetDeviceMotionEventsReq);
  84. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixReadAccess);
  85. if (rc != Success)
  86. return rc;
  87. v = dev->valuator;
  88. if (v == NULL || v->numAxes == 0)
  89. return BadMatch;
  90. if (dev->valuator->motionHintWindow)
  91. MaybeStopDeviceHint(dev, client);
  92. axes = v->numAxes;
  93. rep = (xGetDeviceMotionEventsReply) {
  94. .repType = X_Reply,
  95. .RepType = X_GetDeviceMotionEvents,
  96. .sequenceNumber = client->sequence,
  97. .length = 0,
  98. .nEvents = 0,
  99. .axes = axes,
  100. .mode = Absolute /* XXX we don't do relative at the moment */
  101. };
  102. start = ClientTimeToServerTime(stuff->start);
  103. stop = ClientTimeToServerTime(stuff->stop);
  104. if (CompareTimeStamps(start, stop) == LATER ||
  105. CompareTimeStamps(start, currentTime) == LATER) {
  106. WriteReplyToClient(client, sizeof(xGetDeviceMotionEventsReply), &rep);
  107. return Success;
  108. }
  109. if (CompareTimeStamps(stop, currentTime) == LATER)
  110. stop = currentTime;
  111. num_events = v->numMotionEvents;
  112. if (num_events) {
  113. size = sizeof(Time) + (axes * sizeof(INT32));
  114. rep.nEvents = GetMotionHistory(dev, (xTimecoord **) &coords, /* XXX */
  115. start.milliseconds, stop.milliseconds,
  116. (ScreenPtr) NULL, FALSE);
  117. }
  118. if (rep.nEvents > 0) {
  119. length = bytes_to_int32(rep.nEvents * size);
  120. rep.length = length;
  121. }
  122. nEvents = rep.nEvents;
  123. WriteReplyToClient(client, sizeof(xGetDeviceMotionEventsReply), &rep);
  124. if (nEvents) {
  125. if (client->swapped) {
  126. bufptr = coords;
  127. for (i = 0; i < nEvents * (axes + 1); i++) {
  128. swapl(bufptr);
  129. bufptr++;
  130. }
  131. }
  132. WriteToClient(client, length * 4, coords);
  133. }
  134. free(coords);
  135. return Success;
  136. }
  137. /***********************************************************************
  138. *
  139. * This procedure writes the reply for the XGetDeviceMotionEvents function,
  140. * if the client and server have a different byte ordering.
  141. *
  142. */
  143. void
  144. SRepXGetDeviceMotionEvents(ClientPtr client, int size,
  145. xGetDeviceMotionEventsReply * rep)
  146. {
  147. swaps(&rep->sequenceNumber);
  148. swapl(&rep->length);
  149. swapl(&rep->nEvents);
  150. WriteToClient(client, size, rep);
  151. }