xkbAccessX.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /************************************************************
  2. Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
  3. Permission to use, copy, modify, and distribute this
  4. software and its documentation for any purpose and without
  5. fee is hereby granted, provided that the above copyright
  6. notice appear in all copies and that both that copyright
  7. notice and this permission notice appear in supporting
  8. documentation, and that the name of Silicon Graphics not be
  9. used in advertising or publicity pertaining to distribution
  10. of the software without specific prior written permission.
  11. Silicon Graphics makes no representation about the suitability
  12. of this software for any purpose. It is provided "as is"
  13. without any express or implied warranty.
  14. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  15. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  16. AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  18. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  20. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
  21. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. ********************************************************/
  23. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include <stdio.h>
  27. #include <math.h>
  28. #include <X11/X.h>
  29. #include <X11/Xproto.h>
  30. #include <X11/keysym.h>
  31. #include "exglobals.h"
  32. #include <X11/extensions/XIproto.h>
  33. #include "inputstr.h"
  34. #include "eventstr.h"
  35. #include "inpututils.h"
  36. #include <xkbsrv.h>
  37. #if !defined(WIN32)
  38. #include <sys/time.h>
  39. #endif
  40. int XkbDfltRepeatDelay = 660;
  41. int XkbDfltRepeatInterval = 40;
  42. #define DFLT_TIMEOUT_CTRLS (XkbAX_KRGMask|XkbStickyKeysMask|XkbMouseKeysMask)
  43. #define DFLT_TIMEOUT_OPTS (XkbAX_IndicatorFBMask)
  44. unsigned short XkbDfltAccessXTimeout = 120;
  45. unsigned int XkbDfltAccessXTimeoutMask = DFLT_TIMEOUT_CTRLS;
  46. static unsigned int XkbDfltAccessXTimeoutValues = 0;
  47. static unsigned int XkbDfltAccessXTimeoutOptionsMask = DFLT_TIMEOUT_OPTS;
  48. static unsigned int XkbDfltAccessXTimeoutOptionsValues = 0;
  49. unsigned int XkbDfltAccessXFeedback = XkbAccessXFeedbackMask;
  50. unsigned short XkbDfltAccessXOptions =
  51. XkbAX_AllOptionsMask & ~(XkbAX_IndicatorFBMask | XkbAX_SKReleaseFBMask |
  52. XkbAX_SKRejectFBMask);
  53. void
  54. AccessXComputeCurveFactor(XkbSrvInfoPtr xkbi, XkbControlsPtr ctrls)
  55. {
  56. xkbi->mouseKeysCurve = 1.0 + (((double) ctrls->mk_curve) * 0.001);
  57. xkbi->mouseKeysCurveFactor = (((double) ctrls->mk_max_speed) /
  58. pow((double) ctrls->mk_time_to_max,
  59. xkbi->mouseKeysCurve));
  60. return;
  61. }
  62. void
  63. AccessXInit(DeviceIntPtr keybd)
  64. {
  65. XkbSrvInfoPtr xkbi = keybd->key->xkbInfo;
  66. XkbControlsPtr ctrls = xkbi->desc->ctrls;
  67. xkbi->shiftKeyCount = 0;
  68. xkbi->mouseKeysCounter = 0;
  69. xkbi->inactiveKey = 0;
  70. xkbi->slowKey = 0;
  71. xkbi->repeatKey = 0;
  72. xkbi->krgTimerActive = _OFF_TIMER;
  73. xkbi->beepType = _BEEP_NONE;
  74. xkbi->beepCount = 0;
  75. xkbi->mouseKeyTimer = NULL;
  76. xkbi->slowKeysTimer = NULL;
  77. xkbi->bounceKeysTimer = NULL;
  78. xkbi->repeatKeyTimer = NULL;
  79. xkbi->krgTimer = NULL;
  80. xkbi->beepTimer = NULL;
  81. ctrls->repeat_delay = XkbDfltRepeatDelay;
  82. ctrls->repeat_interval = XkbDfltRepeatInterval;
  83. ctrls->debounce_delay = 300;
  84. ctrls->slow_keys_delay = 300;
  85. ctrls->mk_delay = 160;
  86. ctrls->mk_interval = 40;
  87. ctrls->mk_time_to_max = 30;
  88. ctrls->mk_max_speed = 30;
  89. ctrls->mk_curve = 500;
  90. ctrls->mk_dflt_btn = 1;
  91. ctrls->ax_timeout = XkbDfltAccessXTimeout;
  92. ctrls->axt_ctrls_mask = XkbDfltAccessXTimeoutMask;
  93. ctrls->axt_ctrls_values = XkbDfltAccessXTimeoutValues;
  94. ctrls->axt_opts_mask = XkbDfltAccessXTimeoutOptionsMask;
  95. ctrls->axt_opts_values = XkbDfltAccessXTimeoutOptionsValues;
  96. if (XkbDfltAccessXTimeout)
  97. ctrls->enabled_ctrls |= XkbAccessXTimeoutMask;
  98. else
  99. ctrls->enabled_ctrls &= ~XkbAccessXTimeoutMask;
  100. ctrls->enabled_ctrls |= XkbDfltAccessXFeedback;
  101. ctrls->ax_options = XkbDfltAccessXOptions;
  102. AccessXComputeCurveFactor(xkbi, ctrls);
  103. return;
  104. }
  105. /************************************************************************/
  106. /* */
  107. /* AccessXKeyboardEvent */
  108. /* */
  109. /* Generate a synthetic keyboard event. */
  110. /* */
  111. /************************************************************************/
  112. static void
  113. AccessXKeyboardEvent(DeviceIntPtr keybd, int type, BYTE keyCode, Bool isRepeat)
  114. {
  115. DeviceEvent event;
  116. init_device_event(&event, keybd, GetTimeInMillis());
  117. event.type = type;
  118. event.detail.key = keyCode;
  119. event.key_repeat = isRepeat;
  120. if (xkbDebugFlags & 0x8) {
  121. DebugF("[xkb] AXKE: Key %d %s\n", keyCode,
  122. (event.type == ET_KeyPress ? "down" : "up"));
  123. }
  124. XkbProcessKeyboardEvent(&event, keybd);
  125. return;
  126. } /* AccessXKeyboardEvent */
  127. /************************************************************************/
  128. /* */
  129. /* AccessXKRGTurnOn */
  130. /* */
  131. /* Turn the keyboard response group on. */
  132. /* */
  133. /************************************************************************/
  134. static void
  135. AccessXKRGTurnOn(DeviceIntPtr dev, CARD16 KRGControl, xkbControlsNotify * pCN)
  136. {
  137. XkbSrvInfoPtr xkbi = dev->key->xkbInfo;
  138. XkbControlsPtr ctrls = xkbi->desc->ctrls;
  139. XkbControlsRec old;
  140. XkbEventCauseRec cause;
  141. XkbSrvLedInfoPtr sli;
  142. old = *ctrls;
  143. ctrls->enabled_ctrls |= (KRGControl & XkbAX_KRGMask);
  144. if (XkbComputeControlsNotify(dev, &old, ctrls, pCN, FALSE))
  145. XkbSendControlsNotify(dev, pCN);
  146. cause.kc = pCN->keycode;
  147. cause.event = pCN->eventType;
  148. cause.mjr = pCN->requestMajor;
  149. cause.mnr = pCN->requestMinor;
  150. sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId, 0);
  151. XkbUpdateIndicators(dev, sli->usesControls, TRUE, NULL, &cause);
  152. if (XkbAX_NeedFeedback(ctrls, XkbAX_FeatureFBMask))
  153. XkbDDXAccessXBeep(dev, _BEEP_FEATURE_ON, KRGControl);
  154. return;
  155. } /* AccessXKRGTurnOn */
  156. /************************************************************************/
  157. /* */
  158. /* AccessXKRGTurnOff */
  159. /* */
  160. /* Turn the keyboard response group off. */
  161. /* */
  162. /************************************************************************/
  163. static void
  164. AccessXKRGTurnOff(DeviceIntPtr dev, xkbControlsNotify * pCN)
  165. {
  166. XkbSrvInfoPtr xkbi = dev->key->xkbInfo;
  167. XkbControlsPtr ctrls = xkbi->desc->ctrls;
  168. XkbControlsRec old;
  169. XkbEventCauseRec cause;
  170. XkbSrvLedInfoPtr sli;
  171. old = *ctrls;
  172. ctrls->enabled_ctrls &= ~XkbAX_KRGMask;
  173. if (XkbComputeControlsNotify(dev, &old, ctrls, pCN, FALSE))
  174. XkbSendControlsNotify(dev, pCN);
  175. cause.kc = pCN->keycode;
  176. cause.event = pCN->eventType;
  177. cause.mjr = pCN->requestMajor;
  178. cause.mnr = pCN->requestMinor;
  179. sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId, 0);
  180. XkbUpdateIndicators(dev, sli->usesControls, TRUE, NULL, &cause);
  181. if (XkbAX_NeedFeedback(ctrls, XkbAX_FeatureFBMask)) {
  182. unsigned changes = old.enabled_ctrls ^ ctrls->enabled_ctrls;
  183. XkbDDXAccessXBeep(dev, _BEEP_FEATURE_OFF, changes);
  184. }
  185. return;
  186. } /* AccessXKRGTurnOff */
  187. /************************************************************************/
  188. /* */
  189. /* AccessXStickyKeysTurnOn */
  190. /* */
  191. /* Turn StickyKeys on. */
  192. /* */
  193. /************************************************************************/
  194. static void
  195. AccessXStickyKeysTurnOn(DeviceIntPtr dev, xkbControlsNotify * pCN)
  196. {
  197. XkbSrvInfoPtr xkbi = dev->key->xkbInfo;
  198. XkbControlsPtr ctrls = xkbi->desc->ctrls;
  199. XkbControlsRec old;
  200. XkbEventCauseRec cause;
  201. XkbSrvLedInfoPtr sli;
  202. old = *ctrls;
  203. ctrls->enabled_ctrls |= XkbStickyKeysMask;
  204. xkbi->shiftKeyCount = 0;
  205. if (XkbComputeControlsNotify(dev, &old, ctrls, pCN, FALSE))
  206. XkbSendControlsNotify(dev, pCN);
  207. cause.kc = pCN->keycode;
  208. cause.event = pCN->eventType;
  209. cause.mjr = pCN->requestMajor;
  210. cause.mnr = pCN->requestMinor;
  211. sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId, 0);
  212. XkbUpdateIndicators(dev, sli->usesControls, TRUE, NULL, &cause);
  213. if (XkbAX_NeedFeedback(ctrls, XkbAX_FeatureFBMask)) {
  214. XkbDDXAccessXBeep(dev, _BEEP_FEATURE_ON, XkbStickyKeysMask);
  215. }
  216. return;
  217. } /* AccessXStickyKeysTurnOn */
  218. /************************************************************************/
  219. /* */
  220. /* AccessXStickyKeysTurnOff */
  221. /* */
  222. /* Turn StickyKeys off. */
  223. /* */
  224. /************************************************************************/
  225. static void
  226. AccessXStickyKeysTurnOff(DeviceIntPtr dev, xkbControlsNotify * pCN)
  227. {
  228. XkbSrvInfoPtr xkbi = dev->key->xkbInfo;
  229. XkbControlsPtr ctrls = xkbi->desc->ctrls;
  230. XkbControlsRec old;
  231. XkbEventCauseRec cause;
  232. XkbSrvLedInfoPtr sli;
  233. old = *ctrls;
  234. ctrls->enabled_ctrls &= ~XkbStickyKeysMask;
  235. xkbi->shiftKeyCount = 0;
  236. if (XkbComputeControlsNotify(dev, &old, ctrls, pCN, FALSE))
  237. XkbSendControlsNotify(dev, pCN);
  238. cause.kc = pCN->keycode;
  239. cause.event = pCN->eventType;
  240. cause.mjr = pCN->requestMajor;
  241. cause.mnr = pCN->requestMinor;
  242. sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId, 0);
  243. XkbUpdateIndicators(dev, sli->usesControls, TRUE, NULL, &cause);
  244. if (XkbAX_NeedFeedback(ctrls, XkbAX_FeatureFBMask)) {
  245. XkbDDXAccessXBeep(dev, _BEEP_FEATURE_OFF, XkbStickyKeysMask);
  246. }
  247. #ifndef NO_CLEAR_LATCHES_FOR_STICKY_KEYS_OFF
  248. XkbClearAllLatchesAndLocks(dev, xkbi, FALSE, &cause);
  249. #endif
  250. return;
  251. } /* AccessXStickyKeysTurnOff */
  252. static CARD32
  253. AccessXKRGExpire(OsTimerPtr timer, CARD32 now, void *arg)
  254. {
  255. xkbControlsNotify cn;
  256. DeviceIntPtr dev = arg;
  257. XkbSrvInfoPtr xkbi = dev->key->xkbInfo;
  258. if (xkbi->krgTimerActive == _KRG_WARN_TIMER) {
  259. XkbDDXAccessXBeep(dev, _BEEP_SLOW_WARN, XkbStickyKeysMask);
  260. xkbi->krgTimerActive = _KRG_TIMER;
  261. return 4000;
  262. }
  263. xkbi->krgTimerActive = _OFF_TIMER;
  264. cn.keycode = xkbi->slowKeyEnableKey;
  265. cn.eventType = KeyPress;
  266. cn.requestMajor = 0;
  267. cn.requestMinor = 0;
  268. if (xkbi->desc->ctrls->enabled_ctrls & XkbSlowKeysMask) {
  269. AccessXKRGTurnOff(dev, &cn);
  270. LogMessage(X_INFO, "XKB SlowKeys are disabled.\n");
  271. }
  272. else {
  273. AccessXKRGTurnOn(dev, XkbSlowKeysMask, &cn);
  274. LogMessage(X_INFO, "XKB SlowKeys are now enabled. Hold shift to disable.\n");
  275. }
  276. xkbi->slowKeyEnableKey = 0;
  277. return 0;
  278. }
  279. static CARD32
  280. AccessXRepeatKeyExpire(OsTimerPtr timer, CARD32 now, void *arg)
  281. {
  282. DeviceIntPtr dev = (DeviceIntPtr) arg;
  283. XkbSrvInfoPtr xkbi = dev->key->xkbInfo;
  284. if (xkbi->repeatKey == 0)
  285. return 0;
  286. AccessXKeyboardEvent(dev, ET_KeyPress, xkbi->repeatKey, TRUE);
  287. return xkbi->desc->ctrls->repeat_interval;
  288. }
  289. void
  290. AccessXCancelRepeatKey(XkbSrvInfoPtr xkbi, KeyCode key)
  291. {
  292. if (xkbi->repeatKey == key)
  293. xkbi->repeatKey = 0;
  294. return;
  295. }
  296. static CARD32
  297. AccessXSlowKeyExpire(OsTimerPtr timer, CARD32 now, void *arg)
  298. {
  299. DeviceIntPtr keybd;
  300. XkbSrvInfoPtr xkbi;
  301. XkbDescPtr xkb;
  302. XkbControlsPtr ctrls;
  303. keybd = (DeviceIntPtr) arg;
  304. xkbi = keybd->key->xkbInfo;
  305. xkb = xkbi->desc;
  306. ctrls = xkb->ctrls;
  307. if (xkbi->slowKey != 0) {
  308. xkbAccessXNotify ev;
  309. KeySym *sym = XkbKeySymsPtr(xkb, xkbi->slowKey);
  310. ev.detail = XkbAXN_SKAccept;
  311. ev.keycode = xkbi->slowKey;
  312. ev.slowKeysDelay = ctrls->slow_keys_delay;
  313. ev.debounceDelay = ctrls->debounce_delay;
  314. XkbSendAccessXNotify(keybd, &ev);
  315. if (XkbAX_NeedFeedback(ctrls, XkbAX_SKAcceptFBMask))
  316. XkbDDXAccessXBeep(keybd, _BEEP_SLOW_ACCEPT, XkbSlowKeysMask);
  317. AccessXKeyboardEvent(keybd, ET_KeyPress, xkbi->slowKey, FALSE);
  318. /* check for magic sequences */
  319. if ((ctrls->enabled_ctrls & XkbAccessXKeysMask) &&
  320. ((sym[0] == XK_Shift_R) || (sym[0] == XK_Shift_L)))
  321. xkbi->shiftKeyCount++;
  322. /* Start repeating if necessary. Stop autorepeating if the user
  323. * presses a non-modifier key that doesn't autorepeat.
  324. */
  325. if (keybd->kbdfeed->ctrl.autoRepeat &&
  326. ((xkbi->slowKey != xkbi->mouseKey) || (!xkbi->mouseKeysAccel)) &&
  327. (ctrls->enabled_ctrls & XkbRepeatKeysMask)) {
  328. if (BitIsOn(keybd->kbdfeed->ctrl.autoRepeats, xkbi->slowKey)) {
  329. xkbi->repeatKey = xkbi->slowKey;
  330. xkbi->repeatKeyTimer = TimerSet(xkbi->repeatKeyTimer,
  331. 0, ctrls->repeat_delay,
  332. AccessXRepeatKeyExpire,
  333. (void *) keybd);
  334. }
  335. }
  336. }
  337. return 0;
  338. }
  339. static CARD32
  340. AccessXBounceKeyExpire(OsTimerPtr timer, CARD32 now, void *arg)
  341. {
  342. XkbSrvInfoPtr xkbi = ((DeviceIntPtr) arg)->key->xkbInfo;
  343. xkbi->inactiveKey = 0;
  344. return 0;
  345. }
  346. static CARD32
  347. AccessXTimeoutExpire(OsTimerPtr timer, CARD32 now, void *arg)
  348. {
  349. DeviceIntPtr dev = (DeviceIntPtr) arg;
  350. XkbSrvInfoPtr xkbi = dev->key->xkbInfo;
  351. XkbControlsPtr ctrls = xkbi->desc->ctrls;
  352. XkbControlsRec old;
  353. xkbControlsNotify cn;
  354. XkbEventCauseRec cause;
  355. XkbSrvLedInfoPtr sli;
  356. if (xkbi->lastPtrEventTime) {
  357. unsigned timeToWait = (ctrls->ax_timeout * 1000);
  358. unsigned timeElapsed = (now - xkbi->lastPtrEventTime);
  359. if (timeToWait > timeElapsed)
  360. return timeToWait - timeElapsed;
  361. }
  362. old = *ctrls;
  363. xkbi->shiftKeyCount = 0;
  364. ctrls->enabled_ctrls &= ~ctrls->axt_ctrls_mask;
  365. ctrls->enabled_ctrls |= (ctrls->axt_ctrls_values & ctrls->axt_ctrls_mask);
  366. if (ctrls->axt_opts_mask) {
  367. ctrls->ax_options &= ~ctrls->axt_opts_mask;
  368. ctrls->ax_options |= (ctrls->axt_opts_values & ctrls->axt_opts_mask);
  369. }
  370. if (XkbComputeControlsNotify(dev, &old, ctrls, &cn, FALSE)) {
  371. cn.keycode = 0;
  372. cn.eventType = 0;
  373. cn.requestMajor = 0;
  374. cn.requestMinor = 0;
  375. XkbSendControlsNotify(dev, &cn);
  376. }
  377. XkbSetCauseUnknown(&cause);
  378. sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId, 0);
  379. XkbUpdateIndicators(dev, sli->usesControls, TRUE, NULL, &cause);
  380. if (ctrls->ax_options != old.ax_options) {
  381. unsigned set, cleared, bell;
  382. set = ctrls->ax_options & (~old.ax_options);
  383. cleared = (~ctrls->ax_options) & old.ax_options;
  384. if (set && cleared)
  385. bell = _BEEP_FEATURE_CHANGE;
  386. else if (set)
  387. bell = _BEEP_FEATURE_ON;
  388. else
  389. bell = _BEEP_FEATURE_OFF;
  390. XkbDDXAccessXBeep(dev, bell, XkbAccessXTimeoutMask);
  391. }
  392. xkbi->krgTimerActive = _OFF_TIMER;
  393. return 0;
  394. }
  395. /************************************************************************/
  396. /* */
  397. /* AccessXFilterPressEvent */
  398. /* */
  399. /* Filter events before they get any further if SlowKeys is turned on. */
  400. /* In addition, this routine handles the ever so popular magic key */
  401. /* acts for turning various accessibility features on/off. */
  402. /* */
  403. /* Returns TRUE if this routine has discarded the event. */
  404. /* Returns FALSE if the event needs further processing. */
  405. /* */
  406. /************************************************************************/
  407. Bool
  408. AccessXFilterPressEvent(DeviceEvent *event, DeviceIntPtr keybd)
  409. {
  410. XkbSrvInfoPtr xkbi = keybd->key->xkbInfo;
  411. XkbControlsPtr ctrls = xkbi->desc->ctrls;
  412. Bool ignoreKeyEvent = FALSE;
  413. KeyCode key = event->detail.key;
  414. KeySym *sym = XkbKeySymsPtr(xkbi->desc, key);
  415. if (ctrls->enabled_ctrls & XkbAccessXKeysMask) {
  416. /* check for magic sequences */
  417. if ((sym[0] == XK_Shift_R) || (sym[0] == XK_Shift_L)) {
  418. xkbi->slowKeyEnableKey = key;
  419. if (XkbAX_NeedFeedback(ctrls, XkbAX_SlowWarnFBMask)) {
  420. xkbi->krgTimerActive = _KRG_WARN_TIMER;
  421. xkbi->krgTimer = TimerSet(xkbi->krgTimer, 0, 4000,
  422. AccessXKRGExpire, (void *) keybd);
  423. }
  424. else {
  425. xkbi->krgTimerActive = _KRG_TIMER;
  426. xkbi->krgTimer = TimerSet(xkbi->krgTimer, 0, 8000,
  427. AccessXKRGExpire, (void *) keybd);
  428. }
  429. if (!(ctrls->enabled_ctrls & XkbSlowKeysMask)) {
  430. CARD32 now = GetTimeInMillis();
  431. if ((now - xkbi->lastShiftEventTime) > 15000)
  432. xkbi->shiftKeyCount = 1;
  433. else
  434. xkbi->shiftKeyCount++;
  435. xkbi->lastShiftEventTime = now;
  436. }
  437. }
  438. else {
  439. if (xkbi->krgTimerActive) {
  440. xkbi->krgTimer = TimerSet(xkbi->krgTimer, 0, 0, NULL, NULL);
  441. xkbi->krgTimerActive = _OFF_TIMER;
  442. }
  443. }
  444. }
  445. /* Don't transmit the KeyPress if SlowKeys is turned on;
  446. * The wakeup handler will synthesize one for us if the user
  447. * has held the key long enough.
  448. */
  449. if (ctrls->enabled_ctrls & XkbSlowKeysMask) {
  450. xkbAccessXNotify ev;
  451. /* If key was already pressed, ignore subsequent press events
  452. * from the server's autorepeat
  453. */
  454. if (xkbi->slowKey == key)
  455. return TRUE;
  456. ev.detail = XkbAXN_SKPress;
  457. ev.keycode = key;
  458. ev.slowKeysDelay = ctrls->slow_keys_delay;
  459. ev.debounceDelay = ctrls->debounce_delay;
  460. XkbSendAccessXNotify(keybd, &ev);
  461. if (XkbAX_NeedFeedback(ctrls, XkbAX_SKPressFBMask))
  462. XkbDDXAccessXBeep(keybd, _BEEP_SLOW_PRESS, XkbSlowKeysMask);
  463. xkbi->slowKey = key;
  464. xkbi->slowKeysTimer = TimerSet(xkbi->slowKeysTimer,
  465. 0, ctrls->slow_keys_delay,
  466. AccessXSlowKeyExpire, (void *) keybd);
  467. ignoreKeyEvent = TRUE;
  468. }
  469. /* Don't transmit the KeyPress if BounceKeys is turned on
  470. * and the user pressed the same key within a given time period
  471. * from the last release.
  472. */
  473. else if ((ctrls->enabled_ctrls & XkbBounceKeysMask) &&
  474. (key == xkbi->inactiveKey)) {
  475. if (XkbAX_NeedFeedback(ctrls, XkbAX_BKRejectFBMask))
  476. XkbDDXAccessXBeep(keybd, _BEEP_BOUNCE_REJECT, XkbBounceKeysMask);
  477. ignoreKeyEvent = TRUE;
  478. }
  479. /* Start repeating if necessary. Stop autorepeating if the user
  480. * presses a non-modifier key that doesn't autorepeat.
  481. */
  482. if (XkbDDXUsesSoftRepeat(keybd)) {
  483. if ((keybd->kbdfeed->ctrl.autoRepeat) &&
  484. ((ctrls->enabled_ctrls & (XkbSlowKeysMask | XkbRepeatKeysMask)) ==
  485. XkbRepeatKeysMask)) {
  486. if (BitIsOn(keybd->kbdfeed->ctrl.autoRepeats, key)) {
  487. if (xkbDebugFlags & 0x10)
  488. DebugF("Starting software autorepeat...\n");
  489. if (xkbi->repeatKey == key)
  490. ignoreKeyEvent = TRUE;
  491. else {
  492. xkbi->repeatKey = key;
  493. xkbi->repeatKeyTimer = TimerSet(xkbi->repeatKeyTimer,
  494. 0, ctrls->repeat_delay,
  495. AccessXRepeatKeyExpire,
  496. (void *) keybd);
  497. }
  498. }
  499. }
  500. }
  501. /* Check for two keys being pressed at the same time. This section
  502. * essentially says the following:
  503. *
  504. * If StickyKeys is on, and a modifier is currently being held down,
  505. * and one of the following is true: the current key is not a modifier
  506. * or the currentKey is a modifier, but not the only modifier being
  507. * held down, turn StickyKeys off if the TwoKeys off ctrl is set.
  508. */
  509. if ((ctrls->enabled_ctrls & XkbStickyKeysMask) &&
  510. (xkbi->state.base_mods != 0) &&
  511. (XkbAX_NeedOption(ctrls, XkbAX_TwoKeysMask))) {
  512. xkbControlsNotify cn;
  513. cn.keycode = key;
  514. cn.eventType = KeyPress;
  515. cn.requestMajor = 0;
  516. cn.requestMinor = 0;
  517. AccessXStickyKeysTurnOff(keybd, &cn);
  518. }
  519. if (!ignoreKeyEvent)
  520. XkbProcessKeyboardEvent(event, keybd);
  521. return ignoreKeyEvent;
  522. } /* AccessXFilterPressEvent */
  523. /************************************************************************/
  524. /* */
  525. /* AccessXFilterReleaseEvent */
  526. /* */
  527. /* Filter events before they get any further if SlowKeys is turned on. */
  528. /* In addition, this routine handles the ever so popular magic key */
  529. /* acts for turning various accessibility features on/off. */
  530. /* */
  531. /* Returns TRUE if this routine has discarded the event. */
  532. /* Returns FALSE if the event needs further processing. */
  533. /* */
  534. /************************************************************************/
  535. Bool
  536. AccessXFilterReleaseEvent(DeviceEvent *event, DeviceIntPtr keybd)
  537. {
  538. XkbSrvInfoPtr xkbi = keybd->key->xkbInfo;
  539. XkbControlsPtr ctrls = xkbi->desc->ctrls;
  540. KeyCode key = event->detail.key;
  541. Bool ignoreKeyEvent = FALSE;
  542. /* Don't transmit the KeyRelease if BounceKeys is on and
  543. * this is the release of a key that was ignored due to
  544. * BounceKeys.
  545. */
  546. if (ctrls->enabled_ctrls & XkbBounceKeysMask) {
  547. if ((key != xkbi->mouseKey) && (!BitIsOn(keybd->key->down, key)))
  548. ignoreKeyEvent = TRUE;
  549. xkbi->inactiveKey = key;
  550. xkbi->bounceKeysTimer = TimerSet(xkbi->bounceKeysTimer, 0,
  551. ctrls->debounce_delay,
  552. AccessXBounceKeyExpire,
  553. (void *) keybd);
  554. }
  555. /* Don't transmit the KeyRelease if SlowKeys is turned on and
  556. * the user didn't hold the key long enough. We know we passed
  557. * the key if the down bit was set by CoreProcessKeyboadEvent.
  558. */
  559. if (ctrls->enabled_ctrls & XkbSlowKeysMask) {
  560. xkbAccessXNotify ev;
  561. unsigned beep_type;
  562. ev.keycode = key;
  563. ev.slowKeysDelay = ctrls->slow_keys_delay;
  564. ev.debounceDelay = ctrls->debounce_delay;
  565. if (BitIsOn(keybd->key->down, key) || (xkbi->mouseKey == key)) {
  566. ev.detail = XkbAXN_SKRelease;
  567. beep_type = _BEEP_SLOW_RELEASE;
  568. }
  569. else {
  570. ev.detail = XkbAXN_SKReject;
  571. beep_type = _BEEP_SLOW_REJECT;
  572. ignoreKeyEvent = TRUE;
  573. }
  574. XkbSendAccessXNotify(keybd, &ev);
  575. if (XkbAX_NeedFeedback(ctrls, XkbAX_SKRejectFBMask)) {
  576. XkbDDXAccessXBeep(keybd, beep_type, XkbSlowKeysMask);
  577. }
  578. if (xkbi->slowKey == key)
  579. xkbi->slowKey = 0;
  580. }
  581. /* Stop Repeating if the user releases the key that is currently
  582. * repeating.
  583. */
  584. if (xkbi->repeatKey == key) {
  585. xkbi->repeatKey = 0;
  586. }
  587. if ((ctrls->enabled_ctrls & XkbAccessXTimeoutMask) &&
  588. (ctrls->ax_timeout > 0)) {
  589. xkbi->lastPtrEventTime = 0;
  590. xkbi->krgTimer = TimerSet(xkbi->krgTimer, 0,
  591. ctrls->ax_timeout * 1000,
  592. AccessXTimeoutExpire, (void *) keybd);
  593. xkbi->krgTimerActive = _ALL_TIMEOUT_TIMER;
  594. }
  595. else if (xkbi->krgTimerActive != _OFF_TIMER) {
  596. xkbi->krgTimer = TimerSet(xkbi->krgTimer, 0, 0, NULL, NULL);
  597. xkbi->krgTimerActive = _OFF_TIMER;
  598. }
  599. /* Keep track of how many times the Shift key has been pressed.
  600. * If it has been pressed and released 5 times in a row, toggle
  601. * the state of StickyKeys.
  602. */
  603. if ((!ignoreKeyEvent) && (xkbi->shiftKeyCount)) {
  604. KeySym *pSym = XkbKeySymsPtr(xkbi->desc, key);
  605. if ((pSym[0] != XK_Shift_L) && (pSym[0] != XK_Shift_R)) {
  606. xkbi->shiftKeyCount = 0;
  607. }
  608. else if (xkbi->shiftKeyCount >= 5) {
  609. xkbControlsNotify cn;
  610. cn.keycode = key;
  611. cn.eventType = KeyPress;
  612. cn.requestMajor = 0;
  613. cn.requestMinor = 0;
  614. if (ctrls->enabled_ctrls & XkbStickyKeysMask)
  615. AccessXStickyKeysTurnOff(keybd, &cn);
  616. else
  617. AccessXStickyKeysTurnOn(keybd, &cn);
  618. xkbi->shiftKeyCount = 0;
  619. }
  620. }
  621. if (!ignoreKeyEvent)
  622. XkbProcessKeyboardEvent(event, keybd);
  623. return ignoreKeyEvent;
  624. } /* AccessXFilterReleaseEvent */
  625. /************************************************************************/
  626. /* */
  627. /* ProcessPointerEvent */
  628. /* */
  629. /* This routine merely sets the shiftKeyCount and clears the keyboard */
  630. /* response group timer (if necessary) on a mouse event. This is so */
  631. /* multiple shifts with just the mouse and shift-drags with the mouse */
  632. /* don't accidentally turn on StickyKeys or the Keyboard Response Group.*/
  633. /* */
  634. /************************************************************************/
  635. extern int xkbDevicePrivateIndex;
  636. void
  637. ProcessPointerEvent(InternalEvent *ev, DeviceIntPtr mouse)
  638. {
  639. DeviceIntPtr dev;
  640. XkbSrvInfoPtr xkbi = NULL;
  641. unsigned changed = 0;
  642. ProcessInputProc backupproc;
  643. xkbDeviceInfoPtr xkbPrivPtr = XKBDEVICEINFO(mouse);
  644. DeviceEvent *event = &ev->device_event;
  645. dev = IsFloating(mouse) ? mouse : GetMaster(mouse, MASTER_KEYBOARD);
  646. if (dev && dev->key) {
  647. xkbi = dev->key->xkbInfo;
  648. xkbi->shiftKeyCount = 0;
  649. xkbi->lastPtrEventTime = event->time;
  650. }
  651. if (event->type == ET_ButtonPress) {
  652. changed |= XkbPointerButtonMask;
  653. }
  654. else if (event->type == ET_ButtonRelease) {
  655. if (IsMaster(dev)) {
  656. DeviceIntPtr source;
  657. int rc;
  658. rc = dixLookupDevice(&source, event->sourceid, serverClient,
  659. DixWriteAccess);
  660. if (rc != Success)
  661. ErrorF("[xkb] bad sourceid '%d' on button release event.\n",
  662. event->sourceid);
  663. else if (!IsXTestDevice(source, GetMaster(dev, MASTER_POINTER))) {
  664. DeviceIntPtr xtest_device;
  665. xtest_device = GetXTestDevice(GetMaster(dev, MASTER_POINTER));
  666. if (button_is_down(xtest_device, ev->device_event.detail.button, BUTTON_PROCESSED))
  667. XkbFakeDeviceButton(dev, FALSE, event->detail.key);
  668. }
  669. }
  670. if (xkbi)
  671. xkbi->lockedPtrButtons &= ~(1 << (event->detail.key & 0x7));
  672. changed |= XkbPointerButtonMask;
  673. }
  674. UNWRAP_PROCESS_INPUT_PROC(mouse, xkbPrivPtr, backupproc);
  675. mouse->public.processInputProc(ev, mouse);
  676. COND_WRAP_PROCESS_INPUT_PROC(mouse, xkbPrivPtr, backupproc, xkbUnwrapProc);
  677. if (!xkbi)
  678. return;
  679. xkbi->state.ptr_buttons = (mouse->button) ? mouse->button->state : 0;
  680. /* clear any latched modifiers */
  681. if (xkbi->state.latched_mods && (event->type == ET_ButtonRelease)) {
  682. unsigned changed_leds;
  683. XkbStateRec oldState;
  684. XkbSrvLedInfoPtr sli;
  685. sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId, 0);
  686. oldState = xkbi->state;
  687. XkbLatchModifiers(dev, 0xFF, 0x00);
  688. XkbComputeDerivedState(xkbi);
  689. changed |= XkbStateChangedFlags(&oldState, &xkbi->state);
  690. if (changed & sli->usedComponents) {
  691. changed_leds = XkbIndicatorsToUpdate(dev, changed, FALSE);
  692. if (changed_leds) {
  693. XkbEventCauseRec cause;
  694. XkbSetCauseKey(&cause, (event->detail.key & 0x7), event->type);
  695. XkbUpdateIndicators(dev, changed_leds, TRUE, NULL, &cause);
  696. }
  697. }
  698. }
  699. if (((xkbi->flags & _XkbStateNotifyInProgress) == 0) && (changed != 0)) {
  700. xkbStateNotify sn;
  701. sn.keycode = event->detail.key;
  702. sn.eventType = event->type;
  703. sn.requestMajor = sn.requestMinor = 0;
  704. sn.changed = changed;
  705. XkbSendStateNotify(dev, &sn);
  706. }
  707. } /* ProcessPointerEvent */