getfctl.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 feedback 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>
  47. #include "exglobals.h"
  48. #include "getfctl.h"
  49. /***********************************************************************
  50. *
  51. * This procedure gets the control attributes for an extension device,
  52. * for clients on machines with a different byte ordering than the server.
  53. *
  54. */
  55. int
  56. SProcXGetFeedbackControl(ClientPtr client)
  57. {
  58. REQUEST(xGetFeedbackControlReq);
  59. swaps(&stuff->length);
  60. return (ProcXGetFeedbackControl(client));
  61. }
  62. /***********************************************************************
  63. *
  64. * This procedure copies KbdFeedbackClass data, swapping if necessary.
  65. *
  66. */
  67. static void
  68. CopySwapKbdFeedback(ClientPtr client, KbdFeedbackPtr k, char **buf)
  69. {
  70. int i;
  71. xKbdFeedbackState *k2;
  72. k2 = (xKbdFeedbackState *) * buf;
  73. k2->class = KbdFeedbackClass;
  74. k2->length = sizeof(xKbdFeedbackState);
  75. k2->id = k->ctrl.id;
  76. k2->click = k->ctrl.click;
  77. k2->percent = k->ctrl.bell;
  78. k2->pitch = k->ctrl.bell_pitch;
  79. k2->duration = k->ctrl.bell_duration;
  80. k2->led_mask = k->ctrl.leds;
  81. k2->global_auto_repeat = k->ctrl.autoRepeat;
  82. for (i = 0; i < 32; i++)
  83. k2->auto_repeats[i] = k->ctrl.autoRepeats[i];
  84. if (client->swapped) {
  85. swaps(&k2->length);
  86. swaps(&k2->pitch);
  87. swaps(&k2->duration);
  88. swapl(&k2->led_mask);
  89. swapl(&k2->led_values);
  90. }
  91. *buf += sizeof(xKbdFeedbackState);
  92. }
  93. /***********************************************************************
  94. *
  95. * This procedure copies PtrFeedbackClass data, swapping if necessary.
  96. *
  97. */
  98. static void
  99. CopySwapPtrFeedback(ClientPtr client, PtrFeedbackPtr p, char **buf)
  100. {
  101. xPtrFeedbackState *p2;
  102. p2 = (xPtrFeedbackState *) * buf;
  103. p2->class = PtrFeedbackClass;
  104. p2->length = sizeof(xPtrFeedbackState);
  105. p2->id = p->ctrl.id;
  106. p2->accelNum = p->ctrl.num;
  107. p2->accelDenom = p->ctrl.den;
  108. p2->threshold = p->ctrl.threshold;
  109. if (client->swapped) {
  110. swaps(&p2->length);
  111. swaps(&p2->accelNum);
  112. swaps(&p2->accelDenom);
  113. swaps(&p2->threshold);
  114. }
  115. *buf += sizeof(xPtrFeedbackState);
  116. }
  117. /***********************************************************************
  118. *
  119. * This procedure copies IntegerFeedbackClass data, swapping if necessary.
  120. *
  121. */
  122. static void
  123. CopySwapIntegerFeedback(ClientPtr client, IntegerFeedbackPtr i, char **buf)
  124. {
  125. xIntegerFeedbackState *i2;
  126. i2 = (xIntegerFeedbackState *) * buf;
  127. i2->class = IntegerFeedbackClass;
  128. i2->length = sizeof(xIntegerFeedbackState);
  129. i2->id = i->ctrl.id;
  130. i2->resolution = i->ctrl.resolution;
  131. i2->min_value = i->ctrl.min_value;
  132. i2->max_value = i->ctrl.max_value;
  133. if (client->swapped) {
  134. swaps(&i2->length);
  135. swapl(&i2->resolution);
  136. swapl(&i2->min_value);
  137. swapl(&i2->max_value);
  138. }
  139. *buf += sizeof(xIntegerFeedbackState);
  140. }
  141. /***********************************************************************
  142. *
  143. * This procedure copies StringFeedbackClass data, swapping if necessary.
  144. *
  145. */
  146. static void
  147. CopySwapStringFeedback(ClientPtr client, StringFeedbackPtr s, char **buf)
  148. {
  149. int i;
  150. xStringFeedbackState *s2;
  151. KeySym *kptr;
  152. s2 = (xStringFeedbackState *) * buf;
  153. s2->class = StringFeedbackClass;
  154. s2->length = sizeof(xStringFeedbackState) +
  155. s->ctrl.num_symbols_supported * sizeof(KeySym);
  156. s2->id = s->ctrl.id;
  157. s2->max_symbols = s->ctrl.max_symbols;
  158. s2->num_syms_supported = s->ctrl.num_symbols_supported;
  159. *buf += sizeof(xStringFeedbackState);
  160. kptr = (KeySym *) (*buf);
  161. for (i = 0; i < s->ctrl.num_symbols_supported; i++)
  162. *kptr++ = *(s->ctrl.symbols_supported + i);
  163. if (client->swapped) {
  164. swaps(&s2->length);
  165. swaps(&s2->max_symbols);
  166. swaps(&s2->num_syms_supported);
  167. kptr = (KeySym *) (*buf);
  168. for (i = 0; i < s->ctrl.num_symbols_supported; i++, kptr++) {
  169. swapl(kptr);
  170. }
  171. }
  172. *buf += (s->ctrl.num_symbols_supported * sizeof(KeySym));
  173. }
  174. /***********************************************************************
  175. *
  176. * This procedure copies LedFeedbackClass data, swapping if necessary.
  177. *
  178. */
  179. static void
  180. CopySwapLedFeedback(ClientPtr client, LedFeedbackPtr l, char **buf)
  181. {
  182. xLedFeedbackState *l2;
  183. l2 = (xLedFeedbackState *) * buf;
  184. l2->class = LedFeedbackClass;
  185. l2->length = sizeof(xLedFeedbackState);
  186. l2->id = l->ctrl.id;
  187. l2->led_values = l->ctrl.led_values;
  188. l2->led_mask = l->ctrl.led_mask;
  189. if (client->swapped) {
  190. swaps(&l2->length);
  191. swapl(&l2->led_values);
  192. swapl(&l2->led_mask);
  193. }
  194. *buf += sizeof(xLedFeedbackState);
  195. }
  196. /***********************************************************************
  197. *
  198. * This procedure copies BellFeedbackClass data, swapping if necessary.
  199. *
  200. */
  201. static void
  202. CopySwapBellFeedback(ClientPtr client, BellFeedbackPtr b, char **buf)
  203. {
  204. xBellFeedbackState *b2;
  205. b2 = (xBellFeedbackState *) * buf;
  206. b2->class = BellFeedbackClass;
  207. b2->length = sizeof(xBellFeedbackState);
  208. b2->id = b->ctrl.id;
  209. b2->percent = b->ctrl.percent;
  210. b2->pitch = b->ctrl.pitch;
  211. b2->duration = b->ctrl.duration;
  212. if (client->swapped) {
  213. swaps(&b2->length);
  214. swaps(&b2->pitch);
  215. swaps(&b2->duration);
  216. }
  217. *buf += sizeof(xBellFeedbackState);
  218. }
  219. /***********************************************************************
  220. *
  221. * This procedure writes the reply for the xGetFeedbackControl function,
  222. * if the client and server have a different byte ordering.
  223. *
  224. */
  225. void
  226. SRepXGetFeedbackControl(ClientPtr client, int size,
  227. xGetFeedbackControlReply * rep)
  228. {
  229. swaps(&rep->sequenceNumber);
  230. swapl(&rep->length);
  231. swaps(&rep->num_feedbacks);
  232. WriteToClient(client, size, rep);
  233. }
  234. /***********************************************************************
  235. *
  236. * Get the feedback control state.
  237. *
  238. */
  239. int
  240. ProcXGetFeedbackControl(ClientPtr client)
  241. {
  242. int rc, total_length = 0;
  243. char *buf, *savbuf;
  244. DeviceIntPtr dev;
  245. KbdFeedbackPtr k;
  246. PtrFeedbackPtr p;
  247. IntegerFeedbackPtr i;
  248. StringFeedbackPtr s;
  249. BellFeedbackPtr b;
  250. LedFeedbackPtr l;
  251. xGetFeedbackControlReply rep;
  252. REQUEST(xGetFeedbackControlReq);
  253. REQUEST_SIZE_MATCH(xGetFeedbackControlReq);
  254. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
  255. if (rc != Success)
  256. return rc;
  257. rep = (xGetFeedbackControlReply) {
  258. .repType = X_Reply,
  259. .RepType = X_GetFeedbackControl,
  260. .sequenceNumber = client->sequence,
  261. .length = 0,
  262. .num_feedbacks = 0
  263. };
  264. for (k = dev->kbdfeed; k; k = k->next) {
  265. rep.num_feedbacks++;
  266. total_length += sizeof(xKbdFeedbackState);
  267. }
  268. for (p = dev->ptrfeed; p; p = p->next) {
  269. rep.num_feedbacks++;
  270. total_length += sizeof(xPtrFeedbackState);
  271. }
  272. for (s = dev->stringfeed; s; s = s->next) {
  273. rep.num_feedbacks++;
  274. total_length += sizeof(xStringFeedbackState) +
  275. (s->ctrl.num_symbols_supported * sizeof(KeySym));
  276. }
  277. for (i = dev->intfeed; i; i = i->next) {
  278. rep.num_feedbacks++;
  279. total_length += sizeof(xIntegerFeedbackState);
  280. }
  281. for (l = dev->leds; l; l = l->next) {
  282. rep.num_feedbacks++;
  283. total_length += sizeof(xLedFeedbackState);
  284. }
  285. for (b = dev->bell; b; b = b->next) {
  286. rep.num_feedbacks++;
  287. total_length += sizeof(xBellFeedbackState);
  288. }
  289. if (total_length == 0)
  290. return BadMatch;
  291. buf = (char *) malloc(total_length);
  292. if (!buf)
  293. return BadAlloc;
  294. savbuf = buf;
  295. for (k = dev->kbdfeed; k; k = k->next)
  296. CopySwapKbdFeedback(client, k, &buf);
  297. for (p = dev->ptrfeed; p; p = p->next)
  298. CopySwapPtrFeedback(client, p, &buf);
  299. for (s = dev->stringfeed; s; s = s->next)
  300. CopySwapStringFeedback(client, s, &buf);
  301. for (i = dev->intfeed; i; i = i->next)
  302. CopySwapIntegerFeedback(client, i, &buf);
  303. for (l = dev->leds; l; l = l->next)
  304. CopySwapLedFeedback(client, l, &buf);
  305. for (b = dev->bell; b; b = b->next)
  306. CopySwapBellFeedback(client, b, &buf);
  307. rep.length = bytes_to_int32(total_length);
  308. WriteReplyToClient(client, sizeof(xGetFeedbackControlReply), &rep);
  309. WriteToClient(client, total_length, savbuf);
  310. free(savbuf);
  311. return Success;
  312. }