[gnome-settings-daemon/gnome-3-16] common: Make device type presence checks work on libinput and wayland



commit 12f746566ae865340b0266c3043d9023546787c1
Author: Rui Matos <tiagomatos gmail com>
Date:   Fri May 29 20:10:38 2015 +0200

    common: Make device type presence checks work on libinput and wayland
    
    Using GsdDeviceManager allows our device type presence checks work
    both on libinput using X sessions and on Wayland sessions.
    
    At the same time we still need to support systems using the synaptics
    X driver so let's make that an explicit separate check.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=749818

 plugins/common/gsd-input-helper.c |  101 ++++++++++++------------------------
 plugins/common/gsd-input-helper.h |    9 +---
 plugins/mouse/gsd-mouse-manager.c |   36 ++++++++++---
 3 files changed, 63 insertions(+), 83 deletions(-)
---
diff --git a/plugins/common/gsd-input-helper.c b/plugins/common/gsd-input-helper.c
index 7ea4061..e0f4015 100644
--- a/plugins/common/gsd-input-helper.c
+++ b/plugins/common/gsd-input-helper.c
@@ -29,6 +29,7 @@
 #include <X11/extensions/XInput2.h>
 
 #include "gsd-input-helper.h"
+#include "gsd-device-manager.h"
 
 #define INPUT_DEVICES_SCHEMA "org.gnome.settings-daemon.peripherals.input-devices"
 #define KEY_HOTPLUG_COMMAND  "hotplug-command"
@@ -163,7 +164,7 @@ supports_xinput2_devices (int *opcode)
 }
 
 gboolean
-device_is_touchpad (XDevice *xdevice)
+xdevice_is_synaptics (XDevice *xdevice)
 {
         Atom realtype, prop;
         int realformat;
@@ -191,60 +192,13 @@ device_is_touchpad (XDevice *xdevice)
 }
 
 gboolean
-device_info_is_touchpad (XDeviceInfo *device_info)
-{
-        return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), 
XI_TOUCHPAD, False));
-}
-
-gboolean
-device_info_is_touchscreen (XDeviceInfo *device_info)
-{
-        return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), 
XI_TOUCHSCREEN, False));
-}
-
-gboolean
-device_info_is_tablet (XDeviceInfo *device_info)
-{
-        /* Note that this doesn't match Wacom tablets */
-        return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), 
XI_TABLET, False));
-}
-
-gboolean
-device_info_is_mouse (XDeviceInfo *device_info)
-{
-        return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), 
XI_MOUSE, False));
-}
-
-gboolean
-device_info_is_trackball (XDeviceInfo *device_info)
-{
-        gboolean retval;
-
-        retval = (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), 
XI_TRACKBALL, False));
-        if (retval == FALSE &&
-            device_info->name != NULL) {
-                char *lowercase;
-
-                lowercase = g_ascii_strdown (device_info->name, -1);
-                retval = strstr (lowercase, "trackball") != NULL;
-                g_free (lowercase);
-        }
-
-        return retval;
-}
-
-static gboolean
-device_type_is_present (InfoIdentifyFunc info_func,
-                        DeviceIdentifyFunc device_func)
+synaptics_is_present (void)
 {
         XDeviceInfo *device_info;
         gint n_devices;
         guint i;
         gboolean retval;
 
-        if (supports_xinput_devices () == FALSE)
-                return TRUE;
-
         retval = FALSE;
 
         device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &n_devices);
