[caribou] xadapter: disable slowkeys when sending key event



commit 6c75e0213f9eecd1c0657f57ac606e63e0703379
Author: Manuel BACHMANN <manuel bachmann eurogiciel fr>
Date:   Fri Nov 1 11:45:20 2013 +0900

    xadapter: disable slowkeys when sending key event
    
    https://bugzilla.gnome.org/show_bug.cgi?id=698746

 libcaribou/xadapter.vala |   20 ++++++++++++++++++++
 vapi/external-libs.vapi  |   18 ++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/libcaribou/xadapter.vala b/libcaribou/xadapter.vala
index 92fba5e..e786c66 100644
--- a/libcaribou/xadapter.vala
+++ b/libcaribou/xadapter.vala
@@ -72,6 +72,24 @@ namespace Caribou {
             Xkb.free_keyboard(this.xkbdesc, Xkb.GBN_AllComponentsMask, true);
         }
 
+        private bool set_slowkeys_enabled (bool enable) {
+            Xkb.get_controls (this.xdisplay, Xkb.AllControlsMask, this.xkbdesc);
+
+            var previous =
+                (this.xkbdesc.ctrls.enabled_ctrls & Xkb.SlowKeysMask) != 0;
+
+            if (enable)
+                this.xkbdesc.ctrls.enabled_ctrls |= Xkb.SlowKeysMask;
+            else
+                this.xkbdesc.ctrls.enabled_ctrls &= ~Xkb.SlowKeysMask;
+
+            Xkb.set_controls (this.xdisplay,
+                              Xkb.SlowKeysMask | Xkb.ControlsEnabledMask,
+                              this.xkbdesc);
+
+            return previous;
+        }
+
         private Gdk.FilterReturn x_event_filter (Gdk.XEvent xevent, Gdk.Event event) {
             // After the following commit, Vala changed the definition
             // of Gdk.XEvent from struct to class:
@@ -246,8 +264,10 @@ namespace Caribou {
             if (mask != 0)
                 mod_latch (mask);
 
+            var enabled = set_slowkeys_enabled (false);
             XTest.fake_key_event (this.xdisplay, keycode, true, X.CURRENT_TIME);
             this.xdisplay.flush ();
+            set_slowkeys_enabled (enabled);
         }
 
         public override void keyval_release (uint keyval) {
diff --git a/vapi/external-libs.vapi b/vapi/external-libs.vapi
index 1489216..af3bf52 100644
--- a/vapi/external-libs.vapi
+++ b/vapi/external-libs.vapi
@@ -6,6 +6,15 @@ namespace Xkb {
     [CCode (cname = "XkbGetKeyboard")]
     public Desc get_keyboard (X.Display dpy, uint which, uint device_spec);
 
+    [CCode (cname = "XkbGetControls")]
+    public X.Status get_controls (X.Display dpy, uint which, Desc xkb);
+
+    [CCode (cname = "XkbSetControls")]
+    public void set_controls (X.Display dpy, uint which, Desc xkb);
+
+    [CCode (cname = "XkbGetMap")]
+    public Desc get_map (X.Display dpy, uint which, uint device_spec);
+
     [CCode (cname = "XkbSetMap")]
     public void set_map (X.Display dpy, uint which, Desc xkb);
 
@@ -92,6 +101,7 @@ namespace Xkb {
     [Compact]
     [CCode (cname = "XkbControlsRec", free_function = "")]
     public class Controls {
+        public uint            enabled_ctrls;
     }
 
     [Compact]
@@ -238,6 +248,8 @@ namespace Xkb {
     public int ExtensionDeviceNotifyMask;
     [CCode (cname = "XkbAllEventsMask")]
     public int AllEventsMask;
+    [CCode (cname = "XkbAllControlsMask")]
+    public int AllControlsMask;
 
     [CCode (cname = "XkbStateNotify")]
     public int StateNotify;
@@ -256,4 +268,10 @@ namespace Xkb {
 
     [CCode (cname = "XkbKeyTypesMask")]
     public int KeyTypesMask;
+
+    [CCode (cname = "XkbSlowKeysMask")]
+    public int SlowKeysMask;
+
+    [CCode (cname = "XkbControlsEnabledMask")]
+    public int ControlsEnabledMask;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]