[gnome-settings-daemon] common: Add helper to get the input device node



commit 24a87788cd7e9eee111ae5da6ba1dfd446b1c99b
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Oct 31 16:11:37 2011 +0000

    common: Add helper to get the input device node

 plugins/common/gsd-input-helper.c |   48 +++++++++++++++++++++++++++++++++++++
 plugins/common/gsd-input-helper.h |    1 +
 2 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/plugins/common/gsd-input-helper.c b/plugins/common/gsd-input-helper.c
index 70b2be4..7ad5cbd 100644
--- a/plugins/common/gsd-input-helper.c
+++ b/plugins/common/gsd-input-helper.c
@@ -236,6 +236,54 @@ touchpad_is_present (void)
                                        device_is_touchpad);
 }
 
+char *
+xdevice_get_device_node (int deviceid)
+{
+        Atom           prop;
+        Atom           act_type;
+        int            act_format;
+        unsigned long  nitems, bytes_after;
+        unsigned char *data;
+        char          *ret;
+
+        gdk_display_sync (gdk_display_get_default ());
+
+        prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Device Node", False);
+        if (!prop)
+                return NULL;
+
+        gdk_error_trap_push ();
+
+        if (!XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+                            deviceid, prop, 0, 1000, False,
+                            AnyPropertyType, &act_type, &act_format,
+                            &nitems, &bytes_after, &data) == Success) {
+                gdk_error_trap_pop_ignored ();
+                return NULL;
+        }
+        if (gdk_error_trap_pop ())
+                goto out;
+
+        if (nitems == 0)
+                goto out;
+
+        if (act_type != XA_STRING)
+                goto out;
+
+        /* Unknown string format */
+        if (act_format != 8)
+                goto out;
+
+        ret = g_strdup ((char *) data);
+
+        XFree (data);
+        return ret;
+
+out:
+        XFree (data);
+        return NULL;
+}
+
 gboolean
 set_device_enabled (int device_id,
                     gboolean enabled)
diff --git a/plugins/common/gsd-input-helper.h b/plugins/common/gsd-input-helper.h
index e96fee4..0bc205b 100644
--- a/plugins/common/gsd-input-helper.h
+++ b/plugins/common/gsd-input-helper.h
@@ -70,6 +70,7 @@ gboolean  run_custom_command      (GdkDevice              *device,
                                    CustomCommand           command);
 
 GList *   get_disabled_devices    (GdkDeviceManager       *manager);
+char *    xdevice_get_device_node (int                     deviceid);
 
 G_END_DECLS
 



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