[Xfce4-commits] r27071 - in xfce4-settings/trunk: dialogs/keyboard-settings xfce4-settings-helper

Stephan Arts stephan at xfce.org
Mon Jun 16 00:10:00 CEST 2008


Author: stephan
Date: 2008-06-15 22:10:00 +0000 (Sun, 15 Jun 2008)
New Revision: 27071

Added:
   xfce4-settings/trunk/xfce4-settings-helper/xkb.c
   xfce4-settings/trunk/xfce4-settings-helper/xkb.h
Modified:
   xfce4-settings/trunk/dialogs/keyboard-settings/keyboard-dialog.glade
   xfce4-settings/trunk/dialogs/keyboard-settings/main.c
   xfce4-settings/trunk/xfce4-settings-helper/Makefile.am
   xfce4-settings/trunk/xfce4-settings-helper/accessx.c
   xfce4-settings/trunk/xfce4-settings-helper/main.c
Log:
Add xkb stuff (for repeat-delay and repeat-rate)...  doesn't quite work yet
Improve keyboard-dialog



Modified: xfce4-settings/trunk/dialogs/keyboard-settings/keyboard-dialog.glade
===================================================================
--- xfce4-settings/trunk/dialogs/keyboard-settings/keyboard-dialog.glade	2008-06-15 21:18:48 UTC (rev 27070)
+++ xfce4-settings/trunk/dialogs/keyboard-settings/keyboard-dialog.glade	2008-06-15 22:10:00 UTC (rev 27071)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Sun Jun 15 22:47:58 2008 -->
+<!--Generated with glade3 3.4.5 on Sun Jun 15 23:48:00 2008 -->
 <glade-interface>
   <requires lib="xfce4"/>
   <widget class="GtkDialog" id="keyboard-settings-dialog">

Modified: xfce4-settings/trunk/dialogs/keyboard-settings/main.c
===================================================================
--- xfce4-settings/trunk/dialogs/keyboard-settings/main.c	2008-06-15 21:18:48 UTC (rev 27070)
+++ xfce4-settings/trunk/dialogs/keyboard-settings/main.c	2008-06-15 22:10:00 UTC (rev 27071)
@@ -51,6 +51,14 @@
 };
 
 void
