[PATCH] xkb: fill in keycode and event type for slow keys enablement

Peter Hutterer peter.hutterer at who-t.net
Sun Jun 24 19:16:00 PDT 2012


eventType is set for the type that triggered a XkbControlsNotify event.
Technically, SlowKeys is triggered by a timer which doesn't have a matching
core event type. So we used to use 0 here.

Practically, the timer is triggered by a key press + hold and cancelled when
the key is released before the timeout expires. So we might as well set
KeyPress (keycode) in the ControlsNotify to give clients a chance to differ
between timer-triggered SlowKeys and client-triggered ones.

This is a chance in behaviour, though I suspect with little impact.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
The current behaviour has been there for years and such a change has a
potential for breaking things. I doubt that there's more than a handful of
clients out there that care about slow keys masks and I don't think it'll
affect those either, especially since now we're providing information that
we didn't in the past.

 xkb/xkbAccessX.c |   24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index fe28e12..4d91762 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -278,10 +278,16 @@ AccessXStickyKeysTurnOff(DeviceIntPtr dev, xkbControlsNotify * pCN)
     return;
 }                               /* AccessXStickyKeysTurnOff */
 
+struct slow_keys_enable_t {
+    DeviceIntPtr keybd;
+    KeyCode key;
+};
+
 static CARD32
 AccessXKRGExpire(OsTimerPtr timer, CARD32 now, pointer arg)
 {
-    XkbSrvInfoPtr xkbi = ((DeviceIntPtr) arg)->key->xkbInfo;
+    struct slow_keys_enable_t *ske = arg;
+    XkbSrvInfoPtr xkbi = ske->keybd->key->xkbInfo;
     xkbControlsNotify cn;
 
     if (xkbi->krgTimerActive == _KRG_WARN_TIMER) {
@@ -291,19 +297,20 @@ AccessXKRGExpire(OsTimerPtr timer, CARD32 now, pointer arg)
         return 4000;
     }
     xkbi->krgTimerActive = _OFF_TIMER;
-    cn.keycode = 0;
-    cn.eventType = 0;
+    cn.keycode = ske->key;
+    cn.eventType = KeyPress;
     cn.requestMajor = 0;
     cn.requestMinor = 0;
     if (xkbi->desc->ctrls->enabled_ctrls & XkbSlowKeysMask) {
-        AccessXKRGTurnOff((DeviceIntPtr) arg, &cn);
+        AccessXKRGTurnOff(ske->keybd, &cn);
         LogMessage(X_INFO, "XKB SlowKeys are disabled.\n");
     }
     else {
-        AccessXKRGTurnOn((DeviceIntPtr) arg, XkbSlowKeysMask, &cn);
+        AccessXKRGTurnOn(ske->keybd, XkbSlowKeysMask, &cn);
         LogMessage(X_INFO, "XKB SlowKeys are now enabled. Hold shift to disable.\n");
     }
 
+    free(ske);
     return 0;
 }
 
@@ -462,15 +469,18 @@ AccessXFilterPressEvent(DeviceEvent *event, DeviceIntPtr keybd)
     if (ctrls->enabled_ctrls & XkbAccessXKeysMask) {
         /* check for magic sequences */
         if ((sym[0] == XK_Shift_R) || (sym[0] == XK_Shift_L)) {
+            struct slow_keys_enable_t *ske = malloc(sizeof(*ske));
+            ske->keybd = keybd;
+            ske->key = key;
             if (XkbAX_NeedFeedback(ctrls, XkbAX_SlowWarnFBMask)) {
                 xkbi->krgTimerActive = _KRG_WARN_TIMER;
                 xkbi->krgTimer = TimerSet(xkbi->krgTimer, 0, 4000,
-                                          AccessXKRGExpire, (pointer) keybd);
+                                          AccessXKRGExpire, ske);
             }
             else {
                 xkbi->krgTimerActive = _KRG_TIMER;
                 xkbi->krgTimer = TimerSet(xkbi->krgTimer, 0, 8000,
-                                          AccessXKRGExpire, (pointer) keybd);
+                                          AccessXKRGExpire, ske);
             }
             if (!(ctrls->enabled_ctrls & XkbSlowKeysMask)) {
                 CARD32 now = GetTimeInMillis();
-- 
1.7.10.2



More information about the xorg-devel mailing list