devices.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. /************************************************************
  2. Copyright 1987, 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 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  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 Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL 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. #ifdef HAVE_DIX_CONFIG_H
  37. #include <dix-config.h>
  38. #endif
  39. #include <X11/X.h>
  40. #include "misc.h"
  41. #include "resource.h"
  42. #include <X11/Xproto.h>
  43. #include "windowstr.h"
  44. #include "inputstr.h"
  45. #include "scrnintstr.h"
  46. #include "cursorstr.h"
  47. #include "dixstruct.h"
  48. #include "site.h"
  49. #ifndef XKB_IN_SERVER
  50. #define XKB_IN_SERVER
  51. #endif
  52. #include "dispatch.h"
  53. #include "swaprep.h"
  54. #include "dixevents.h"
  55. DeviceIntPtr
  56. AddInputDevice(DeviceProc deviceProc, Bool autoStart)
  57. {
  58. DeviceIntPtr dev;
  59. if (inputInfo.numDevices >= MAX_DEVICES)
  60. return (DeviceIntPtr) NULL;
  61. dev = malloc(sizeof(DeviceIntRec));
  62. if (!dev)
  63. return (DeviceIntPtr) NULL;
  64. dev->name = (char *) NULL;
  65. dev->type = 0;
  66. dev->id = inputInfo.numDevices;
  67. inputInfo.numDevices++;
  68. dev->public.on = FALSE;
  69. dev->public.processInputProc = (ProcessInputProc) NoopDDA;
  70. dev->public.realInputProc = (ProcessInputProc) NoopDDA;
  71. dev->public.enqueueInputProc = EnqueueEvent;
  72. dev->deviceProc = deviceProc;
  73. dev->startup = autoStart;
  74. dev->sync.frozen = FALSE;
  75. dev->sync.other = NullGrab;
  76. dev->sync.state = NOT_GRABBED;
  77. dev->sync.event = (xEvent *) NULL;
  78. dev->sync.evcount = 0;
  79. dev->grab = NullGrab;
  80. dev->grabTime = currentTime;
  81. dev->fromPassiveGrab = FALSE;
  82. dev->key = (KeyClassPtr) NULL;
  83. dev->valuator = (ValuatorClassPtr) NULL;
  84. dev->button = (ButtonClassPtr) NULL;
  85. dev->focus = (FocusClassPtr) NULL;
  86. dev->proximity = (ProximityClassPtr) NULL;
  87. dev->kbdfeed = (KbdFeedbackPtr) NULL;
  88. dev->ptrfeed = (PtrFeedbackPtr) NULL;
  89. dev->intfeed = (IntegerFeedbackPtr) NULL;
  90. dev->stringfeed = (StringFeedbackPtr) NULL;
  91. dev->bell = (BellFeedbackPtr) NULL;
  92. dev->leds = (LedFeedbackPtr) NULL;
  93. dev->next = inputInfo.off_devices;
  94. dev->nPrivates = 0;
  95. dev->devPrivates = NULL;
  96. dev->unwrapProc = NULL;
  97. inputInfo.off_devices = dev;
  98. return dev;
  99. }
  100. Bool
  101. EnableDevice(register DeviceIntPtr dev)
  102. {
  103. DeviceIntPtr *prev;
  104. for (prev = &inputInfo.off_devices;
  105. *prev && (*prev != dev); prev = &(*prev)->next);
  106. if ((*prev != dev) || !dev->inited ||
  107. ((*dev->deviceProc) (dev, DEVICE_ON) != Success))
  108. return FALSE;
  109. *prev = dev->next;
  110. dev->next = inputInfo.devices;
  111. inputInfo.devices = dev;
  112. return TRUE;
  113. }
  114. Bool
  115. DisableDevice(register DeviceIntPtr dev)
  116. {
  117. DeviceIntPtr *prev;
  118. for (prev = &inputInfo.devices;
  119. *prev && (*prev != dev); prev = &(*prev)->next);
  120. if (*prev != dev)
  121. return FALSE;
  122. (void) (*dev->deviceProc) (dev, DEVICE_OFF);
  123. *prev = dev->next;
  124. dev->next = inputInfo.off_devices;
  125. inputInfo.off_devices = dev;
  126. return TRUE;
  127. }
  128. int
  129. InitAndStartDevices()
  130. {
  131. DeviceIntPtr dev, next;
  132. for (dev = inputInfo.off_devices; dev; dev = dev->next)
  133. dev->inited = ((*dev->deviceProc) (dev, DEVICE_INIT) == Success);
  134. for (dev = inputInfo.off_devices; dev; dev = next) {
  135. next = dev->next;
  136. if (dev->inited && dev->startup)
  137. (void) EnableDevice(dev);
  138. }
  139. for (dev = inputInfo.devices;
  140. dev && (dev != inputInfo.keyboard); dev = dev->next);
  141. if (!dev || (dev != inputInfo.keyboard)) {
  142. ErrorF("No core keyboard\n");
  143. return BadImplementation;
  144. }
  145. for (dev = inputInfo.devices;
  146. dev && (dev != inputInfo.pointer); dev = dev->next);
  147. if (!dev || (dev != inputInfo.pointer)) {
  148. ErrorF("No core pointer\n");
  149. return BadImplementation;
  150. }
  151. return Success;
  152. }
  153. static void
  154. CloseDevice(register DeviceIntPtr dev)
  155. {
  156. KbdFeedbackPtr k, knext;
  157. PtrFeedbackPtr p, pnext;
  158. IntegerFeedbackPtr i, inext;
  159. StringFeedbackPtr s, snext;
  160. BellFeedbackPtr b, bnext;
  161. LedFeedbackPtr l, lnext;
  162. if (dev->inited)
  163. (void) (*dev->deviceProc) (dev, DEVICE_CLOSE);
  164. free(dev->name);
  165. if (dev->key) {
  166. free(dev->key->curKeySyms.map);
  167. free(dev->key->modifierKeyMap);
  168. free(dev->key);
  169. }
  170. free(dev->valuator);
  171. free(dev->button);
  172. if (dev->focus) {
  173. free(dev->focus->trace);
  174. free(dev->focus);
  175. }
  176. free(dev->proximity);
  177. for (k = dev->kbdfeed; k; k = knext) {
  178. knext = k->next;
  179. free(k);
  180. }
  181. for (p = dev->ptrfeed; p; p = pnext) {
  182. pnext = p->next;
  183. free(p);
  184. }
  185. for (i = dev->intfeed; i; i = inext) {
  186. inext = i->next;
  187. free(i);
  188. }
  189. for (s = dev->stringfeed; s; s = snext) {
  190. snext = s->next;
  191. free(s->ctrl.symbols_supported);
  192. free(s->ctrl.symbols_displayed);
  193. free(s);
  194. }
  195. for (b = dev->bell; b; b = bnext) {
  196. bnext = b->next;
  197. free(b);
  198. }
  199. for (l = dev->leds; l; l = lnext) {
  200. lnext = l->next;
  201. free(l);
  202. }
  203. free(dev->sync.event);
  204. free(dev);
  205. }
  206. void
  207. CloseDownDevices()
  208. {
  209. DeviceIntPtr dev, next;
  210. for (dev = inputInfo.devices; dev; dev = next) {
  211. next = dev->next;
  212. CloseDevice(dev);
  213. }
  214. for (dev = inputInfo.off_devices; dev; dev = next) {
  215. next = dev->next;
  216. CloseDevice(dev);
  217. }
  218. inputInfo.devices = NULL;
  219. inputInfo.off_devices = NULL;
  220. inputInfo.keyboard = NULL;
  221. inputInfo.pointer = NULL;
  222. }
  223. void
  224. RemoveDevice(register DeviceIntPtr dev)
  225. {
  226. DeviceIntPtr prev, tmp, next;
  227. prev = NULL;
  228. for (tmp = inputInfo.devices; tmp; (prev = tmp), (tmp = next)) {
  229. next = tmp->next;
  230. if (tmp == dev) {
  231. CloseDevice(tmp);
  232. if (prev == NULL)
  233. inputInfo.devices = next;
  234. else
  235. prev->next = next;
  236. inputInfo.numDevices--;
  237. if (inputInfo.keyboard == tmp)
  238. inputInfo.keyboard = NULL;
  239. else if (inputInfo.pointer == tmp)
  240. inputInfo.pointer = NULL;
  241. return;
  242. }
  243. }
  244. prev = NULL;
  245. for (tmp = inputInfo.off_devices; tmp; (prev = tmp), (tmp = next)) {
  246. next = tmp->next;
  247. if (tmp == dev) {
  248. CloseDevice(tmp);
  249. if (prev == NULL)
  250. inputInfo.off_devices = next;
  251. else
  252. prev->next = next;
  253. inputInfo.numDevices--;
  254. if (inputInfo.keyboard == tmp)
  255. inputInfo.keyboard = NULL;
  256. else if (inputInfo.pointer == tmp)
  257. inputInfo.pointer = NULL;
  258. return;
  259. }
  260. }
  261. ErrorF("Internal Error! Attempt to remove a non-existent device\n");
  262. return;
  263. }
  264. int
  265. NumMotionEvents()
  266. {
  267. return inputInfo.pointer->valuator->numMotionEvents;
  268. }
  269. void
  270. RegisterPointerDevice(DeviceIntPtr device)
  271. {
  272. inputInfo.pointer = device;
  273. device->public.processInputProc = ProcessPointerEvent;
  274. device->public.realInputProc = ProcessPointerEvent;
  275. device->ActivateGrab = ActivatePointerGrab;
  276. device->DeactivateGrab = DeactivatePointerGrab;
  277. if (!device->name) {
  278. char *p = "pointer";
  279. device->name = malloc(strlen(p) + 1);
  280. strcpy(device->name, p);
  281. }
  282. }
  283. void
  284. RegisterKeyboardDevice(DeviceIntPtr device)
  285. {
  286. inputInfo.keyboard = device;
  287. device->public.processInputProc = ProcessKeyboardEvent;
  288. device->public.realInputProc = ProcessKeyboardEvent;
  289. device->ActivateGrab = ActivateKeyboardGrab;
  290. device->DeactivateGrab = DeactivateKeyboardGrab;
  291. if (!device->name) {
  292. char *k = "keyboard";
  293. device->name = malloc(strlen(k) + 1);
  294. strcpy(device->name, k);
  295. }
  296. }
  297. _X_EXPORT DevicePtr
  298. LookupKeyboardDevice()
  299. {
  300. return inputInfo.keyboard ? &inputInfo.keyboard->public : NULL;
  301. }
  302. _X_EXPORT DevicePtr
  303. LookupPointerDevice()
  304. {
  305. return inputInfo.pointer ? &inputInfo.pointer->public : NULL;
  306. }
  307. DevicePtr
  308. LookupDevice(int id)
  309. {
  310. DeviceIntPtr dev;
  311. for (dev = inputInfo.devices; dev; dev = dev->next) {
  312. if (dev->id == (CARD8) id)
  313. return (DevicePtr) dev;
  314. }
  315. for (dev = inputInfo.off_devices; dev; dev = dev->next) {
  316. if (dev->id == (CARD8) id)
  317. return (DevicePtr) dev;
  318. }
  319. return NULL;
  320. }
  321. void
  322. QueryMinMaxKeyCodes(KeyCode *minCode, KeyCode *maxCode)
  323. {
  324. if (inputInfo.keyboard) {
  325. *minCode = inputInfo.keyboard->key->curKeySyms.minKeyCode;
  326. *maxCode = inputInfo.keyboard->key->curKeySyms.maxKeyCode;
  327. }
  328. }
  329. Bool
  330. SetKeySymsMap(register KeySymsPtr dst, register KeySymsPtr src)
  331. {
  332. int i, j;
  333. int rowDif = src->minKeyCode - dst->minKeyCode;
  334. /* if keysym map size changes, grow map first */
  335. if (src->mapWidth < dst->mapWidth) {
  336. for (i = src->minKeyCode; i <= src->maxKeyCode; i++) {
  337. #define SI(r, c) (((r-src->minKeyCode)*src->mapWidth) + (c))
  338. #define DI(r, c) (((r - dst->minKeyCode)*dst->mapWidth) + (c))
  339. for (j = 0; j < src->mapWidth; j++)
  340. dst->map[DI(i, j)] = src->map[SI(i, j)];
  341. for (j = src->mapWidth; j < dst->mapWidth; j++)
  342. dst->map[DI(i, j)] = NoSymbol;
  343. #undef SI
  344. #undef DI
  345. }
  346. return TRUE;
  347. }
  348. else if (src->mapWidth > dst->mapWidth) {
  349. KeySym *map;
  350. int bytes = sizeof(KeySym) * src->mapWidth *
  351. (dst->maxKeyCode - dst->minKeyCode + 1);
  352. map = malloc(bytes);
  353. if (!map)
  354. return FALSE;
  355. bzero((char *) map, bytes);
  356. if (dst->map) {
  357. for (i = 0; i <= dst->maxKeyCode - dst->minKeyCode; i++)
  358. memmove((char *) &map[i * src->mapWidth],
  359. (char *) &dst->map[i * dst->mapWidth],
  360. dst->mapWidth * sizeof(KeySym));
  361. free(dst->map);
  362. }
  363. dst->mapWidth = src->mapWidth;
  364. dst->map = map;
  365. }
  366. memmove((char *) &dst->map[rowDif * dst->mapWidth],
  367. (char *) src->map,
  368. (int) (src->maxKeyCode - src->minKeyCode + 1) *
  369. dst->mapWidth * sizeof(KeySym));
  370. return TRUE;
  371. }
  372. static Bool
  373. InitModMap(register KeyClassPtr keyc)
  374. {
  375. int i, j;
  376. CARD8 keysPerModifier[8];
  377. CARD8 mask;
  378. keyc->maxKeysPerModifier = 0;
  379. for (i = 0; i < 8; i++)
  380. keysPerModifier[i] = 0;
  381. for (i = 8; i < MAP_LENGTH; i++) {
  382. for (j = 0, mask = 1; j < 8; j++, mask <<= 1) {
  383. if (mask & keyc->modifierMap[i]) {
  384. if (++keysPerModifier[j] > keyc->maxKeysPerModifier)
  385. keyc->maxKeysPerModifier = keysPerModifier[j];
  386. }
  387. }
  388. }
  389. keyc->modifierKeyMap = malloc(8 * keyc->maxKeysPerModifier);
  390. if (!keyc->modifierKeyMap && keyc->maxKeysPerModifier)
  391. return (FALSE);
  392. bzero((char *) keyc->modifierKeyMap, 8 * (int) keyc->maxKeysPerModifier);
  393. for (i = 0; i < 8; i++)
  394. keysPerModifier[i] = 0;
  395. for (i = 8; i < MAP_LENGTH; i++) {
  396. for (j = 0, mask = 1; j < 8; j++, mask <<= 1) {
  397. if (mask & keyc->modifierMap[i]) {
  398. keyc->modifierKeyMap[(j * keyc->maxKeysPerModifier) +
  399. keysPerModifier[j]] = i;
  400. keysPerModifier[j]++;
  401. }
  402. }
  403. }
  404. return TRUE;
  405. }
  406. _X_EXPORT Bool
  407. InitKeyClassDeviceStruct(DeviceIntPtr dev, KeySymsPtr pKeySyms,
  408. CARD8 pModifiers[])
  409. {
  410. int i;
  411. KeyClassPtr keyc;
  412. keyc = malloc(sizeof(KeyClassRec));
  413. if (!keyc)
  414. return FALSE;
  415. keyc->curKeySyms.map = (KeySym *) NULL;
  416. keyc->curKeySyms.mapWidth = 0;
  417. keyc->curKeySyms.minKeyCode = pKeySyms->minKeyCode;
  418. keyc->curKeySyms.maxKeyCode = pKeySyms->maxKeyCode;
  419. keyc->modifierKeyMap = (KeyCode *) NULL;
  420. keyc->state = 0;
  421. keyc->prev_state = 0;
  422. if (pModifiers)
  423. memmove((char *) keyc->modifierMap, (char *) pModifiers, MAP_LENGTH);
  424. else
  425. bzero((char *) keyc->modifierMap, MAP_LENGTH);
  426. bzero((char *) keyc->down, DOWN_LENGTH);
  427. for (i = 0; i < 8; i++)
  428. keyc->modifierKeyCount[i] = 0;
  429. if (!SetKeySymsMap(&keyc->curKeySyms, pKeySyms) || !InitModMap(keyc)) {
  430. free(keyc->curKeySyms.map);
  431. free(keyc->modifierKeyMap);
  432. free(keyc);
  433. return FALSE;
  434. }
  435. dev->key = keyc;
  436. return TRUE;
  437. }
  438. _X_EXPORT Bool
  439. InitButtonClassDeviceStruct(register DeviceIntPtr dev, int numButtons,
  440. CARD8 *map)
  441. {
  442. ButtonClassPtr butc;
  443. int i;
  444. butc = malloc(sizeof(ButtonClassRec));
  445. if (!butc)
  446. return FALSE;
  447. butc->numButtons = numButtons;
  448. for (i = 1; i <= numButtons; i++)
  449. butc->map[i] = map[i];
  450. butc->buttonsDown = 0;
  451. butc->state = 0;
  452. butc->motionMask = 0;
  453. bzero((char *) butc->down, DOWN_LENGTH);
  454. dev->button = butc;
  455. return TRUE;
  456. }
  457. _X_EXPORT Bool
  458. InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes,
  459. ValuatorMotionProcPtr motionProc,
  460. int numMotionEvents, int mode)
  461. {
  462. int i;
  463. ValuatorClassPtr valc;
  464. valc = malloc(sizeof(ValuatorClassRec) +
  465. numAxes * sizeof(AxisInfo) +
  466. numAxes * sizeof(unsigned int));
  467. if (!valc)
  468. return FALSE;
  469. valc->GetMotionProc = motionProc;
  470. valc->numMotionEvents = numMotionEvents;
  471. valc->motionHintWindow = NullWindow;
  472. valc->numAxes = numAxes;
  473. valc->mode = mode;
  474. valc->axes = (AxisInfoPtr) (valc + 1);
  475. valc->axisVal = (int *) (valc->axes + numAxes);
  476. for (i = 0; i < numAxes; i++)
  477. valc->axisVal[i] = 0;
  478. dev->valuator = valc;
  479. return TRUE;
  480. }
  481. _X_EXPORT Bool
  482. InitFocusClassDeviceStruct(DeviceIntPtr dev)
  483. {
  484. FocusClassPtr focc;
  485. focc = malloc(sizeof(FocusClassRec));
  486. if (!focc)
  487. return FALSE;
  488. focc->win = PointerRootWin;
  489. focc->revert = None;
  490. focc->time = currentTime;
  491. focc->trace = (WindowPtr *) NULL;
  492. focc->traceSize = 0;
  493. focc->traceGood = 0;
  494. dev->focus = focc;
  495. return TRUE;
  496. }
  497. _X_EXPORT Bool
  498. InitKbdFeedbackClassDeviceStruct(DeviceIntPtr dev, BellProcPtr bellProc,
  499. KbdCtrlProcPtr controlProc)
  500. {
  501. KbdFeedbackPtr feedc;
  502. feedc = malloc(sizeof(KbdFeedbackClassRec));
  503. if (!feedc)
  504. return FALSE;
  505. feedc->BellProc = bellProc;
  506. feedc->CtrlProc = controlProc;
  507. feedc->ctrl = defaultKeyboardControl;
  508. feedc->ctrl.id = 0;
  509. if ((feedc->next = dev->kbdfeed) != 0)
  510. feedc->ctrl.id = dev->kbdfeed->ctrl.id + 1;
  511. dev->kbdfeed = feedc;
  512. (*dev->kbdfeed->CtrlProc) (dev, &dev->kbdfeed->ctrl);
  513. return TRUE;
  514. }
  515. _X_EXPORT Bool
  516. InitPtrFeedbackClassDeviceStruct(DeviceIntPtr dev, PtrCtrlProcPtr controlProc)
  517. {
  518. PtrFeedbackPtr feedc;
  519. feedc = malloc(sizeof(PtrFeedbackClassRec));
  520. if (!feedc)
  521. return FALSE;
  522. feedc->CtrlProc = controlProc;
  523. feedc->ctrl = defaultPointerControl;
  524. feedc->ctrl.id = 0;
  525. if ((feedc->next = dev->ptrfeed))
  526. feedc->ctrl.id = dev->ptrfeed->ctrl.id + 1;
  527. dev->ptrfeed = feedc;
  528. (*controlProc) (dev, &feedc->ctrl);
  529. return TRUE;
  530. }
  531. _X_EXPORT Bool
  532. InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons,
  533. ValuatorMotionProcPtr motionProc,
  534. PtrCtrlProcPtr controlProc, int numMotionEvents)
  535. {
  536. DeviceIntPtr dev = (DeviceIntPtr) device;
  537. return (InitButtonClassDeviceStruct(dev, numButtons, map) &&
  538. InitValuatorClassDeviceStruct(dev, 2, motionProc,
  539. numMotionEvents, 0) &&
  540. InitPtrFeedbackClassDeviceStruct(dev, controlProc));
  541. }
  542. _X_EXPORT Bool
  543. InitKeyboardDeviceStruct(DevicePtr device, KeySymsPtr pKeySyms,
  544. CARD8 pModifiers[], BellProcPtr bellProc,
  545. KbdCtrlProcPtr controlProc)
  546. {
  547. DeviceIntPtr dev = (DeviceIntPtr) device;
  548. return (InitKeyClassDeviceStruct(dev, pKeySyms, pModifiers) &&
  549. InitFocusClassDeviceStruct(dev) &&
  550. InitKbdFeedbackClassDeviceStruct(dev, bellProc, controlProc));
  551. }
  552. _X_EXPORT void
  553. SendMappingNotify(unsigned request, unsigned firstKeyCode, unsigned count,
  554. ClientPtr client)
  555. {
  556. int i;
  557. xEvent event;
  558. event.u.u.type = MappingNotify;
  559. event.u.mappingNotify.request = request;
  560. if (request == MappingKeyboard) {
  561. event.u.mappingNotify.firstKeyCode = firstKeyCode;
  562. event.u.mappingNotify.count = count;
  563. }
  564. /* 0 is the server client */
  565. for (i = 1; i < currentMaxClients; i++) {
  566. if (clients[i] && clients[i]->clientState == ClientStateRunning) {
  567. event.u.u.sequenceNumber = clients[i]->sequence;
  568. WriteEventsToClient(clients[i], 1, &event);
  569. }
  570. }
  571. }
  572. /*
  573. * n-squared algorithm. n < 255 and don't want to copy the whole thing and
  574. * sort it to do the checking. How often is it called? Just being lazy?
  575. */
  576. Bool
  577. BadDeviceMap(register BYTE * buff, int length, unsigned low, unsigned high,
  578. XID *errval)
  579. {
  580. int i, j;
  581. for (i = 0; i < length; i++)
  582. if (buff[i]) { /* only check non-zero elements */
  583. if ((low > buff[i]) || (high < buff[i])) {
  584. *errval = buff[i];
  585. return TRUE;
  586. }
  587. for (j = i + 1; j < length; j++)
  588. if (buff[i] == buff[j]) {
  589. *errval = buff[i];
  590. return TRUE;
  591. }
  592. }
  593. return FALSE;
  594. }
  595. Bool
  596. AllModifierKeysAreUp(dev, map1, per1, map2, per2)
  597. DeviceIntPtr dev;
  598. CARD8 *map1, *map2;
  599. int per1, per2;
  600. {
  601. int i, j, k;
  602. CARD8 *down = dev->key->down;
  603. for (i = 8; --i >= 0; map2 += per2) {
  604. for (j = per1; --j >= 0; map1++) {
  605. if (*map1 && BitIsOn(down, *map1)) {
  606. for (k = per2; (--k >= 0) && (*map1 != map2[k]););
  607. if (k < 0)
  608. return FALSE;
  609. }
  610. }
  611. }
  612. return TRUE;
  613. }
  614. int
  615. ProcSetModifierMapping(ClientPtr client)
  616. {
  617. xSetModifierMappingReply rep;
  618. REQUEST(xSetModifierMappingReq);
  619. KeyCode *inputMap;
  620. int inputMapLen;
  621. int i;
  622. DeviceIntPtr keybd = inputInfo.keyboard;
  623. KeyClassPtr keyc = keybd->key;
  624. REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
  625. if (client->req_len != ((stuff->numKeyPerModifier << 1) +
  626. (sizeof(xSetModifierMappingReq) >> 2)))
  627. return BadLength;
  628. inputMapLen = 8 * stuff->numKeyPerModifier;
  629. inputMap = (KeyCode *) &stuff[1];
  630. /*
  631. * Now enforce the restriction that "all of the non-zero keycodes must be
  632. * in the range specified by min-keycode and max-keycode in the
  633. * connection setup (else a Value error)"
  634. */
  635. i = inputMapLen;
  636. while (i--) {
  637. if (inputMap[i]
  638. && (inputMap[i] < keyc->curKeySyms.minKeyCode
  639. || inputMap[i] > keyc->curKeySyms.maxKeyCode)) {
  640. client->errorValue = inputMap[i];
  641. return BadValue;
  642. }
  643. }
  644. rep.type = X_Reply;
  645. rep.length = 0;
  646. rep.sequenceNumber = client->sequence;
  647. rep.success = MappingSuccess;
  648. /*
  649. * Now enforce the restriction that none of the old or new
  650. * modifier keys may be down while we change the mapping, and
  651. * that the DDX layer likes the choice.
  652. */
  653. if (!AllModifierKeysAreUp(keybd, keyc->modifierKeyMap,
  654. (int) keyc->maxKeysPerModifier,
  655. inputMap, (int) stuff->numKeyPerModifier)
  656. ||
  657. !AllModifierKeysAreUp(keybd, inputMap, (int) stuff->numKeyPerModifier,
  658. keyc->modifierKeyMap,
  659. (int) keyc->maxKeysPerModifier)) {
  660. rep.success = MappingBusy;
  661. }
  662. else {
  663. for (i = 0; i < inputMapLen; i++) {
  664. if (inputMap[i] && !LegalModifier(inputMap[i], (DevicePtr) keybd)) {
  665. rep.success = MappingFailed;
  666. break;
  667. }
  668. }
  669. }
  670. if (rep.success == MappingSuccess) {
  671. KeyCode *map;
  672. /*
  673. * Now build the keyboard's modifier bitmap from the
  674. * list of keycodes.
  675. */
  676. map = malloc(inputMapLen);
  677. if (!map && inputMapLen)
  678. return BadAlloc;
  679. if (keyc->modifierKeyMap)
  680. free(keyc->modifierKeyMap);
  681. keyc->modifierKeyMap = map;
  682. memmove((char *) map, (char *) inputMap, inputMapLen);
  683. keyc->maxKeysPerModifier = stuff->numKeyPerModifier;
  684. for (i = 0; i < MAP_LENGTH; i++)
  685. keyc->modifierMap[i] = 0;
  686. for (i = 0; i < inputMapLen; i++) {
  687. if (inputMap[i])
  688. keyc->modifierMap[inputMap[i]] |=
  689. (1 << (((unsigned int) i) / keyc->maxKeysPerModifier));
  690. }
  691. }
  692. if (rep.success == MappingSuccess)
  693. SendMappingNotify(MappingModifier, 0, 0, client);
  694. WriteReplyToClient(client, sizeof(xSetModifierMappingReply), &rep);
  695. return (client->noClientException);
  696. }
  697. int
  698. ProcGetModifierMapping(ClientPtr client)
  699. {
  700. xGetModifierMappingReply rep = {0};
  701. KeyClassPtr keyc = inputInfo.keyboard->key;
  702. REQUEST_SIZE_MATCH(xReq);
  703. memset(&rep, 0, sizeof(xGetModifierMappingReply));
  704. rep.type = X_Reply;
  705. rep.numKeyPerModifier = keyc->maxKeysPerModifier;
  706. rep.sequenceNumber = client->sequence;
  707. /* length counts 4 byte quantities - there are 8 modifiers 1 byte big */
  708. rep.length = keyc->maxKeysPerModifier << 1;
  709. WriteReplyToClient(client, sizeof(xGetModifierMappingReply), &rep);
  710. /* Use the (modified by DDX) map that SetModifierMapping passed in */
  711. (void) WriteToClient(client, (int) (keyc->maxKeysPerModifier << 3),
  712. (char *) keyc->modifierKeyMap);
  713. return client->noClientException;
  714. }
  715. int
  716. ProcChangeKeyboardMapping(ClientPtr client)
  717. {
  718. REQUEST(xChangeKeyboardMappingReq);
  719. unsigned len;
  720. KeySymsRec keysyms;
  721. KeySymsPtr curKeySyms = &inputInfo.keyboard->key->curKeySyms;
  722. REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq);
  723. len = client->req_len - (sizeof(xChangeKeyboardMappingReq) >> 2);
  724. if (len != (stuff->keyCodes * stuff->keySymsPerKeyCode))
  725. return BadLength;
  726. if ((stuff->firstKeyCode < curKeySyms->minKeyCode) ||
  727. (stuff->firstKeyCode > curKeySyms->maxKeyCode)) {
  728. client->errorValue = stuff->firstKeyCode;
  729. return BadValue;
  730. }
  731. if (((unsigned) (stuff->firstKeyCode + stuff->keyCodes - 1) >
  732. curKeySyms->maxKeyCode) || (stuff->keySymsPerKeyCode == 0)) {
  733. client->errorValue = stuff->keySymsPerKeyCode;
  734. return BadValue;
  735. }
  736. keysyms.minKeyCode = stuff->firstKeyCode;
  737. keysyms.maxKeyCode = stuff->firstKeyCode + stuff->keyCodes - 1;
  738. keysyms.mapWidth = stuff->keySymsPerKeyCode;
  739. keysyms.map = (KeySym *) & stuff[1];
  740. if (!SetKeySymsMap(curKeySyms, &keysyms))
  741. return BadAlloc;
  742. SendMappingNotify(MappingKeyboard, stuff->firstKeyCode, stuff->keyCodes,
  743. client);
  744. return client->noClientException;
  745. }
  746. int
  747. ProcSetPointerMapping(ClientPtr client)
  748. {
  749. REQUEST(xSetPointerMappingReq);
  750. BYTE *map;
  751. xSetPointerMappingReply rep;
  752. unsigned int i;
  753. DeviceIntPtr mouse = inputInfo.pointer;
  754. REQUEST_AT_LEAST_SIZE(xSetPointerMappingReq);
  755. if (client->req_len !=
  756. (sizeof(xSetPointerMappingReq) + stuff->nElts + 3) >> 2)
  757. return BadLength;
  758. rep.type = X_Reply;
  759. rep.length = 0;
  760. rep.sequenceNumber = client->sequence;
  761. rep.success = MappingSuccess;
  762. map = (BYTE *) & stuff[1];
  763. if (stuff->nElts != mouse->button->numButtons) {
  764. client->errorValue = stuff->nElts;
  765. return BadValue;
  766. }
  767. if (BadDeviceMap(&map[0], (int) stuff->nElts, 1, 255, &client->errorValue))
  768. return BadValue;
  769. for (i = 0; i < stuff->nElts; i++)
  770. if ((mouse->button->map[i + 1] != map[i]) &&
  771. BitIsOn(mouse->button->down, i + 1)) {
  772. rep.success = MappingBusy;
  773. WriteReplyToClient(client, sizeof(xSetPointerMappingReply), &rep);
  774. return Success;
  775. }
  776. for (i = 0; i < stuff->nElts; i++)
  777. mouse->button->map[i + 1] = map[i];
  778. SendMappingNotify(MappingPointer, 0, 0, client);
  779. WriteReplyToClient(client, sizeof(xSetPointerMappingReply), &rep);
  780. return Success;
  781. }
  782. int
  783. ProcGetKeyboardMapping(ClientPtr client)
  784. {
  785. xGetKeyboardMappingReply rep = {0};
  786. REQUEST(xGetKeyboardMappingReq);
  787. KeySymsPtr curKeySyms = &inputInfo.keyboard->key->curKeySyms;
  788. REQUEST_SIZE_MATCH(xGetKeyboardMappingReq);
  789. if ((stuff->firstKeyCode < curKeySyms->minKeyCode) ||
  790. (stuff->firstKeyCode > curKeySyms->maxKeyCode)) {
  791. client->errorValue = stuff->firstKeyCode;
  792. return BadValue;
  793. }
  794. if (stuff->firstKeyCode + stuff->count >
  795. (unsigned) (curKeySyms->maxKeyCode + 1)) {
  796. client->errorValue = stuff->count;
  797. return BadValue;
  798. }
  799. memset(&rep, 0, sizeof(xGetKeyboardMappingReply));
  800. rep.type = X_Reply;
  801. rep.sequenceNumber = client->sequence;
  802. rep.keySymsPerKeyCode = curKeySyms->mapWidth;
  803. /* length is a count of 4 byte quantities and KeySyms are 4 bytes */
  804. rep.length = (curKeySyms->mapWidth * stuff->count);
  805. WriteReplyToClient(client, sizeof(xGetKeyboardMappingReply), &rep);
  806. client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
  807. WriteSwappedDataToClient(client,
  808. curKeySyms->mapWidth * stuff->count *
  809. sizeof(KeySym),
  810. &curKeySyms->
  811. map[(stuff->firstKeyCode -
  812. curKeySyms->minKeyCode) *
  813. curKeySyms->mapWidth]);
  814. return client->noClientException;
  815. }
  816. int
  817. ProcGetPointerMapping(ClientPtr client)
  818. {
  819. xGetPointerMappingReply rep;
  820. ButtonClassPtr butc = inputInfo.pointer->button;
  821. REQUEST_SIZE_MATCH(xReq);
  822. rep.type = X_Reply;
  823. rep.sequenceNumber = client->sequence;
  824. rep.nElts = butc->numButtons;
  825. rep.length = ((unsigned) rep.nElts + (4 - 1)) / 4;
  826. WriteReplyToClient(client, sizeof(xGetPointerMappingReply), &rep);
  827. (void) WriteToClient(client, (int) rep.nElts, (char *) &butc->map[1]);
  828. return Success;
  829. }
  830. void
  831. NoteLedState(DeviceIntPtr keybd, int led, Bool on)
  832. {
  833. KeybdCtrl *ctrl = &keybd->kbdfeed->ctrl;
  834. if (on)
  835. ctrl->leds |= ((Leds) 1 << (led - 1));
  836. else
  837. ctrl->leds &= ~((Leds) 1 << (led - 1));
  838. }
  839. _X_EXPORT int
  840. Ones(unsigned long mask)
  841. { /* HACKMEM 169 */
  842. unsigned long y;
  843. y = (mask >> 1) & 033333333333;
  844. y = mask - y - ((y >> 1) & 033333333333);
  845. return (((y + (y >> 3)) & 030707070707) % 077);
  846. }
  847. int
  848. ProcChangeKeyboardControl(ClientPtr client)
  849. {
  850. #define DO_ALL (-1)
  851. KeybdCtrl ctrl;
  852. DeviceIntPtr keybd = inputInfo.keyboard;
  853. XID *vlist;
  854. int t;
  855. int led = DO_ALL;
  856. int key = DO_ALL;
  857. BITS32 vmask, index2;
  858. int mask, i;
  859. REQUEST(xChangeKeyboardControlReq);
  860. REQUEST_AT_LEAST_SIZE(xChangeKeyboardControlReq);
  861. vmask = stuff->mask;
  862. if (client->req_len !=
  863. (sizeof(xChangeKeyboardControlReq) >> 2) + Ones(vmask))
  864. return BadLength;
  865. vlist = (XID *) &stuff[1]; /* first word of values */
  866. ctrl = keybd->kbdfeed->ctrl;
  867. while (vmask) {
  868. index2 = (BITS32) lowbit(vmask);
  869. vmask &= ~index2;
  870. switch (index2) {
  871. case KBKeyClickPercent:
  872. t = (INT8) *vlist;
  873. vlist++;
  874. if (t == -1)
  875. t = defaultKeyboardControl.click;
  876. else if (t < 0 || t > 100) {
  877. client->errorValue = t;
  878. return BadValue;
  879. }
  880. ctrl.click = t;
  881. break;
  882. case KBBellPercent:
  883. t = (INT8) *vlist;
  884. vlist++;
  885. if (t == -1)
  886. t = defaultKeyboardControl.bell;
  887. else if (t < 0 || t > 100) {
  888. client->errorValue = t;
  889. return BadValue;
  890. }
  891. ctrl.bell = t;
  892. break;
  893. case KBBellPitch:
  894. t = (INT16) *vlist;
  895. vlist++;
  896. if (t == -1)
  897. t = defaultKeyboardControl.bell_pitch;
  898. else if (t < 0) {
  899. client->errorValue = t;
  900. return BadValue;
  901. }
  902. ctrl.bell_pitch = t;
  903. break;
  904. case KBBellDuration:
  905. t = (INT16) *vlist;
  906. vlist++;
  907. if (t == -1)
  908. t = defaultKeyboardControl.bell_duration;
  909. else if (t < 0) {
  910. client->errorValue = t;
  911. return BadValue;
  912. }
  913. ctrl.bell_duration = t;
  914. break;
  915. case KBLed:
  916. led = (CARD8) *vlist;
  917. vlist++;
  918. if (led < 1 || led > 32) {
  919. client->errorValue = led;
  920. return BadValue;
  921. }
  922. if (!(stuff->mask & KBLedMode))
  923. return BadMatch;
  924. break;
  925. case KBLedMode:
  926. t = (CARD8) *vlist;
  927. vlist++;
  928. if (t == LedModeOff) {
  929. if (led == DO_ALL)
  930. ctrl.leds = 0x0;
  931. else
  932. ctrl.leds &= ~(((Leds) (1)) << (led - 1));
  933. }
  934. else if (t == LedModeOn) {
  935. if (led == DO_ALL)
  936. ctrl.leds = ~0L;
  937. else
  938. ctrl.leds |= (((Leds) (1)) << (led - 1));
  939. }
  940. else {
  941. client->errorValue = t;
  942. return BadValue;
  943. }
  944. break;
  945. case KBKey:
  946. key = (KeyCode) *vlist;
  947. vlist++;
  948. if ((KeyCode) key < inputInfo.keyboard->key->curKeySyms.minKeyCode
  949. || (KeyCode) key >
  950. inputInfo.keyboard->key->curKeySyms.maxKeyCode) {
  951. client->errorValue = key;
  952. return BadValue;
  953. }
  954. if (!(stuff->mask & KBAutoRepeatMode))
  955. return BadMatch;
  956. break;
  957. case KBAutoRepeatMode:
  958. i = (key >> 3);
  959. mask = (1 << (key & 7));
  960. t = (CARD8) *vlist;
  961. vlist++;
  962. if (t == AutoRepeatModeOff) {
  963. if (key == DO_ALL)
  964. ctrl.autoRepeat = FALSE;
  965. else
  966. ctrl.autoRepeats[i] &= ~mask;
  967. }
  968. else if (t == AutoRepeatModeOn) {
  969. if (key == DO_ALL)
  970. ctrl.autoRepeat = TRUE;
  971. else
  972. ctrl.autoRepeats[i] |= mask;
  973. }
  974. else if (t == AutoRepeatModeDefault) {
  975. if (key == DO_ALL)
  976. ctrl.autoRepeat = defaultKeyboardControl.autoRepeat;
  977. else
  978. ctrl.autoRepeats[i] =
  979. (ctrl.autoRepeats[i] & ~mask) |
  980. (defaultKeyboardControl.autoRepeats[i] & mask);
  981. }
  982. else {
  983. client->errorValue = t;
  984. return BadValue;
  985. }
  986. break;
  987. default:
  988. client->errorValue = stuff->mask;
  989. return BadValue;
  990. }
  991. }
  992. keybd->kbdfeed->ctrl = ctrl;
  993. (*keybd->kbdfeed->CtrlProc) (keybd, &keybd->kbdfeed->ctrl);
  994. return Success;
  995. #undef DO_ALL
  996. }
  997. int
  998. ProcGetKeyboardControl(ClientPtr client)
  999. {
  1000. int i;
  1001. KeybdCtrl *ctrl = &inputInfo.keyboard->kbdfeed->ctrl;
  1002. xGetKeyboardControlReply rep;
  1003. REQUEST_SIZE_MATCH(xReq);
  1004. rep.type = X_Reply;
  1005. rep.length = 5;
  1006. rep.sequenceNumber = client->sequence;
  1007. rep.globalAutoRepeat = ctrl->autoRepeat;
  1008. rep.keyClickPercent = ctrl->click;
  1009. rep.bellPercent = ctrl->bell;
  1010. rep.bellPitch = ctrl->bell_pitch;
  1011. rep.bellDuration = ctrl->bell_duration;
  1012. rep.ledMask = ctrl->leds;
  1013. for (i = 0; i < 32; i++)
  1014. rep.map[i] = ctrl->autoRepeats[i];
  1015. WriteReplyToClient(client, sizeof(xGetKeyboardControlReply), &rep);
  1016. return Success;
  1017. }
  1018. int
  1019. ProcBell(ClientPtr client)
  1020. {
  1021. DeviceIntPtr keybd = inputInfo.keyboard;
  1022. int base = keybd->kbdfeed->ctrl.bell;
  1023. int newpercent;
  1024. REQUEST(xBellReq);
  1025. REQUEST_SIZE_MATCH(xBellReq);
  1026. if (stuff->percent < -100 || stuff->percent > 100) {
  1027. client->errorValue = stuff->percent;
  1028. return BadValue;
  1029. }
  1030. newpercent = (base * stuff->percent) / 100;
  1031. if (stuff->percent < 0)
  1032. newpercent = base + newpercent;
  1033. else
  1034. newpercent = base - newpercent + stuff->percent;
  1035. (*keybd->kbdfeed->BellProc) (newpercent, keybd,
  1036. (pointer) &keybd->kbdfeed->ctrl, 0);
  1037. return Success;
  1038. }
  1039. int
  1040. ProcChangePointerControl(ClientPtr client)
  1041. {
  1042. DeviceIntPtr mouse = inputInfo.pointer;
  1043. PtrCtrl ctrl; /* might get BadValue part way through */
  1044. REQUEST(xChangePointerControlReq);
  1045. REQUEST_SIZE_MATCH(xChangePointerControlReq);
  1046. ctrl = mouse->ptrfeed->ctrl;
  1047. if ((stuff->doAccel != xTrue) && (stuff->doAccel != xFalse)) {
  1048. client->errorValue = stuff->doAccel;
  1049. return (BadValue);
  1050. }
  1051. if ((stuff->doThresh != xTrue) && (stuff->doThresh != xFalse)) {
  1052. client->errorValue = stuff->doThresh;
  1053. return (BadValue);
  1054. }
  1055. if (stuff->doAccel) {
  1056. if (stuff->accelNum == -1)
  1057. ctrl.num = defaultPointerControl.num;
  1058. else if (stuff->accelNum < 0) {
  1059. client->errorValue = stuff->accelNum;
  1060. return BadValue;
  1061. }
  1062. else
  1063. ctrl.num = stuff->accelNum;
  1064. if (stuff->accelDenum == -1)
  1065. ctrl.den = defaultPointerControl.den;
  1066. else if (stuff->accelDenum <= 0) {
  1067. client->errorValue = stuff->accelDenum;
  1068. return BadValue;
  1069. }
  1070. else
  1071. ctrl.den = stuff->accelDenum;
  1072. }
  1073. if (stuff->doThresh) {
  1074. if (stuff->threshold == -1)
  1075. ctrl.threshold = defaultPointerControl.threshold;
  1076. else if (stuff->threshold < 0) {
  1077. client->errorValue = stuff->threshold;
  1078. return BadValue;
  1079. }
  1080. else
  1081. ctrl.threshold = stuff->threshold;
  1082. }
  1083. mouse->ptrfeed->ctrl = ctrl;
  1084. (*mouse->ptrfeed->CtrlProc) (mouse, &mouse->ptrfeed->ctrl);
  1085. return Success;
  1086. }
  1087. int
  1088. ProcGetPointerControl(ClientPtr client)
  1089. {
  1090. PtrCtrl *ctrl = &inputInfo.pointer->ptrfeed->ctrl;
  1091. xGetPointerControlReply rep;
  1092. REQUEST_SIZE_MATCH(xReq);
  1093. rep.type = X_Reply;
  1094. rep.length = 0;
  1095. rep.sequenceNumber = client->sequence;
  1096. rep.threshold = ctrl->threshold;
  1097. rep.accelNumerator = ctrl->num;
  1098. rep.accelDenominator = ctrl->den;
  1099. WriteReplyToClient(client, sizeof(xGenericReply), &rep);
  1100. return Success;
  1101. }
  1102. void
  1103. MaybeStopHint(register DeviceIntPtr dev, ClientPtr client)
  1104. {
  1105. GrabPtr grab = dev->grab;
  1106. if ((grab && SameClient(grab, client) &&
  1107. ((grab->eventMask & PointerMotionHintMask) ||
  1108. (grab->ownerEvents &&
  1109. (EventMaskForClient(dev->valuator->motionHintWindow, client) &
  1110. PointerMotionHintMask)))) ||
  1111. (!grab &&
  1112. (EventMaskForClient(dev->valuator->motionHintWindow, client) &
  1113. PointerMotionHintMask)))
  1114. dev->valuator->motionHintWindow = NullWindow;
  1115. }
  1116. int
  1117. ProcGetMotionEvents(ClientPtr client)
  1118. {
  1119. WindowPtr pWin;
  1120. xTimecoord *coords = (xTimecoord *) NULL;
  1121. xGetMotionEventsReply rep;
  1122. int i, count, xmin, xmax, ymin, ymax;
  1123. unsigned long nEvents;
  1124. DeviceIntPtr mouse = inputInfo.pointer;
  1125. TimeStamp start, stop;
  1126. REQUEST(xGetMotionEventsReq);
  1127. REQUEST_SIZE_MATCH(xGetMotionEventsReq);
  1128. pWin = SecurityLookupWindow(stuff->window, client, TRUE);
  1129. if (!pWin)
  1130. return BadWindow;
  1131. if (mouse->valuator->motionHintWindow)
  1132. MaybeStopHint(mouse, client);
  1133. rep.type = X_Reply;
  1134. rep.sequenceNumber = client->sequence;
  1135. nEvents = 0;
  1136. start = ClientTimeToServerTime(stuff->start);
  1137. stop = ClientTimeToServerTime(stuff->stop);
  1138. if ((CompareTimeStamps(start, stop) != LATER) &&
  1139. (CompareTimeStamps(start, currentTime) != LATER) &&
  1140. mouse->valuator->numMotionEvents) {
  1141. if (CompareTimeStamps(stop, currentTime) == LATER)
  1142. stop = currentTime;
  1143. coords = (xTimecoord *) ALLOCATE_LOCAL(mouse->valuator->numMotionEvents
  1144. * sizeof(xTimecoord));
  1145. if (!coords)
  1146. return BadAlloc;
  1147. count = (*mouse->valuator->GetMotionProc) (mouse, coords,
  1148. start.milliseconds,
  1149. stop.milliseconds,
  1150. pWin->drawable.pScreen);
  1151. xmin = pWin->drawable.x - wBorderWidth(pWin);
  1152. xmax = pWin->drawable.x + (int) pWin->drawable.width +
  1153. wBorderWidth(pWin);
  1154. ymin = pWin->drawable.y - wBorderWidth(pWin);
  1155. ymax = pWin->drawable.y + (int) pWin->drawable.height +
  1156. wBorderWidth(pWin);
  1157. for (i = 0; i < count; i++)
  1158. if ((xmin <= coords[i].x) && (coords[i].x < xmax) &&
  1159. (ymin <= coords[i].y) && (coords[i].y < ymax)) {
  1160. coords[nEvents].time = coords[i].time;
  1161. coords[nEvents].x = coords[i].x - pWin->drawable.x;
  1162. coords[nEvents].y = coords[i].y - pWin->drawable.y;
  1163. nEvents++;
  1164. }
  1165. }
  1166. rep.length = nEvents * (sizeof(xTimecoord) >> 2);
  1167. rep.nEvents = nEvents;
  1168. WriteReplyToClient(client, sizeof(xGetMotionEventsReply), &rep);
  1169. if (nEvents) {
  1170. client->pSwapReplyFunc = (ReplySwapPtr) SwapTimeCoordWrite;
  1171. WriteSwappedDataToClient(client, nEvents * sizeof(xTimecoord),
  1172. (char *) coords);
  1173. }
  1174. if (coords)
  1175. DEALLOCATE_LOCAL(coords);
  1176. return Success;
  1177. }
  1178. int
  1179. ProcQueryKeymap(ClientPtr client)
  1180. {
  1181. xQueryKeymapReply rep;
  1182. int i;
  1183. CARD8 *down = inputInfo.keyboard->key->down;
  1184. REQUEST_SIZE_MATCH(xReq);
  1185. rep.type = X_Reply;
  1186. rep.sequenceNumber = client->sequence;
  1187. rep.length = 2;
  1188. for (i = 0; i < 32; i++)
  1189. rep.map[i] = down[i];
  1190. WriteReplyToClient(client, sizeof(xQueryKeymapReply), &rep);
  1191. return Success;
  1192. }