[gtk+/xi2: 1140/1239] GdkDevice: Add GdkDeviceType property.



commit 38ff65de97ff2b367d13a348e503a3bada7ed3db
Author: Carlos Garnacho <carlos gnome org>
Date:   Tue Sep 15 10:20:02 2009 +0200

    GdkDevice: Add GdkDeviceType property.
    
    Device managers now set that property to all created devices.

 gdk/gdkdevice.c                 |   28 ++++++++++++++++++++++++++++
 gdk/gdkdevice.h                 |    9 +++++++++
 gdk/gdkdevicemanager.h          |    6 ------
 gdk/x11/gdkdevicemanager-core.c |    2 ++
 gdk/x11/gdkdevicemanager-xi2.c  |   18 ++++++++++++++++++
 5 files changed, 57 insertions(+), 6 deletions(-)
---
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index f0c3d18..27e11c1 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -45,6 +45,7 @@ struct _GdkDevicePrivate
 {
   GdkDisplay *display;
   GdkDevice *relative;
+  GdkDeviceType type;
   GArray *axes;
 };
 
@@ -66,6 +67,7 @@ enum {
   PROP_DISPLAY,
   PROP_NAME,
   PROP_RELATIVE,
+  PROP_TYPE,
   PROP_INPUT_SOURCE,
   PROP_INPUT_MODE,
   PROP_HAS_CURSOR,
@@ -97,6 +99,14 @@ gdk_device_class_init (GdkDeviceClass *klass)
                                                         NULL,
                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
   g_object_class_install_property (object_class,
+                                   PROP_TYPE,
+                                   g_param_spec_enum ("type",
+                                                      P_("Device type"),
+                                                      P_("Device role in the device manager"),
+                                                      GDK_TYPE_DEVICE_TYPE,
+                                                      GDK_DEVICE_TYPE_MASTER,
+                                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (object_class,
 				   PROP_RELATIVE,
 				   g_param_spec_object ("relative",
                                                         P_("Relative device"),
@@ -183,6 +193,9 @@ gdk_device_set_property (GObject      *object,
 
       device->name = g_value_dup_string (value);
       break;
+    case PROP_TYPE:
+      priv->type = g_value_get_enum (value);
+      break;
     case PROP_INPUT_SOURCE:
       device->source = g_value_get_enum (value);
       break;
@@ -219,6 +232,9 @@ gdk_device_get_property (GObject    *object,
       g_value_set_string (value,
                           device->name);
       break;
+    case PROP_TYPE:
+      g_value_set_enum (value, priv->type);
+      break;
     case PROP_INPUT_SOURCE:
       g_value_set_enum (value, device->source);
       break;
@@ -393,6 +409,18 @@ _gdk_device_set_relative (GdkDevice *device,
     priv->relative = g_object_ref (relative);
 }
 
+GdkDeviceType
+gdk_device_get_device_type (GdkDevice *device)
+{
+  GdkDevicePrivate *priv;
+
+  g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_DEVICE_TYPE_MASTER);
+
+  priv = GDK_DEVICE_GET_PRIVATE (device);
+
+  return priv->type;
+}
+
 GList *
 gdk_device_list_axes (GdkDevice *device)
 {
diff --git a/gdk/gdkdevice.h b/gdk/gdkdevice.h
index 354abf3..3f4eae2 100644
--- a/gdk/gdkdevice.h
+++ b/gdk/gdkdevice.h
@@ -73,6 +73,12 @@ typedef enum
   GDK_AXIS_LAST
 } GdkAxisUse;
 
+typedef enum {
+  GDK_DEVICE_TYPE_MASTER,
+  GDK_DEVICE_TYPE_SLAVE,
+  GDK_DEVICE_TYPE_FLOATING
+} GdkDeviceType;
+
 struct _GdkDeviceKey
 {
   guint keyval;
@@ -160,6 +166,9 @@ GdkDisplay * gdk_device_get_display (GdkDevice      *device);
 
 GdkDevice  * gdk_device_get_relative (GdkDevice     *device);
 
+GdkDeviceType gdk_device_get_device_type (GdkDevice *device);
+
+
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_H__ */
diff --git a/gdk/gdkdevicemanager.h b/gdk/gdkdevicemanager.h
index 0f35dd8..1bfa610 100644
--- a/gdk/gdkdevicemanager.h
+++ b/gdk/gdkdevicemanager.h
@@ -40,12 +40,6 @@ G_BEGIN_DECLS
 typedef struct _GdkDeviceManager GdkDeviceManager;
 typedef struct _GdkDeviceManagerClass GdkDeviceManagerClass;
 
-typedef enum {
-  GDK_DEVICE_TYPE_MASTER,
-  GDK_DEVICE_TYPE_SLAVE,
-  GDK_DEVICE_TYPE_FLOATING
-} GdkDeviceType;
-
 struct _GdkDeviceManager
 {
   GObject parent_instance;
diff --git a/gdk/x11/gdkdevicemanager-core.c b/gdk/x11/gdkdevicemanager-core.c
index dda714b..4a7955a 100644
--- a/gdk/x11/gdkdevicemanager-core.c
+++ b/gdk/x11/gdkdevicemanager-core.c
@@ -71,6 +71,7 @@ create_core_pointer (GdkDisplay *display)
 {
   return g_object_new (GDK_TYPE_DEVICE_CORE,
                        "name", "Core Pointer",
+                       "type", GDK_DEVICE_TYPE_MASTER,
                        "input-source", GDK_SOURCE_MOUSE,
                        "input-mode", GDK_MODE_SCREEN,
                        "has-cursor", TRUE,
@@ -83,6 +84,7 @@ create_core_keyboard (GdkDisplay *display)
 {
   return g_object_new (GDK_TYPE_DEVICE_CORE,
                        "name", "Core Keyboard",
+                       "type", GDK_DEVICE_TYPE_MASTER,
                        "input-source", GDK_SOURCE_KEYBOARD,
                        "has-cursor", TRUE,
                        "display", display,
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index a8f8829..950264f 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -166,6 +166,7 @@ create_device (GdkDisplay   *display,
                XIDeviceInfo *dev)
 {
   GdkInputSource input_source;
+  GdkDeviceType type;
   GdkDevice *device;
 
   if (dev->use == XIMasterKeyboard || dev->use == XISlaveKeyboard)
@@ -176,8 +177,25 @@ create_device (GdkDisplay   *display,
       input_source = GDK_SOURCE_MOUSE;
     }
 
+  switch (dev->use)
+    {
+    case XIMasterKeyboard:
+    case XIMasterPointer:
+      type = GDK_DEVICE_TYPE_MASTER;
+      break;
+    case XISlaveKeyboard:
+    case XISlavePointer:
+      type = GDK_DEVICE_TYPE_SLAVE;
+      break;
+    case XIFloatingSlave:
+    default:
+      type = GDK_DEVICE_TYPE_FLOATING;
+      break;
+    }
+
   device = g_object_new (GDK_TYPE_DEVICE_XI2,
                          "name", dev->name,
+                         "type", type,
                          "input-source", input_source,
                          "input-mode", (dev->use == XIMasterPointer) ? GDK_MODE_SCREEN : GDK_MODE_DISABLED,
                          "has-cursor", (dev->use == XIMasterPointer),



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