+cb_xkb_key_repeat_toggled (GtkToggleButton *button, gpointer user_data)
+{
+    GladeXML *gxml = GLADE_XML(user_data);
+    GtkWidget *box = glade_xml_get_widget (gxml, "xkb_key_repeat_box");
+    gtk_widget_set_sensitive (box, gtk_toggle_button_get_active (button));
+}
+
+void
 cb_net_cursor_blink_toggled (GtkToggleButton *button, gpointer user_data)
 {
     GladeXML *gxml = GLADE_XML(user_data);
@@ -66,9 +74,28 @@
 
     GtkWidget *net_cursor_blink_check = glade_xml_get_widget (gxml, "net_cursor_blink_check");
     GtkWidget *net_cursor_blink_time_scale = (GtkWidget *)gtk_range_get_adjustment (GTK_RANGE (glade_xml_get_widget (gxml, "net_cursor_blink_time_scale")));
+    GtkWidget *xkb_key_repeat_check = glade_xml_get_widget (gxml, "xkb_key_repeat_check");
+    GtkWidget *xkb_key_repeat_delay_scale = (GtkWidget *)gtk_range_get_adjustment (GTK_RANGE (glade_xml_get_widget (gxml, "xkb_key_repeat_delay_scale")));
+    GtkWidget *xkb_key_repeat_rate_scale = (GtkWidget *)gtk_range_get_adjustment (GTK_RANGE (glade_xml_get_widget (gxml, "xkb_key_repeat_rate_scale")));
 
     g_signal_connect (G_OBJECT(net_cursor_blink_check), "toggled", (GCallback)cb_net_cursor_blink_toggled, gxml);
+    g_signal_connect (G_OBJECT(xkb_key_repeat_check), "toggled", (GCallback)cb_xkb_key_repeat_toggled, gxml);
 
+
+    /* XKB Settings */
+    xfconf_g_property_bind (xkb_channel, 
+                            "/Xkb/KeyRepeat",
+                            G_TYPE_BOOLEAN,
+                            (GObject *)xkb_key_repeat_check, "active");
+    xfconf_g_property_bind (xkb_channel, 
+                            "/Xkb/KeyRepeat/Rate",
+                            G_TYPE_INT,
+                            (GObject *)xkb_key_repeat_rate_scale, "value");
+    xfconf_g_property_bind (xkb_channel, 
+                            "/Xkb/KeyRepeat/Delay",
+                            G_TYPE_INT,
+                            (GObject *)xkb_key_repeat_delay_scale, "value");
+    /* XSETTINGS */
     xfconf_g_property_bind (xsettings_channel, 
                             "/Net/CursorBlink",
                             G_TYPE_BOOLEAN,

Modified: xfce4-settings/trunk/xfce4-settings-helper/Makefile.am
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/Makefile.am	2008-06-15 21:18:48 UTC (rev 27070)
+++ xfce4-settings/trunk/xfce4-settings-helper/Makefile.am	2008-06-15 22:10:00 UTC (rev 27071)
@@ -2,7 +2,8 @@
 
 xfce4_settings_helper_SOURCES = \
 	main.c \
-	accessx.c accessx.h
+	accessx.c accessx.h \
+	xkb.c xkb.h
 
 xfce4_settings_helper_CFLAGS = \
 	$(GTK_CFLAGS) \

Modified: xfce4-settings/trunk/xfce4-settings-helper/accessx.c
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/accessx.c	2008-06-15 21:18:48 UTC (rev 27070)
+++ xfce4-settings/trunk/xfce4-settings-helper/accessx.c	2008-06-15 22:10:00 UTC (rev 27071)
@@ -44,10 +44,11 @@
 #include <xfconf/xfconf.h>
 #include <libnotify/notify.h>
 
+#include "xkb.h"
+
 static NotifyNotification *accessx_notification = NULL;
 
 static XfconfChannel *accessx_channel;
-static gboolean xkbpresent = FALSE;
 
 static gboolean accessx_initialized = FALSE;
 
@@ -241,27 +242,6 @@
     int xkbopcode, xkbevent, xkberror;
     accessx_channel = channel;
 
-#ifdef DEBUG
-    g_message ("Querying Xkb extension");
-#endif
-    if (XkbQueryExtension (GDK_DISPLAY (), &xkbopcode, &xkbevent, &xkberror, &xkbmajor, &xkbminor))
-    {
-#ifdef DEBUG
-        g_message ("Xkb extension found");
-#endif
-        xkbpresent = TRUE;
-    }
-    else
-    {
-#ifdef DEBUG
-        g_message ("Your X server does not support Xkb extension");
-#endif
-        xkbpresent = FALSE;
-    }
-#ifdef DEBUG
-    g_warning ("This build doesn't include support for Xkb extension");
-#endif
-    
     g_signal_connect(G_OBJECT(channel), "property-changed", (GCallback)cb_accessx_channel_property_changed, NULL);
 
     accessx_notification = notify_notification_new(

Modified: xfce4-settings/trunk/xfce4-settings-helper/main.c
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/main.c	2008-06-15 21:18:48 UTC (rev 27070)
+++ xfce4-settings/trunk/xfce4-settings-helper/main.c	2008-06-15 22:10:00 UTC (rev 27071)
@@ -35,7 +35,7 @@
 #include <xfconf/xfconf.h>
 #include <libnotify/notify.h>
 
-
+#include "xkb.h"
 #include "accessx.h"
 
 #define XF_DEBUG(str) \
@@ -69,7 +69,7 @@
     GdkDisplay *gdpy;
     gint n_screens, screen;
     gboolean keep_running = FALSE;
-    XfconfChannel *accessx_channel;
+    XfconfChannel *accessx_channel, *xkb_channel;
 
     xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
 
@@ -96,12 +96,14 @@
         return 1;
     }
 
-    notify_init("xfce-xkbd");
+    notify_init("xfce4-settings-helper");
 
     accessx_channel = xfconf_channel_new("accessx");
+    xkb_channel = xfconf_channel_new("xkb");
 
 
     accessx_notification_init(accessx_channel);
+    xkb_notification_init(accessx_channel);
 
     if(!debug) /* If not in debug mode, fork to background */
     {

Added: xfce4-settings/trunk/xfce4-settings-helper/xkb.c
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/xkb.c	                        (rev 0)
+++ xfce4-settings/trunk/xfce4-settings-helper/xkb.c	2008-06-15 22:10:00 UTC (rev 27071)
@@ -0,0 +1,183 @@
+/*
+ *  Copyright (c) 2008 Stephan Arts <stephan at xfce.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  XKB Extension code taken from the original mcs-keyboard-plugin written
+ *  by Olivier Fourdan.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <X11/Xlib.h>
+
+#include <X11/XKBlib.h>
+
+#ifdef HAVE_XF86MISC
+#include <X11/extensions/xf86misc.h>
+#endif
+
+#define HAVE_XKB
+
+#include <glib.h>
+
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+
+#include <libxfce4util/libxfce4util.h>
+#include <xfconf/xfconf.h>
+#include <libnotify/notify.h>
+
+#include "xkb.h"
+
+static XfconfChannel *xkb_channel;
+
+static gboolean xkb_initialized = FALSE;
+
+static void
+set_repeat (int key, int auto_repeat_mode)
+{
+    XKeyboardControl values;
+    values.auto_repeat_mode = auto_repeat_mode;
+
+    gdk_flush ();
+    gdk_error_trap_push ();
+    if (key != -1)
+    {
+        values.key = key;
+        XChangeKeyboardControl (GDK_DISPLAY (), KBKey | KBAutoRepeatMode, &values);
+    }
+    else
+    {
+        XChangeKeyboardControl (GDK_DISPLAY (), KBAutoRepeatMode, &values);
+    }
+    gdk_flush ();
+    gdk_error_trap_pop ();
+}
+
+static void
+set_repeat_rate (int delay, int rate)
+{
+#ifdef HAVE_XF86MISC
+    XF86MiscKbdSettings values;
+#endif
+
+    g_return_if_fail (rate > 0);
+    g_return_if_fail (delay > 0);
+
+#ifdef HAVE_XF86MISC
+    if (miscpresent)
+    {
+        gdk_flush ();
+        gdk_error_trap_push ();
+        XF86MiscGetKbdSettings (GDK_DISPLAY (), &values);
+        if (delay != -1)
+            values.delay = delay;
+        if (rate != -1)
+            values.rate = rate;
+        XF86MiscSetKbdSettings (GDK_DISPLAY (), &values);
+        gdk_flush ();
+        gdk_error_trap_pop ();
+    }
+#endif
+
+#ifdef HAVE_XKB
+    if (xkbpresent)
+    {
+        XkbDescPtr xkb = XkbAllocKeyboard ();
+        if (xkb)
+        {
+            gdk_error_trap_push ();
+            XkbGetControls (GDK_DISPLAY (), XkbRepeatKeysMask, xkb);
+            if (delay != -1)
+                xkb->ctrls->repeat_delay = delay;
+            if (rate != -1)
+                xkb->ctrls->repeat_interval = 1000 / rate;
+            XkbSetControls (GDK_DISPLAY (), XkbRepeatKeysMask, xkb);
+            XFree (xkb);
+            gdk_flush ();
+            gdk_error_trap_pop ();
+        }
+        else
+        {
+            g_warning ("XkbAllocKeyboard() returned null pointer");
+        }
+    }
+#endif
+}
+
+
+
+static void
+cb_xkb_channel_property_changed(XfconfChannel *channel, const gchar *name, const GValue *value, gpointer user_data)
+{
+    if (!strcmp (name, "/Xkb/KeyRepeat"))
+    {
+        gboolean key_repeat = g_value_get_boolean (value);
+        set_repeat (-1, key_repeat == TRUE?1:0);
+    }
+
+    /* TODO */
+    if (!strcmp (name, "/Xkb/KeyRepeat/Delay"))
+    {
+        set_repeat_rate (g_value_get_int (value), -1);
+    }
+    if (!strcmp (name, "/Xkb/KeyRepeat/Rate"))
+    {
+        set_repeat_rate (-1, g_value_get_int (value));
+    }
+}
+
+void
+xkb_notification_init (XfconfChannel *channel)
+{
+    g_return_if_fail (xkb_initialized == FALSE);
+
+    int xkbmajor = XkbMajorVersion, xkbminor = XkbMinorVersion;
+    int xkbopcode, xkbevent, xkberror;
+    xkb_channel = channel;
+
+#ifdef DEBUG
+    g_message ("Querying Xkb extension");
+#endif
+    if (XkbQueryExtension (GDK_DISPLAY (), &xkbopcode, &xkbevent, &xkberror, &xkbmajor, &xkbminor))
+    {
+#ifdef DEBUG
+        g_message ("Xkb extension found");
+#endif
+        xkbpresent = TRUE;
+    }
+    else
+    {
+#ifdef DEBUG
+        g_message ("Your X server does not support Xkb extension");
+#endif
+        xkbpresent = FALSE;
+    }
+#ifdef DEBUG
+    g_warning ("This build doesn't include support for Xkb extension");
+#endif
+    
+    g_signal_connect(G_OBJECT(channel), "property-changed", (GCallback)cb_xkb_channel_property_changed, NULL);
+
+    xkb_initialized = TRUE;
+}
+

Added: xfce4-settings/trunk/xfce4-settings-helper/xkb.h
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/xkb.h	                        (rev 0)
+++ xfce4-settings/trunk/xfce4-settings-helper/xkb.h	2008-06-15 22:10:00 UTC (rev 27071)
@@ -0,0 +1,25 @@
+/*
+ *  Copyright (c) 2008 Stephan Arts <stephan at xfce.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  XKB Extension code taken from the original mcs-keyboard-plugin written
+ *  by Olivier Fourdan.
+ */
+
+static gboolean xkbpresent = FALSE;
+
+void
+xkb_notification_init (XfconfChannel *channel);



More information about the Xfce4-commits mailing list