[gnome-settings-daemon] mouse: Do not disable touchpad buttons



commit b23917f0a279aba4599cdc7a5b34055f3d8975ba
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Apr 8 12:39:48 2015 +0200

    mouse: Do not disable touchpad buttons
    
    Touchpad buttons are disabled also if touchpad is disabled using
    "Device Enabled" property. Unfortunately some touchpads share those
    buttons with trackpoint, which is consequently unusable. Disable
    touchpad using "Synaptics Off" property instead to avoid disabling
    the buttons.
    
    Remove also some redundant calls to enable/disable touchpad and
    make sure syndaemon isn't running if the touchpads are disabled.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747504

 plugins/common/gsd-input-helper.c  |   63 +++++++++++++++++++++++++++++------
 plugins/common/gsd-input-helper.h  |    5 ++-
 plugins/common/test-input-helper.c |   24 -------------
 plugins/mouse/gsd-mouse-manager.c  |   28 +++++-----------
 4 files changed, 65 insertions(+), 55 deletions(-)
---
diff --git a/plugins/common/gsd-input-helper.c b/plugins/common/gsd-input-helper.c
index d3cf40c..7ea4061 100644
--- a/plugins/common/gsd-input-helper.c
+++ b/plugins/common/gsd-input-helper.c
@@ -464,6 +464,29 @@ set_device_enabled (int device_id,
         return TRUE;
 }
 
+gboolean
+set_touchpad_device_enabled (int device_id,
+                             gboolean enabled)
+{
+        Atom prop;
+        guchar value;
+
+        prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Off", False);
+        if (!prop)
+                return FALSE;
+
+        gdk_error_trap_push ();
+
+        value = enabled ? 0 : 1;
+        XIChangeProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+                          device_id, prop, XA_INTEGER, 8, PropModeReplace, &value, 1);
+
+        if (gdk_error_trap_pop ())
+                return FALSE;
+
+        return TRUE;
+}
+
 static const char *
 custom_command_to_string (CustomCommand command)
 {
@@ -555,35 +578,53 @@ run_custom_command (GdkDevice              *device,
 }
 
 GList *
-get_disabled_devices (GdkDeviceManager *manager)
+get_disabled_touchpads (GdkDeviceManager *manager)
 {
+        GdkDisplay *display;
         XDeviceInfo *device_info;
-        gint n_devices;
+        gint n_devices, act_format, rc;
         guint i;
         GList *ret;
+        Atom prop, act_type;
+        unsigned long  nitems, bytes_after;
+        unsigned char *data;
 
         ret = NULL;
 
-        device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &n_devices);
-        if (device_info == NULL)
+        display = gdk_display_get_default ();
+        prop = gdk_x11_get_xatom_by_name ("Synaptics Off");
+
+        gdk_error_trap_push ();
+
+        device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (display), &n_devices);
+        if (device_info == NULL) {
+                gdk_error_trap_pop_ignored ();
+
                 return ret;
+        }
 
         for (i = 0; i < n_devices; i++) {
-                GdkDevice *device;
+                rc = XIGetProperty (GDK_DISPLAY_XDISPLAY (display),
+                                    device_info[i].id, prop, 0, 1, False,
+                                    XA_INTEGER, &act_type, &act_format,
+                                    &nitems, &bytes_after, &data);
 
-                /* Ignore core devices */
-                if (device_info[i].use == IsXKeyboard ||
-                    device_info[i].use == IsXPointer)
+                if (rc != Success || act_type != XA_INTEGER ||
+                    act_format != 8 || nitems < 1)
                         continue;
 
-                /* Check whether the device is actually available */
-                device = gdk_x11_device_manager_lookup (manager, device_info[i].id);
-                if (device != NULL)
+                if (!(data[0])) {
+                        XFree (data);
                         continue;
+                }
+
+                XFree (data);
 
                 ret = g_list_prepend (ret, GINT_TO_POINTER (device_info[i].id));
         }
 
