[Xfce4-commits] <xfce4-settings:master> Restore XKB settings whenever a new keyboard is inserted.

Igor Slepchin noreply at xfce.org
Wed Aug 22 23:14:02 CEST 2012


Updating branch refs/heads/master
         to 8d24e58307a784fad26b3d1fa197dfeb641f15de (commit)
       from 3eb6c191e1a92e57fa0edde785b0f0b8088b40c5 (commit)

commit 8d24e58307a784fad26b3d1fa197dfeb641f15de
Author: Igor Slepchin <igor.slepchin at gmail.com>
Date:   Wed Jul 18 04:11:04 2012 -0400

    Restore XKB settings whenever a new keyboard is inserted.
    
    X will reset XKB settings to system defaults whenever
    a new keyboard is detected, thus losing all the keyboard layout
    settings controled by XFCE unless care is taken to restore them.
    
    This fixes bugs 5637, 7833, 7995, 8736; probably most other bugs about
    losing xkb configuration as well (i.e., 5600, 5636, 6109, 6642, 6657,
    7931, 8019, 8136, 8341, 8435).
    
    This should also take care of bug 6370 as the new code takes care
    not to overwrite any options it does not explicitly control.

 xfsettingsd/keyboard-layout.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/xfsettingsd/keyboard-layout.c b/xfsettingsd/keyboard-layout.c
index 6c83ca4..d6d5083 100644
--- a/xfsettingsd/keyboard-layout.c
+++ b/xfsettingsd/keyboard-layout.c
@@ -56,6 +56,11 @@ static void xfce_keyboard_layout_helper_channel_property_changed  (XfconfChannel
 static gchar* xfce_keyboard_layout_get_option                     (gchar                        **options,
                                                                    gchar                         *option_name,
                                                                    gchar                        **other_options);
+static GdkFilterReturn handle_xevent                              (GdkXEvent                     *xev,
+                                                                   GdkEvent                      *event,
+                                                                   XfceKeyboardLayoutHelper      *helper);
+static void xfce_keyboard_layout_reset_xkl_config                 (XklEngine                     *xklengine,
+                                                                   XfceKeyboardLayoutHelper      *helper);
 
 struct _XfceKeyboardLayoutHelperClass
 {
@@ -103,6 +108,11 @@ xfce_keyboard_layout_helper_init (XfceKeyboardLayoutHelper *helper)
     helper->engine = xkl_engine_get_instance (GDK_DISPLAY ());
     helper->config = xkl_config_rec_new ();
     xkl_config_rec_get_from_server (helper->config, helper->engine);
+
+    gdk_window_add_filter (NULL, (GdkFilterFunc) handle_xevent, helper);
+    g_signal_connect (helper->engine, "X-new-device",
+                      G_CALLBACK (xfce_keyboard_layout_reset_xkl_config), helper);
+    xkl_engine_start_listen (helper->engine, XKLL_TRACK_KEYBOARD_STATE);
 #endif /* HAVE_LIBXKLAVIER */
 
     /* load settings */
@@ -333,3 +343,32 @@ xfce_keyboard_layout_helper_channel_property_changed (XfconfChannel      *channe
 
     xfce_keyboard_layout_helper_process_xmodmap ();
 }
+
+static GdkFilterReturn
+handle_xevent (GdkXEvent * xev, GdkEvent * event, XfceKeyboardLayoutHelper *helper)
+{
+#ifdef HAVE_LIBXKLAVIER
+    XEvent *xevent = (XEvent *) xev;
+    xkl_engine_filter_events (helper->engine, xevent);
+#endif /* HAVE_LIBXKLAVIER */
+
+    return GDK_FILTER_CONTINUE;
+}
+
+static void
+xfce_keyboard_layout_reset_xkl_config (XklEngine *xklengine,
+                                       XfceKeyboardLayoutHelper *helper)
+{
+    if (!helper->xkb_disable_settings)
+    {
+        xfsettings_dbg (XFSD_DEBUG_KEYBOARD_LAYOUT,
+                        "New keyboard detected; restoring XKB settings.");
+
+        xfce_keyboard_layout_helper_set_model (helper);
+        xfce_keyboard_layout_helper_set_layout (helper);
+        xfce_keyboard_layout_helper_set_variant (helper);
+        xfce_keyboard_layout_helper_set_grpkey (helper);
+
+        xfce_keyboard_layout_helper_process_xmodmap ();
+    }
+}


More information about the Xfce4-commits mailing list