chgfctl.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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 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> /* control constants */
  47. #include "exglobals.h"
  48. #include "chgfctl.h"
  49. #define DO_ALL (-1)
  50. /***********************************************************************
  51. *
  52. * This procedure changes the control attributes for an extension device,
  53. * for clients on machines with a different byte ordering than the server.
  54. *
  55. */
  56. int
  57. SProcXChangeFeedbackControl(ClientPtr client)
  58. {
  59. REQUEST(xChangeFeedbackControlReq);
  60. swaps(&stuff->length);
  61. REQUEST_AT_LEAST_SIZE(xChangeFeedbackControlReq);
  62. swapl(&stuff->mask);
  63. return (ProcXChangeFeedbackControl(client));
  64. }
  65. /******************************************************************************
  66. *
  67. * This procedure changes KbdFeedbackClass data.
  68. *
  69. */
  70. static int
  71. ChangeKbdFeedback(ClientPtr client, DeviceIntPtr dev, long unsigned int mask,
  72. KbdFeedbackPtr k, xKbdFeedbackCtl * f)
  73. {
  74. KeybdCtrl kctrl;
  75. int t;
  76. int key = DO_ALL;
  77. if (client->swapped) {
  78. swaps(&f->length);
  79. swaps(&f->pitch);
  80. swaps(&f->duration);
  81. swapl(&f->led_mask);
  82. swapl(&f->led_values);
  83. }
  84. kctrl = k->ctrl;
  85. if (mask & DvKeyClickPercent) {
  86. t = f->click;
  87. if (t == -1)
  88. t = defaultKeyboardControl.click;
  89. else if (t < 0 || t > 100) {
  90. client->errorValue = t;
  91. return BadValue;
  92. }
  93. kctrl.click = t;
  94. }
  95. if (mask & DvPercent) {
  96. t = f->percent;
  97. if (t == -1)
  98. t = defaultKeyboardControl.bell;
  99. else if (t < 0 || t > 100) {
  100. client->errorValue = t;
  101. return BadValue;
  102. }
  103. kctrl.bell = t;
  104. }
  105. if (mask & DvPitch) {
  106. t = f->pitch;
  107. if (t == -1)
  108. t = defaultKeyboardControl.bell_pitch;
  109. else if (t < 0) {
  110. client->errorValue = t;
  111. return BadValue;
  112. }
  113. kctrl.bell_pitch = t;
  114. }
  115. if (mask & DvDuration) {
  116. t = f->duration;
  117. if (t == -1)
  118. t = defaultKeyboardControl.bell_duration;
  119. else if (t < 0) {
  120. client->errorValue = t;
  121. return BadValue;
  122. }
  123. kctrl.bell_duration = t;
  124. }
  125. if (mask & DvLed) {
  126. kctrl.leds &= ~(f->led_mask);
  127. kctrl.leds |= (f->led_mask & f->led_values);
  128. }
  129. if (mask & DvKey) {
  130. key = (KeyCode) f->key;
  131. if (key < 8 || key > 255) {
  132. client->errorValue = key;
  133. return BadValue;
  134. }
  135. if (!(mask & DvAutoRepeatMode))
  136. return BadMatch;
  137. }
  138. if (mask & DvAutoRepeatMode) {
  139. int inx = (key >> 3);
  140. int kmask = (1 << (key & 7));
  141. t = (CARD8) f->auto_repeat_mode;
  142. if (t == AutoRepeatModeOff) {
  143. if (key == DO_ALL)
  144. kctrl.autoRepeat = FALSE;
  145. else
  146. kctrl.autoRepeats[inx] &= ~kmask;
  147. }
  148. else if (t == AutoRepeatModeOn) {
  149. if (key == DO_ALL)
  150. kctrl.autoRepeat = TRUE;
  151. else
  152. kctrl.autoRepeats[inx] |= kmask;
  153. }
  154. else if (t == AutoRepeatModeDefault) {
  155. if (key == DO_ALL)
  156. kctrl.autoRepeat = defaultKeyboardControl.autoRepeat;
  157. else
  158. kctrl.autoRepeats[inx] &= ~kmask;
  159. kctrl.autoRepeats[inx] =
  160. (kctrl.autoRepeats[inx] & ~kmask) |
  161. (defaultKeyboardControl.autoRepeats[inx] & kmask);
  162. }
  163. else {
  164. client->errorValue = t;
  165. return BadValue;
  166. }
  167. }
  168. k->ctrl = kctrl;
  169. (*k->CtrlProc) (dev, &k->ctrl);
  170. return Success;
  171. }
  172. /******************************************************************************
  173. *
  174. * This procedure changes PtrFeedbackClass data.
  175. *
  176. */
  177. static int
  178. ChangePtrFeedback(ClientPtr client, DeviceIntPtr dev, long unsigned int mask,
  179. PtrFeedbackPtr p, xPtrFeedbackCtl * f)
  180. {
  181. PtrCtrl pctrl; /* might get BadValue part way through */
  182. if (client->swapped) {
  183. swaps(&f->length);
  184. swaps(&f->num);
  185. swaps(&f->denom);
  186. swaps(&f->thresh);
  187. }
  188. pctrl = p->ctrl;
  189. if (mask & DvAccelNum) {
  190. int accelNum;
  191. accelNum = f->num;
  192. if (accelNum == -1)
  193. pctrl.num = defaultPointerControl.num;
  194. else if (accelNum < 0) {
  195. client->errorValue = accelNum;
  196. return BadValue;
  197. }
  198. else
  199. pctrl.num = accelNum;
  200. }
  201. if (mask & DvAccelDenom) {
  202. int accelDenom;
  203. accelDenom = f->denom;
  204. if (accelDenom == -1)
  205. pctrl.den = defaultPointerControl.den;
  206. else if (accelDenom <= 0) {
  207. client->errorValue = accelDenom;
  208. return BadValue;
  209. }
  210. else
  211. pctrl.den = accelDenom;
  212. }
  213. if (mask & DvThreshold) {
  214. int threshold;
  215. threshold = f->thresh;
  216. if (threshold == -1)
  217. pctrl.threshold = defaultPointerControl.threshold;
  218. else if (threshold < 0) {
  219. client->errorValue = threshold;
  220. return BadValue;
  221. }
  222. else
  223. pctrl.threshold = threshold;
  224. }
  225. p->ctrl = pctrl;
  226. (*p->CtrlProc) (dev, &p->ctrl);
  227. return Success;
  228. }
  229. /******************************************************************************
  230. *
  231. * This procedure changes IntegerFeedbackClass data.
  232. *
  233. */
  234. static int
  235. ChangeIntegerFeedback(ClientPtr client, DeviceIntPtr dev,
  236. long unsigned int mask, IntegerFeedbackPtr i,
  237. xIntegerFeedbackCtl * f)
  238. {
  239. if (client->swapped) {
  240. swaps(&f->length);
  241. swapl(&f->int_to_display);
  242. }
  243. i->ctrl.integer_displayed = f->int_to_display;
  244. (*i->CtrlProc) (dev, &i->ctrl);
  245. return Success;
  246. }
  247. /******************************************************************************
  248. *
  249. * This procedure changes StringFeedbackClass data.
  250. *
  251. */
  252. static int
  253. ChangeStringFeedback(ClientPtr client, DeviceIntPtr dev,
  254. long unsigned int mask, StringFeedbackPtr s,
  255. xStringFeedbackCtl * f)
  256. {
  257. int i, j;
  258. KeySym *syms, *sup_syms;
  259. syms = (KeySym *) (f + 1);
  260. if (client->swapped) {
  261. swaps(&f->length); /* swapped num_keysyms in calling proc */
  262. SwapLongs((CARD32 *) syms, f->num_keysyms);
  263. }
  264. if (f->num_keysyms > s->ctrl.max_symbols)
  265. return BadValue;
  266. sup_syms = s->ctrl.symbols_supported;
  267. for (i = 0; i < f->num_keysyms; i++) {
  268. for (j = 0; j < s->ctrl.num_symbols_supported; j++)
  269. if (*(syms + i) == *(sup_syms + j))
  270. break;
  271. if (j == s->ctrl.num_symbols_supported)
  272. return BadMatch;
  273. }
  274. s->ctrl.num_symbols_displayed = f->num_keysyms;
  275. for (i = 0; i < f->num_keysyms; i++)
  276. *(s->ctrl.symbols_displayed + i) = *(syms + i);
  277. (*s->CtrlProc) (dev, &s->ctrl);
  278. return Success;
  279. }
  280. /******************************************************************************
  281. *
  282. * This procedure changes BellFeedbackClass data.
  283. *
  284. */
  285. static int
  286. ChangeBellFeedback(ClientPtr client, DeviceIntPtr dev,
  287. long unsigned int mask, BellFeedbackPtr b,
  288. xBellFeedbackCtl * f)
  289. {
  290. int t;
  291. BellCtrl bctrl; /* might get BadValue part way through */
  292. if (client->swapped) {
  293. swaps(&f->length);
  294. swaps(&f->pitch);
  295. swaps(&f->duration);
  296. }
  297. bctrl = b->ctrl;
  298. if (mask & DvPercent) {
  299. t = f->percent;
  300. if (t == -1)
  301. t = defaultKeyboardControl.bell;
  302. else if (t < 0 || t > 100) {
  303. client->errorValue = t;
  304. return BadValue;
  305. }
  306. bctrl.percent = t;
  307. }
  308. if (mask & DvPitch) {
  309. t = f->pitch;
  310. if (t == -1)
  311. t = defaultKeyboardControl.bell_pitch;
  312. else if (t < 0) {
  313. client->errorValue = t;
  314. return BadValue;
  315. }
  316. bctrl.pitch = t;
  317. }
  318. if (mask & DvDuration) {
  319. t = f->duration;
  320. if (t == -1)
  321. t = defaultKeyboardControl.bell_duration;
  322. else if (t < 0) {
  323. client->errorValue = t;
  324. return BadValue;
  325. }
  326. bctrl.duration = t;
  327. }
  328. b->ctrl = bctrl;
  329. (*b->CtrlProc) (dev, &b->ctrl);
  330. return Success;
  331. }
  332. /******************************************************************************
  333. *
  334. * This procedure changes LedFeedbackClass data.
  335. *
  336. */
  337. static int
  338. ChangeLedFeedback(ClientPtr client, DeviceIntPtr dev, long unsigned int mask,
  339. LedFeedbackPtr l, xLedFeedbackCtl * f)
  340. {
  341. LedCtrl lctrl; /* might get BadValue part way through */
  342. if (client->swapped) {
  343. swaps(&f->length);
  344. swapl(&f->led_values);
  345. swapl(&f->led_mask);
  346. }
  347. f->led_mask &= l->ctrl.led_mask; /* set only supported leds */
  348. f->led_values &= l->ctrl.led_mask; /* set only supported leds */
  349. if (mask & DvLed) {
  350. lctrl.led_mask = f->led_mask;
  351. lctrl.led_values = f->led_values;
  352. (*l->CtrlProc) (dev, &lctrl);
  353. l->ctrl.led_values &= ~(f->led_mask); /* zero changed leds */
  354. l->ctrl.led_values |= (f->led_mask & f->led_values); /* OR in set leds */
  355. }
  356. return Success;
  357. }
  358. /***********************************************************************
  359. *
  360. * Change the control attributes.
  361. *
  362. */
  363. int
  364. ProcXChangeFeedbackControl(ClientPtr client)
  365. {
  366. unsigned len;
  367. DeviceIntPtr dev;
  368. KbdFeedbackPtr k;
  369. PtrFeedbackPtr p;
  370. IntegerFeedbackPtr i;
  371. StringFeedbackPtr s;
  372. BellFeedbackPtr b;
  373. LedFeedbackPtr l;
  374. int rc;
  375. REQUEST(xChangeFeedbackControlReq);
  376. REQUEST_AT_LEAST_SIZE(xChangeFeedbackControlReq);
  377. len = stuff->length - bytes_to_int32(sizeof(xChangeFeedbackControlReq));
  378. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess);
  379. if (rc != Success)
  380. return rc;
  381. switch (stuff->feedbackid) {
  382. case KbdFeedbackClass:
  383. if (len != bytes_to_int32(sizeof(xKbdFeedbackCtl)))
  384. return BadLength;
  385. for (k = dev->kbdfeed; k; k = k->next)
  386. if (k->ctrl.id == ((xKbdFeedbackCtl *) &stuff[1])->id)
  387. return ChangeKbdFeedback(client, dev, stuff->mask, k,
  388. (xKbdFeedbackCtl *) &stuff[1]);
  389. break;
  390. case PtrFeedbackClass:
  391. if (len != bytes_to_int32(sizeof(xPtrFeedbackCtl)))
  392. return BadLength;
  393. for (p = dev->ptrfeed; p; p = p->next)
  394. if (p->ctrl.id == ((xPtrFeedbackCtl *) &stuff[1])->id)
  395. return ChangePtrFeedback(client, dev, stuff->mask, p,
  396. (xPtrFeedbackCtl *) &stuff[1]);
  397. break;
  398. case StringFeedbackClass:
  399. {
  400. xStringFeedbackCtl *f = ((xStringFeedbackCtl *) &stuff[1]);
  401. if (client->swapped) {
  402. if (len < bytes_to_int32(sizeof(xStringFeedbackCtl)))
  403. return BadLength;
  404. swaps(&f->num_keysyms);
  405. }
  406. if (len !=
  407. (bytes_to_int32(sizeof(xStringFeedbackCtl)) + f->num_keysyms))
  408. return BadLength;
  409. for (s = dev->stringfeed; s; s = s->next)
  410. if (s->ctrl.id == ((xStringFeedbackCtl *) &stuff[1])->id)
  411. return ChangeStringFeedback(client, dev, stuff->mask, s,
  412. (xStringFeedbackCtl *) &stuff[1]);
  413. break;
  414. }
  415. case IntegerFeedbackClass:
  416. if (len != bytes_to_int32(sizeof(xIntegerFeedbackCtl)))
  417. return BadLength;
  418. for (i = dev->intfeed; i; i = i->next)
  419. if (i->ctrl.id == ((xIntegerFeedbackCtl *) &stuff[1])->id)
  420. return ChangeIntegerFeedback(client, dev, stuff->mask, i,
  421. (xIntegerFeedbackCtl *) &
  422. stuff[1]);
  423. break;
  424. case LedFeedbackClass:
  425. if (len != bytes_to_int32(sizeof(xLedFeedbackCtl)))
  426. return BadLength;
  427. for (l = dev->leds; l; l = l->next)
  428. if (l->ctrl.id == ((xLedFeedbackCtl *) &stuff[1])->id)
  429. return ChangeLedFeedback(client, dev, stuff->mask, l,
  430. (xLedFeedbackCtl *) &stuff[1]);
  431. break;
  432. case BellFeedbackClass:
  433. if (len != bytes_to_int32(sizeof(xBellFeedbackCtl)))
  434. return BadLength;
  435. for (b = dev->bell; b; b = b->next)
  436. if (b->ctrl.id == ((xBellFeedbackCtl *) &stuff[1])->id)
  437. return ChangeBellFeedback(client, dev, stuff->mask, b,
  438. (xBellFeedbackCtl *) &stuff[1]);
  439. break;
  440. default:
  441. break;
  442. }
  443. return BadMatch;
  444. }