+        gdk_error_trap_pop_ignored ();
+
         XFreeDeviceList (device_info);
 
         return ret;
diff --git a/plugins/common/gsd-input-helper.h b/plugins/common/gsd-input-helper.h
index f7f568e..4df8dc3 100644
--- a/plugins/common/gsd-input-helper.h
+++ b/plugins/common/gsd-input-helper.h
@@ -57,6 +57,9 @@ gboolean  supports_xtest           (void);
 gboolean set_device_enabled       (int device_id,
                                    gboolean enabled);
 
+gboolean  set_touchpad_device_enabled (int device_id,
+                                       gboolean enabled);
+
 gboolean  device_is_touchpad       (XDevice                *xdevice);
 
 gboolean  device_info_is_touchpad    (XDeviceInfo         *device_info);
@@ -77,7 +80,7 @@ gboolean  device_set_property     (XDevice                *xdevice,
 gboolean  run_custom_command      (GdkDevice              *device,
                                    CustomCommand           command);
 
-GList *   get_disabled_devices     (GdkDeviceManager       *manager);
+GList *   get_disabled_touchpads     (GdkDeviceManager       *manager);
 char *    xdevice_get_device_node  (int                     deviceid);
 int       xdevice_get_last_tool_id (int                     deviceid);
 gboolean  xdevice_get_dimensions   (int                     deviceid,
diff --git a/plugins/common/test-input-helper.c b/plugins/common/test-input-helper.c
index e7ac4a0..94b3bea 100644
--- a/plugins/common/test-input-helper.c
+++ b/plugins/common/test-input-helper.c
@@ -28,28 +28,6 @@
 
 #include "gsd-input-helper.h"
 
-static void
-print_disabled_devices (void)
-{
-       GList *devices, *l;
-       GdkDeviceManager *manager;
-
-       manager = gdk_display_get_device_manager (gdk_display_get_default ());
-
-       devices = get_disabled_devices (manager);
-       g_print ("Disabled devices:\t\t\t");
-       if (devices == NULL) {
-               g_print ("no\n");
-               return;
-       }
-
-       for (l = devices; l != NULL; l = l->next) {
-               g_print ("%d ", GPOINTER_TO_INT (l->data));
-       }
-       g_list_free (devices);
-       g_print ("\n");
-}
-
 int main (int argc, char **argv)
 {
        gboolean supports_xinput;
@@ -90,8 +68,6 @@ int main (int argc, char **argv)
                 return 1;
        }
 
-       print_disabled_devices ();
-
         for (i = 0; i < n_devices; i++) {
                 XDevice *device;
 
diff --git a/plugins/mouse/gsd-mouse-manager.c b/plugins/mouse/gsd-mouse-manager.c
index 0a927ff..1e844e0 100644
--- a/plugins/mouse/gsd-mouse-manager.c
+++ b/plugins/mouse/gsd-mouse-manager.c
@@ -107,6 +107,7 @@ static void     set_tap_to_click              (GdkDevice           *device,
                                                gboolean             state,
                                                gboolean             left_handed);
 static void     ensure_touchpad_active        (GsdMouseManager     *manager);
+static gboolean get_touchpad_enabled          (GsdMouseManager     *manager);
 
 
 G_DEFINE_TYPE (GsdMouseManager, gsd_mouse_manager, G_TYPE_OBJECT)
@@ -834,7 +835,7 @@ set_touchpad_disabled (GdkDevice *device)
                 return;
         }
 
-        if (set_device_enabled (id, FALSE) == FALSE)
+        if (set_touchpad_device_enabled (id, FALSE) == FALSE)
                 g_warning ("Error disabling device \"%s\" (%d)", gdk_device_get_name (device), id);
         else
                 g_debug ("Disabled device \"%s\" (%d)", gdk_device_get_name (device), id);
@@ -862,7 +863,7 @@ set_touchpad_enabled (int id)
                 return;
         }
 
-        if (set_device_enabled (id, TRUE) == FALSE)
+        if (set_touchpad_device_enabled (id, TRUE) == FALSE)
                 g_warning ("Error enabling device \"%d\"", id);
         else
                 g_debug ("Enabled device %d", id);
@@ -1130,8 +1131,6 @@ set_mouse_settings (GsdMouseManager *manager,
         set_scroll_method (manager, device, g_settings_get_enum (manager->priv->touchpad_settings, 
KEY_SCROLL_METHOD));
         set_horiz_scroll (device, TRUE);
         set_natural_scroll (manager, device, g_settings_get_boolean (manager->priv->touchpad_settings, 
KEY_NATURAL_SCROLL_ENABLED));
-        if (!get_touchpad_enabled (manager))
-                set_touchpad_disabled (device);
 
         set_scroll_wheel_button (manager, device);
 }
@@ -1202,11 +1201,6 @@ touchpad_callback (GSettings       *settings,
                 } else if (g_str_equal (key, KEY_SCROLL_METHOD)) {
                         set_scroll_method (manager, device, g_settings_get_enum (settings, key));
                         set_horiz_scroll (device, TRUE);
-                } else if (g_str_equal (key, KEY_SEND_EVENTS)) {
-                        if (!get_touchpad_enabled (manager))
-                                set_touchpad_disabled (device);
-                        else
-                                set_touchpad_enabled (gdk_x11_device_get_id (device));
                 } else if (g_str_equal (key, KEY_SPEED)) {
                         set_motion (manager, device);
                 } else if (g_str_equal (key, KEY_LEFT_HANDED)) {
@@ -1252,9 +1246,11 @@ static void
 ensure_touchpad_active (GsdMouseManager *manager)
 {
         GList *devices, *l;
+        gboolean state;
 
-        if (get_touchpad_enabled (manager)) {
-                devices = get_disabled_devices (manager->priv->device_manager);
+        state = get_touchpad_enabled (manager);
+        if (state) {
+                devices = get_disabled_touchpads (manager->priv->device_manager);
                 for (l = devices; l != NULL; l = l->next) {
                         int device_id;
 
@@ -1281,6 +1277,8 @@ ensure_touchpad_active (GsdMouseManager *manager)
 
                 g_list_free (devices);
         }
+
+        set_disable_w_typing (manager, state);
 }
 
 static void
@@ -1298,10 +1296,6 @@ device_added_cb (GdkDeviceManager *device_manager,
                                              GINT_TO_POINTER (id), GINT_TO_POINTER (1));
                 }
 
-                /* If a touchpad was to appear... */
-                set_disable_w_typing (manager, TRUE);
-
-                /* If a mouse was to appear... */
                 ensure_touchpad_active (manager);
         }
 }
@@ -1322,9 +1316,6 @@ device_removed_cb (GdkDeviceManager *device_manager,
         if (device_is_ignored (manager, device) == FALSE) {
                 run_custom_command (device, COMMAND_DEVICE_REMOVED);
 
-                /* If a touchpad was to disappear... */
-                set_disable_w_typing (manager, TRUE);
-
                 ensure_touchpad_active (manager);
         }
 }
@@ -1385,7 +1376,6 @@ gsd_mouse_manager_idle_cb (GsdMouseManager *manager)
         set_mousetweaks_daemon (manager,
                                 g_settings_get_boolean (manager->priv->mouse_a11y_settings, 
KEY_DWELL_CLICK_ENABLED),
                                 g_settings_get_boolean (manager->priv->mouse_a11y_settings, 
KEY_SECONDARY_CLICK_ENABLED));
-        set_disable_w_typing (manager, TRUE);
 
         devices = gdk_device_manager_list_devices (manager->priv->device_manager, GDK_DEVICE_TYPE_SLAVE);
         for (l = devices; l != NULL; l = l->next) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]