@@ -254,21 +208,12 @@ device_type_is_present (InfoIdentifyFunc info_func,
         for (i = 0; i < n_devices; i++) {
                 XDevice *device;
 
-                /* Check with the device info first */
-                retval = (info_func) (&device_info[i]);
-                if (retval == FALSE)
-                        continue;
-
-                /* If we only have an info func, we're done checking */
-                if (device_func == NULL)
-                        break;
-
                 gdk_error_trap_push ();
                 device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device_info[i].id);
                 if (gdk_error_trap_pop () || (device == NULL))
                         continue;
 
-                retval = (device_func) (device);
+                retval = xdevice_is_synaptics (device);
                 xdevice_close (device);
                 if (retval)
                         break;
@@ -278,32 +223,54 @@ device_type_is_present (InfoIdentifyFunc info_func,
         return retval;
 }
 
+static gboolean
+device_type_is_present (GsdDeviceType type)
+{
+        GList *l = gsd_device_manager_list_devices (gsd_device_manager_get (),
+                                                    type);
+        g_list_free (l);
+        return l != NULL;
+}
+
 gboolean
 touchscreen_is_present (void)
 {
-        return device_type_is_present (device_info_is_touchscreen,
-                                       NULL);
+        return device_type_is_present (GSD_DEVICE_TYPE_TOUCHSCREEN);
 }
 
 gboolean
 touchpad_is_present (void)
 {
-        return device_type_is_present (device_info_is_touchpad,
-                                       device_is_touchpad);
+        return device_type_is_present (GSD_DEVICE_TYPE_TOUCHPAD);
 }
 
 gboolean
 mouse_is_present (void)
 {
-        return device_type_is_present (device_info_is_mouse,
-                                       NULL);
+        return device_type_is_present (GSD_DEVICE_TYPE_MOUSE);
 }
 
 gboolean
 trackball_is_present (void)
 {
-        return device_type_is_present (device_info_is_trackball,
-                                       NULL);
+        gboolean retval;
+        GList *l, *mice = gsd_device_manager_list_devices (gsd_device_manager_get (),
+                                                           GSD_DEVICE_TYPE_MOUSE);
+        if (mice == NULL)
+                return FALSE;
+
+        for (l = mice; l != NULL; l = l->next) {
+                gchar *lowercase;
+                const gchar *name = gsd_device_get_name (l->data);
+                if (!name)
+                        continue;
+                lowercase = g_ascii_strdown (name, -1);
+                retval = strstr (lowercase, "trackball") != NULL;
+                g_free (lowercase);
+        }
+
+        g_list_free (mice);
+        return retval;
 }
 
 char *
diff --git a/plugins/common/gsd-input-helper.h b/plugins/common/gsd-input-helper.h
index 4df8dc3..9f54806 100644
--- a/plugins/common/gsd-input-helper.h
+++ b/plugins/common/gsd-input-helper.h
@@ -60,14 +60,9 @@ gboolean set_device_enabled       (int device_id,
 gboolean  set_touchpad_device_enabled (int device_id,
                                        gboolean enabled);
 
-gboolean  device_is_touchpad       (XDevice                *xdevice);
-
-gboolean  device_info_is_touchpad    (XDeviceInfo         *device_info);
-gboolean  device_info_is_touchscreen (XDeviceInfo         *device_info);
-gboolean  device_info_is_tablet (XDeviceInfo         *device_info);
-gboolean  device_info_is_mouse       (XDeviceInfo         *device_info);
-gboolean  device_info_is_trackball   (XDeviceInfo         *device_info);
+gboolean  xdevice_is_synaptics       (XDevice                *xdevice);
 
+gboolean  synaptics_is_present    (void);
 gboolean  touchpad_is_present     (void);
 gboolean  touchscreen_is_present  (void);
 gboolean  mouse_is_present        (void);
diff --git a/plugins/mouse/gsd-mouse-manager.c b/plugins/mouse/gsd-mouse-manager.c
index 1e844e0..4449722 100644
--- a/plugins/mouse/gsd-mouse-manager.c
+++ b/plugins/mouse/gsd-mouse-manager.c
@@ -144,6 +144,24 @@ open_gdk_device (GdkDevice *device)
 }
 
 static gboolean
+device_info_is_trackball (XDeviceInfo *device_info)
+{
+        gboolean retval;
+
+        retval = (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), 
XI_TRACKBALL, False));
+        if (retval == FALSE &&
+            device_info->name != NULL) {
+                char *lowercase;
+
+                lowercase = g_ascii_strdown (device_info->name, -1);
+                retval = strstr (lowercase, "trackball") != NULL;
+                g_free (lowercase);
+        }
+
+        return retval;
+}
+
+static gboolean
 device_is_trackball (GdkDevice *device)
 {
         XDeviceInfo *device_info;
@@ -375,7 +393,7 @@ set_left_handed (GsdMouseManager *manager,
 
         /* If the device is a touchpad, swap tap buttons
          * around too, otherwise a tap would be a right-click */
-        if (device_is_touchpad (xdevice)) {
+        if (xdevice_is_synaptics (xdevice)) {
                 gboolean tap = g_settings_get_boolean (manager->priv->touchpad_settings, KEY_TAP_TO_CLICK);
                 gboolean single_button = touchpad_has_single_button (xdevice);
 
@@ -440,7 +458,7 @@ set_motion (GsdMouseManager *manager,
 
        g_debug ("setting motion on %s", gdk_device_get_name (device));
 
-        if (device_is_touchpad (xdevice))
+        if (xdevice_is_synaptics (xdevice))
                 settings = manager->priv->touchpad_settings;
         else
                 settings = manager->priv->mouse_settings;
@@ -551,7 +569,7 @@ syndaemon_died (GPid pid, gint status, gpointer user_data)
 static int
 set_disable_w_typing (GsdMouseManager *manager, gboolean state)
 {
-        if (state && touchpad_is_present ()) {
+        if (state && synaptics_is_present ()) {
                 GError *error = NULL;
                 GPtrArray *args;
 
@@ -622,7 +640,7 @@ set_tap_to_click (GdkDevice *device,
         if (xdevice == NULL)
                 return;
 
-        if (!device_is_touchpad (xdevice)) {
+        if (!xdevice_is_synaptics (xdevice)) {
                 xdevice_close (xdevice);
                 return;
         }
@@ -687,7 +705,7 @@ set_horiz_scroll (GdkDevice *device,
         if (xdevice == NULL)
                 return;
 
-        if (!device_is_touchpad (xdevice)) {
+        if (!xdevice_is_synaptics (xdevice)) {
                 xdevice_close (xdevice);
                 return;
         }
@@ -757,7 +775,7 @@ set_scroll_method (GsdMouseManager         *manager,
         if (xdevice == NULL)
                 return;
 
-        if (!device_is_touchpad (xdevice)) {
+        if (!xdevice_is_synaptics (xdevice)) {
                 xdevice_close (xdevice);
                 return;
         }
@@ -830,7 +848,7 @@ set_touchpad_disabled (GdkDevice *device)
         if (xdevice == NULL)
                 return;
 
-        if (!device_is_touchpad (xdevice)) {
+        if (!xdevice_is_synaptics (xdevice)) {
                 xdevice_close (xdevice);
                 return;
         }
@@ -858,7 +876,7 @@ set_touchpad_enabled (int id)
         if (gdk_error_trap_pop () != 0)
                 return;
 
-        if (!device_is_touchpad (xdevice)) {
+        if (!xdevice_is_synaptics (xdevice)) {
                 xdevice_close (xdevice);
                 return;
         }
@@ -969,7 +987,7 @@ set_natural_scroll (GsdMouseManager *manager,
         if (xdevice == NULL)
                 return;
 
-        if (!device_is_touchpad (xdevice)) {
+        if (!xdevice_is_synaptics (xdevice)) {
                 xdevice_close (xdevice);
                 return;
         }


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