--- libcaribou/xadapter.vala	2013-10-18 16:43:17.955918856 +0200
+++ libcaribou/xadapter.vala	2013-10-23 14:53:31.414235351 +0200
@@ -20,6 +20,7 @@
         uchar modifiers;
         uchar group;
         uint[] level_switch_modifiers;
+        GLib.Settings a11y_settings;
 
         public delegate void KeyButtonCallback (uint keybuttoncode, bool pressed);
 
@@ -43,6 +44,9 @@
             this.xkbdesc = Xkb.get_keyboard (this.xdisplay,
                                              Xkb.GBN_AllComponentsMask,
                                              Xkb.UseCoreKbd);
+            Xkb.get_controls (this.xdisplay, Xkb.AllControlsMask, this.xkbdesc);
+            this.a11y_settings = new GLib.Settings ("org.gnome.desktop.a11y.keyboard");
+
             this.xkl_engine = Xkl.Engine.get_instance (this.xdisplay);
             xkl_engine.start_listen (Xkl.EngineListenModes.TRACK_KEYBOARD_STATE);
             xkl_state = this.xkl_engine.get_current_state ();
@@ -87,6 +91,17 @@
             return instance;
         }
 
+	private void trigger_slowkeys (bool enable) {
+           if (this.a11y_settings.get_boolean ("slowkeys-enable") == true) {
+               if (enable == false)
+                 this.xkbdesc.ctrls.enabled_ctrls = this.xkbdesc.ctrls.enabled_ctrls & ~Xkb.SlowKeysMask;
+               else
+                 this.xkbdesc.ctrls.enabled_ctrls = this.xkbdesc.ctrls.enabled_ctrls | Xkb.SlowKeysMask;
+
+               Xkb.set_controls (this.xdisplay, Xkb.ControlsEnabledMask | Xkb.SlowKeysMask, this.xkbdesc);
+           }
+	}
+
         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:
@@ -261,7 +276,9 @@
             if (mask != 0)
                 mod_latch (mask);
 
+            trigger_slowkeys (false);
             XTest.fake_key_event (this.xdisplay, keycode, true, X.CURRENT_TIME);
+            trigger_slowkeys (true);
             this.xdisplay.flush ();
         }
 
--- vapi/external-libs.vapi	2013-10-18 16:42:21.163921179 +0200
+++ vapi/external-libs.vapi	2013-10-23 14:49:37.302227740 +0200
@@ -6,6 +6,15 @@
     [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,15 @@
     [Compact]
     [CCode (cname = "XkbControlsRec", free_function = "")]
     public class Controls {
+        public uint		enabled_ctrls;
+        public uint		axt_ctrls_mask;
+        public uint		axt_ctrls_values;
+        public ushort		axt_opts_mask;
+        public ushort		axt_opts_values;
+        public ushort		ax_timeout;
+        public ushort		slow_keys_delay;
+        public ushort		repeat_delay;
+        public ushort		repeat_interval;
     }
 
     [Compact]
@@ -238,6 +256,8 @@
     public int ExtensionDeviceNotifyMask;
     [CCode (cname = "XkbAllEventsMask")]
     public int AllEventsMask;
+    [CCode (cname = "XkbAllControlsMask")]
+    public int AllControlsMask;
 
     [CCode (cname = "XkbStateNotify")]
     public int StateNotify;
@@ -256,4 +276,10 @@
 
     [CCode (cname = "XkbKeyTypesMask")]
     public int KeyTypesMask;
+
+    [CCode (cname = "XkbSlowKeysMask")]
+    public int SlowKeysMask;
+
+    [CCode (cname = "XkbControlsEnabledMask")]
+    public int ControlsEnabledMask;
 }
