[Xfce4-commits] <xfce4-settings:master> Improve numlock state saving.

Nick Schermer noreply at xfce.org
Thu Jan 5 20:14:01 CET 2012


Updating branch refs/heads/master
         to fabc8dfa6f286efcd988df401ef740362335bfcb (commit)
       from cdcaee8e5738e8ddf1268751836765157fe1e8df (commit)

commit fabc8dfa6f286efcd988df401ef740362335bfcb
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Jan 5 20:11:08 2012 +0100

    Improve numlock state saving.
    
    - Add a property /Default/RestoreNumlock to enable or disable
      numlock restoring.
    - Don't set a value if it does not exist.
    - Add error traps around the x11 code.

 xfsettingsd/keyboards.c |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/xfsettingsd/keyboards.c b/xfsettingsd/keyboards.c
index 0512513..976e2ba 100644
--- a/xfsettingsd/keyboards.c
+++ b/xfsettingsd/keyboards.c
@@ -73,7 +73,7 @@ struct _XfceKeyboardsHelper
 
 
 
-G_DEFINE_TYPE (XfceKeyboardsHelper, xfce_keyboards_helper, G_TYPE_OBJECT);
+G_DEFINE_TYPE (XfceKeyboardsHelper, xfce_keyboards_helper, G_TYPE_OBJECT)
 
 
 
@@ -227,14 +227,26 @@ xfce_keyboards_helper_restore_numlock_state (XfconfChannel *channel)
     Display      *dpy;
     gboolean      state;
 
-    dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
-    state = xfconf_channel_get_bool (channel, "/Default/Numlock", FALSE);
+    if (xfconf_channel_has_property (channel, "/Default/Numlock")
+        && xfconf_channel_get_bool (channel, "/Default/RestoreNumlock", TRUE))
+    {
+        state = xfconf_channel_get_bool (channel, "/Default/Numlock", FALSE);
 
-    numlock_mask = XkbKeysymToModifiers (dpy, XK_Num_Lock);
+        gdk_error_trap_push ();
 
-    XkbLockModifiers (dpy, XkbUseCoreKbd, numlock_mask, state ? numlock_mask : 0);
+        dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+        numlock_mask = XkbKeysymToModifiers (dpy, XK_Num_Lock);
+        XkbLockModifiers (dpy, XkbUseCoreKbd, numlock_mask, state ? numlock_mask : 0);
 
-    xfsettings_dbg (XFSD_DEBUG_KEYBOARDS, "set numlock %s", state ? "on" : "off");
+        if (gdk_error_trap_pop () != 0)
+            g_critical ("Failed to change numlock modifier");
+
+        xfsettings_dbg (XFSD_DEBUG_KEYBOARDS, "set numlock %s", state ? "on" : "off");
+    }
+    else
+    {
+        xfsettings_dbg (XFSD_DEBUG_KEYBOARDS, "don't set numlock");
+    }
 }
 
 
@@ -246,10 +258,16 @@ xfce_keyboards_helper_save_numlock_state (XfconfChannel *channel)
     Bool     numlock_state;
     Atom     numlock;
 
+    gdk_error_trap_push ();
+
     dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
     numlock = XInternAtom(dpy, "Num Lock", False);
-
     XkbGetNamedIndicator (dpy, numlock, NULL, &numlock_state, NULL, NULL);
 
+    if (gdk_error_trap_pop () != 0)
+        g_critical ("Failed to get numlock state");
+
+    xfsettings_dbg (XFSD_DEBUG_KEYBOARDS, "save numlock %s", numlock_state ? "on" : "off");
+
     xfconf_channel_set_bool (channel, "/Default/Numlock", numlock_state);
 }


More information about the Xfce4-commits mailing list