[Xfce4-commits] r27055 - xfconf/trunk/xfsettingsd
Stephan Arts
stephan at xfce.org
Sat Jun 14 14:55:33 CEST 2008
Author: stephan
Date: 2008-06-14 12:55:33 +0000 (Sat, 14 Jun 2008)
New Revision: 27055
Added:
xfconf/trunk/xfsettingsd/accessx.c
xfconf/trunk/xfsettingsd/accessx.h
Modified:
xfconf/trunk/xfsettingsd/Makefile.am
xfconf/trunk/xfsettingsd/main.c
xfconf/trunk/xfsettingsd/registry.c
Log:
Add xkb-accessx support to xfsettingsd (TODO: make libnotify dependency
optional)
Modified: xfconf/trunk/xfsettingsd/Makefile.am
===================================================================
--- xfconf/trunk/xfsettingsd/Makefile.am 2008-06-14 07:20:10 UTC (rev 27054)
+++ xfconf/trunk/xfsettingsd/Makefile.am 2008-06-14 12:55:33 UTC (rev 27055)
@@ -4,12 +4,14 @@
xfsettingsd_SOURCES = \
main.c \
- registry.c registry.h
+ registry.c registry.h \
+ accessx.c accessx.h
xfsettingsd_CFLAGS = \
$(GTK_CFLAGS) \
$(GLIB_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
+ $(LIBNOTIFY_CFLAGS) \
$(LIBXFCE4UTIL_CFLAGS) \
-DDATADIR=\"$(datadir)\" \
-DSRCDIR=\"$(top_srcdir)\" \
@@ -20,6 +22,7 @@
$(GTK_LIBS) \
$(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) \
+ $(LIBNOTIFY_LIBS) \
$(LIBXFCE4UTIL_LIBS)
INCLUDES = \
Added: xfconf/trunk/xfsettingsd/accessx.c
===================================================================
--- xfconf/trunk/xfsettingsd/accessx.c (rev 0)
+++ xfconf/trunk/xfsettingsd/accessx.c 2008-06-14 12:55:33 UTC (rev 27055)
@@ -0,0 +1,274 @@
+/*
+ * 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>
+
+#ifdef HAVE_XKB
+#include <X11/XKBlib.h>
+#endif
+
+#ifdef HAVE_XF86MISC
+#include <X11/extensions/xf86misc.h>
+#endif
+
+#include <glib.h>
+
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+
+#include <libxfce4util/libxfce4util.h>
+#include <xfconf/xfconf.h>
+#include <libnotify/notify.h>
+
+static NotifyNotification *accessx_notification = NULL;
+
+static XfconfChannel *accessx_channel;
+static gboolean xkbpresent = FALSE;
+
+static gboolean accessx_initialized = FALSE;
+
+static void
+toggle_accessx (XfconfChannel *channel);
+
+GdkFilterReturn
+accessx_event_filter (GdkXEvent *xevent,
+ GdkEvent *g_event,
+ gpointer data)
+{
+ XkbEvent *event = xevent;
+
+ switch(event->any.xkb_type)
+ {
+ case XkbBellNotify:
+ break;
+ case XkbControlsNotify:
+ {
+ if(event->ctrls.enabled_ctrl_changes & XkbStickyKeysMask)
+ {
+ if(event->ctrls.enabled_ctrls & XkbStickyKeysMask)
+ {
+ notify_notification_update(accessx_notification,
+ _("Sticky keys"),
+ _("Sticky keys are enabled"),
+ "keyboard");
+ }
+ else
+ {
+ notify_notification_update(accessx_notification,
+ _("Sticky keys"),
+ _("Sticky keys are disabled"),
+ "keyboard");
+ }
+
+ notify_notification_show(accessx_notification, NULL);
+ }
+
+ if(event->ctrls.enabled_ctrl_changes & XkbSlowKeysMask)
+ {
+ if(event->ctrls.enabled_ctrls & XkbSlowKeysMask)
+ {
+ notify_notification_update(accessx_notification,
+ _("Slow keys"),
+ _("Slow keys are enabled"),
+ "keyboard");
+ }
+ else
+ {
+ notify_notification_update(accessx_notification,
+ _("Slow keys"),
+ _("Slow keys are disabled"),
+ "keyboard");
+ }
+
+ notify_notification_show(accessx_notification, NULL);
+ }
+
+ if(event->ctrls.enabled_ctrl_changes & XkbBounceKeysMask)
+ {
+ if(event->ctrls.enabled_ctrls & XkbBounceKeysMask)
+ {
+ notify_notification_update(accessx_notification,
+ _("Bounce keys"),
+ _("Bounce keys are enabled"),
+ "keyboard");
+ }
+ else
+ {
+ notify_notification_update(accessx_notification,
+ _("Bounce keys"),
+ _("Bounce keys are disabled"),
+ "keyboard");
+ }
+
+ notify_notification_show(accessx_notification, NULL);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return GDK_FILTER_CONTINUE;
+}
+
+static void
+cb_accessx_channel_property_changed(XfconfChannel *channel, const gchar *name, const GValue *value, gpointer user_data)
+{
+ toggle_accessx(channel);
+}
+
+static void
+toggle_accessx (XfconfChannel *channel)
+{
+ gboolean slow_keys = xfconf_channel_get_bool (channel, "/AccessX/SlowKeys", FALSE);
+ gboolean sticky_keys = xfconf_channel_get_bool (channel, "/AccessX/StickyKeys", FALSE);
+ gboolean bounce_keys = xfconf_channel_get_bool (channel, "/AccessX/BounceKeys", FALSE);
+ gint slow_keys_delay = xfconf_channel_get_int (channel, "/AccessX/SlowKeysDelay", 100);
+ gint debounce_delay = xfconf_channel_get_int (channel, "/AccessX/DeBounceDelay", 100);
+ gboolean sticky_keys_ltl = xfconf_channel_get_bool (channel, "/AccessX/StickyKeysLatchToLock", FALSE);
+ gboolean sticky_keys_tk = xfconf_channel_get_bool (channel, "/AccessX/StickyKeysTwoKeysUnlock", FALSE);
+#ifdef HAVE_XKB
+ if (xkbpresent)
+ {
+ XkbDescPtr xkb = XkbAllocKeyboard ();
+ if (xkb)
+ {
+ gdk_error_trap_push ();
+ XkbGetControls (GDK_DISPLAY (), XkbAllControlsMask, xkb);
+
+ /* Slow keys */
+ if(slow_keys)
+ {
+ xkb->ctrls->enabled_ctrls |= XkbSlowKeysMask;
+ xkb->ctrls->slow_keys_delay = slow_keys_delay;
+ }
+ else
+ xkb->ctrls->enabled_ctrls &= ~XkbSlowKeysMask;
+
+ /* Bounce keys */
+ if(bounce_keys)
+ {
+ xkb->ctrls->enabled_ctrls |= XkbBounceKeysMask;
+ xkb->ctrls->debounce_delay = debounce_delay;
+ }
+ else
+ xkb->ctrls->enabled_ctrls &= ~XkbBounceKeysMask;
+
+ /* Sticky keys */
+ if(sticky_keys)
+ xkb->ctrls->enabled_ctrls |= XkbStickyKeysMask;
+ else
+ xkb->ctrls->enabled_ctrls &= ~XkbStickyKeysMask;
+
+ if(sticky_keys_ltl)
+ xkb->ctrls->ax_options |= XkbAX_LatchToLockMask;
+ else
+ xkb->ctrls->ax_options &= ~XkbAX_LatchToLockMask;
+
+ if(sticky_keys_tk)
+ xkb->ctrls->ax_options |= XkbAX_TwoKeysMask;
+ else
+ xkb->ctrls->ax_options &= ~XkbAX_TwoKeysMask;
+
+ /* If any option is set, enable AccessXKeys, otherwise: don't */
+ if(sticky_keys || bounce_keys || slow_keys)
+ xkb->ctrls->enabled_ctrls |= XkbAccessXKeysMask;
+ else
+ xkb->ctrls->enabled_ctrls &= ~XkbAccessXKeysMask;
+
+ XkbSetControls (GDK_DISPLAY (), XkbControlsEnabledMask | XkbStickyKeysMask | XkbBounceKeysMask | XkbSlowKeysMask, xkb);
+ XFree (xkb);
+ gdk_flush ();
+ gdk_error_trap_pop ();
+ }
+ else
+ {
+ g_warning ("XkbAllocKeyboard() returned null pointer");
+ }
+ }
+#endif
+}
+
+void
+accessx_notification_init (XfconfChannel *channel)
+{
+ g_return_if_fail (accessx_initialized == FALSE);
+
+#ifdef HAVE_XF86MISC
+ int major, minor;
+#endif
+#ifdef HAVE_XKB
+ int xkbmajor = XkbMajorVersion, xkbminor = XkbMinorVersion;
+ int xkbopcode, xkbevent, xkberror;
+#endif
+ accessx_channel = channel;
+
+#ifdef HAVE_XKB
+#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;
+ }
+#else
+#ifdef DEBUG
+ g_warning ("This build doesn't include support for Xkb extension");
+#endif
+#endif
+
+ g_signal_connect(G_OBJECT(channel), "property-changed", (GCallback)cb_accessx_channel_property_changed, NULL);
+
+ accessx_notification = notify_notification_new(
+ _("Accessibility Notification"),
+ _("Accessibility settings changed"),
+ "preferences-desktop-accessibility",
+ NULL);
+
+ XkbSelectEvents(gdk_display,
+ XkbUseCoreKbd,
+ XkbControlsNotifyMask,
+ XkbControlsNotifyMask);
+
+ gdk_window_add_filter(NULL, accessx_event_filter, NULL);
+
+ toggle_accessx (channel);
+
+ accessx_initialized = TRUE;
+}
+
Added: xfconf/trunk/xfsettingsd/accessx.h
===================================================================
--- xfconf/trunk/xfsettingsd/accessx.h (rev 0)
+++ xfconf/trunk/xfsettingsd/accessx.h 2008-06-14 12:55:33 UTC (rev 27055)
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+
+void
+accessx_notification_init (XfconfChannel *channel);
Modified: xfconf/trunk/xfsettingsd/main.c
===================================================================
--- xfconf/trunk/xfsettingsd/main.c 2008-06-14 07:20:10 UTC (rev 27054)
+++ xfconf/trunk/xfsettingsd/main.c 2008-06-14 12:55:33 UTC (rev 27055)
@@ -33,7 +33,9 @@
#include <libxfce4util/libxfce4util.h>
#include <xfconf/xfconf.h>
+#include <libnotify/notify.h>
+#include "accessx.h"
#include "registry.h"
#define XF_DEBUG(str) \
@@ -120,7 +122,7 @@
GdkDisplay *gdpy;
gint n_screens, screen;
gboolean keep_running = FALSE;
- XfconfChannel *channel;
+ XfconfChannel *xsettings_channel, *accessx_channel;
xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
@@ -147,7 +149,8 @@
return 1;
}
- channel = xfconf_channel_new("xsettings");
+ xsettings_channel = xfconf_channel_new("xsettings");
+ accessx_channel = xfconf_channel_new("accessx");
gdpy = gdk_display_get_default();
n_screens = gdk_display_get_n_screens(gdpy);
@@ -175,7 +178,7 @@
XF_DEBUG("Initializing...\n");
- registry = xsettings_registry_new(channel,
+ registry = xsettings_registry_new(xsettings_channel,
GDK_DISPLAY_XDISPLAY(gdpy),
screen);
registries = g_list_append(registries, registry);
@@ -195,6 +198,10 @@
return 1;
}
+ notify_init("xfsettingsd");
+
+ accessx_notification_init(accessx_channel);
+
if(!debug) /* If not in debug mode, fork to background */
{
if(!fork())
Modified: xfconf/trunk/xfsettingsd/registry.c
===================================================================
--- xfconf/trunk/xfsettingsd/registry.c 2008-06-14 07:20:10 UTC (rev 27054)
+++ xfconf/trunk/xfsettingsd/registry.c 2008-06-14 12:55:33 UTC (rev 27055)
@@ -101,36 +101,36 @@
} XSettingType;
static XSettingsRegistryEntry properties[] = {
-{ "Net/DoubleClickTime", G_TYPE_INT, },
-{ "Net/DoubleClickDistance", G_TYPE_INT, },
-{ "Net/DndDragThreshold", G_TYPE_INT, },
-{ "Net/CursorBlink", G_TYPE_BOOLEAN, },
-{ "Net/CursorBlinkTime", G_TYPE_INT, },
-{ "Net/ThemeName", G_TYPE_STRING, },
-{ "Net/IconThemeName", G_TYPE_STRING, },
+{ "Net/DoubleClickTime", {G_TYPE_INT, }},
+{ "Net/DoubleClickDistance", {G_TYPE_INT, }},
+{ "Net/DndDragThreshold", {G_TYPE_INT, }},
+{ "Net/CursorBlink", {G_TYPE_BOOLEAN, }},
+{ "Net/CursorBlinkTime", {G_TYPE_INT, }},
+{ "Net/ThemeName", {G_TYPE_STRING, }},
+{ "Net/IconThemeName", {G_TYPE_STRING, }},
-{ "Xft/Antialias", G_TYPE_INT, },
-{ "Xft/Hinting", G_TYPE_INT, },
-{ "Xft/HintStyle", G_TYPE_STRING, },
-{ "Xft/RGBA", G_TYPE_STRING, },
-{ "Xft/DPI", G_TYPE_INT, },
+{ "Xft/Antialias", {G_TYPE_INT, }},
+{ "Xft/Hinting", {G_TYPE_INT, }},
+{ "Xft/HintStyle", {G_TYPE_STRING, }},
+{ "Xft/RGBA", {G_TYPE_STRING, }},
+{ "Xft/DPI", {G_TYPE_INT, }},
-{ "Gtk/CanChangeAccels", G_TYPE_BOOLEAN, },
-{ "Gtk/ColorPalette", G_TYPE_STRING, },
-{ "Gtk/FontName", G_TYPE_STRING, },
-{ "Gtk/IconSizes", G_TYPE_STRING, },
-{ "Gtk/KeyThemeName", G_TYPE_STRING, },
-{ "Gtk/ToolbarStyle", G_TYPE_STRING, },
-{ "Gtk/ToolbarIconSize", G_TYPE_INT, },
-{ "Gtk/IMPreeditStyle", G_TYPE_STRING, },
-{ "Gtk/IMStatusStyle", G_TYPE_STRING, },
-{ "Gtk/MenuImages", G_TYPE_BOOLEAN, },
-{ "Gtk/ButtonImages", G_TYPE_BOOLEAN, },
-{ "Gtk/MenuBarAccel", G_TYPE_STRING, },
-{ "Gtk/CursorThemeName", G_TYPE_STRING, },
-{ "Gtk/CursorThemeSize", G_TYPE_INT, },
+{ "Gtk/CanChangeAccels", {G_TYPE_BOOLEAN, }},
+{ "Gtk/ColorPalette", {G_TYPE_STRING, }},
+{ "Gtk/FontName", {G_TYPE_STRING, }},
+{ "Gtk/IconSizes", {G_TYPE_STRING, }},
+{ "Gtk/KeyThemeName", {G_TYPE_STRING, }},
+{ "Gtk/ToolbarStyle", {G_TYPE_STRING, }},
+{ "Gtk/ToolbarIconSize", {G_TYPE_INT, }},
+{ "Gtk/IMPreeditStyle", {G_TYPE_STRING, }},
+{ "Gtk/IMStatusStyle", {G_TYPE_STRING, }},
+{ "Gtk/MenuImages", {G_TYPE_BOOLEAN, }},
+{ "Gtk/ButtonImages", {G_TYPE_BOOLEAN, }},
+{ "Gtk/MenuBarAccel", {G_TYPE_STRING, }},
+{ "Gtk/CursorThemeName", {G_TYPE_STRING, }},
+{ "Gtk/CursorThemeSize", {G_TYPE_INT, }},
-{ NULL, 0,},
+{ NULL, {0, }},
};
@@ -251,8 +251,6 @@
static void
cb_xsettings_registry_channel_property_changed(XfconfChannel *channel, const gchar *name, const GValue *value, XSettingsRegistry *registry)
{
- gint i;
-
XSettingsRegistryEntry *entry = properties;
for(; entry->name != NULL; ++entry)
@@ -340,7 +338,7 @@
xsettings_registry_notify(XSettingsRegistry *registry)
{
guchar *buffer, *pos;
- gint buf_len, i;
+ gint buf_len;
gint prop_count = 0;
registry->priv->last_change_serial = registry->priv->serial;
@@ -663,7 +661,6 @@
gboolean
xsettings_registry_load(XSettingsRegistry *registry, gboolean debug)
{
- gint i;
XfconfChannel *channel = registry->priv->channel;
XSettingsRegistryEntry *entry = properties;
More information about the Xfce4-commits
mailing list