- Apply a11y settings to newly plugged keyboards as well (#647022)

This commit is contained in:
Bastien Nocera 2010-10-27 15:03:02 +01:00
parent 266787ca71
commit d9be2ebe25
2 changed files with 148 additions and 1 deletions

View File

@ -0,0 +1,139 @@
From 5972dd9c1628de941215bd3a3a31fbcfa098089f Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Thu, 17 Jun 2010 15:58:27 +0100
Subject: [PATCH] Apply keyboard a11y settings for new keyboards
1. Enable mouse-keys, check they work
2. Unplug keyboard
3. Replug keyboard
4. Mouse keys don't work any more.
This patch fixes the above.
https://bugzilla.gnome.org/show_bug.cgi?id=621899
---
plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c | 80 +++++++++++++++++++++
1 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c b/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c
index ba19b42..f355b24 100644
--- a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c
+++ b/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c
@@ -41,6 +41,11 @@
#include <X11/XKBlib.h>
#include <X11/extensions/XKBstr.h>
+#ifdef HAVE_X11_EXTENSIONS_XINPUT_H
+#include <X11/extensions/XInput.h>
+#include <X11/extensions/XIproto.h>
+#endif
+
#ifdef HAVE_LIBNOTIFY
#include <libnotify/notify.h>
#endif /* HAVE_LIBNOTIFY */
@@ -76,6 +81,8 @@ static void gsd_a11y_keyboard_manager_class_init (GsdA11yKeyboardManagerCla
static void gsd_a11y_keyboard_manager_init (GsdA11yKeyboardManager *a11y_keyboard_manager);
static void gsd_a11y_keyboard_manager_finalize (GObject *object);
static void gsd_a11y_keyboard_manager_ensure_status_icon (GsdA11yKeyboardManager *manager);
+static void set_server_from_gconf (GsdA11yKeyboardManager *manager,
+ GConfClient *client);
G_DEFINE_TYPE (GsdA11yKeyboardManager, gsd_a11y_keyboard_manager, G_TYPE_OBJECT)
@@ -88,6 +95,71 @@ static gpointer manager_object = NULL;
#define d(str) do { } while (0)
#endif
+#ifdef HAVE_X11_EXTENSIONS_XINPUT_H
+static GdkFilterReturn
+devicepresence_filter (GdkXEvent *xevent,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xev = (XEvent *) xevent;
+ XEventClass class_presence;
+ int xi_presence;
+
+ DevicePresence (gdk_x11_get_default_xdisplay (), xi_presence, class_presence);
+
+ if (xev->type == xi_presence)
+ {
+ XDevicePresenceNotifyEvent *dpn = (XDevicePresenceNotifyEvent *) xev;
+ if (dpn->devchange == DeviceEnabled) {
+ GConfClient *client;
+ client = gconf_client_get_default ();
+ set_server_from_gconf (data, client);
+ g_object_unref (client);
+ }
+ }
+ return GDK_FILTER_CONTINUE;
+}
+
+static gboolean
+supports_xinput_devices (void)
+{
+ gint op_code, event, error;
+
+ return XQueryExtension (GDK_DISPLAY (),
+ "XInputExtension",
+ &op_code,
+ &event,
+ &error);
+}
+
+static void
+set_devicepresence_handler (GsdA11yKeyboardManager *manager)
+{
+ Display *display;
+ XEventClass class_presence;
+ int xi_presence;
+
+ if (!supports_xinput_devices ())
+ return;
+
+ display = gdk_x11_get_default_xdisplay ();
+
+ gdk_error_trap_push ();
+ DevicePresence (display, xi_presence, class_presence);
+ /* FIXME:
+ * Note that this might overwrite other events, see:
+ * https://bugzilla.gnome.org/show_bug.cgi?id=610245#c2
+ **/
+ XSelectExtensionEvent (display,
+ RootWindow (display, DefaultScreen (display)),
+ &class_presence, 1);
+
+ gdk_flush ();
+ if (!gdk_error_trap_pop ())
+ gdk_window_add_filter (NULL, devicepresence_filter, manager);
+}
+#endif
+
static gboolean
xkb_enabled (GsdA11yKeyboardManager *manager)
{
@@ -996,6 +1068,10 @@ start_a11y_keyboard_idle_cb (GsdA11yKeyboardManager *manager)
(GConfClientNotifyFunc) keyboard_callback,
&manager->priv->gconf_notify);
+#ifdef HAVE_X11_EXTENSIONS_XINPUT_H
+ set_devicepresence_handler (manager);
+#endif
+
/* Save current xkb state so we can restore it on exit
*/
manager->priv->original_xkb_desc = get_xkb_desc_rec (manager);
@@ -1072,6 +1148,10 @@ gsd_a11y_keyboard_manager_stop (GsdA11yKeyboardManager *manager)
g_debug ("Stopping a11y_keyboard manager");
+#ifdef HAVE_X11_EXTENSIONS_XINPUT_H
+ gdk_window_remove_filter (NULL, devicepresence_filter, manager);
+#endif
+
if (p->status_icon)
gtk_status_icon_set_visible (p->status_icon, FALSE);
--
1.7.3.1

View File

@ -1,6 +1,6 @@
Name: gnome-settings-daemon
Version: 2.30.1
Release: 8%{?dist}
Release: 9%{?dist}
Summary: The daemon sharing settings from GNOME to GTK+/KDE applications
Group: System Environment/Daemons
@ -39,6 +39,10 @@ BuildRequires: libcanberra-devel
# https://bugzilla.redhat.com/show_bug.cgi?id=624380
Patch0: 0001-Check-whether-XGetWindowProperty-returns-no-items-an.patch
# https://bugzilla.gnome.org/show_bug.cgi?id=621899
# https://bugzilla.redhat.com/show_bug.cgi?id=647022
Patch1: 0001-Apply-keyboard-a11y-settings-for-new-keyboards.patch
# change font rendering
Patch3: slight-hinting.patch
@ -63,6 +67,7 @@ developing applications that use %{name}.
%prep
%setup -q
%patch0 -p1 -b .copy-crasher
%patch1 -p1 -b .new-kbd
%patch3 -p1 -b .slight-hinting
%patch4 -p1 -b .keyboard-icon
@ -133,6 +138,9 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor >&/dev/null || :
%{_libdir}/pkgconfig/gnome-settings-daemon.pc
%changelog
* Wed Oct 27 2010 Bastien Nocera <bnocera@redhat.com> 2.30.1-9
- Apply a11y settings to newly plugged keyboards as well (#647022)
* Thu Sep 23 2010 Bastien Nocera <bnocera@redhat.com> 2.30.1-8
- Don't crash if we don't recognise the copy/paste buffer content (#624380)