[gtk+] Emit GdkDevice::changed when the slave device being used changes



commit 9f41101ccc5d81f748f64752528cc3751f971597
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Dec 15 02:34:42 2010 +0100

    Emit GdkDevice::changed when the slave device being used changes
    
    When the slave device changes, the master takes the shape of the
    new one, modifying its axes, this signal is more useful to catch
    this situation than the n-axes property

 gdk/gdkdevice.c                |   28 ++++++++++++++++++++++++++++
 gdk/x11/gdkdevicemanager-xi2.c |    2 ++
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index 4e9b3d2..dc66f3b 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -64,6 +64,14 @@ struct _GdkDevicePrivate
   GArray *axes;
 };
 
+enum {
+  CHANGED,
+  LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL] = { 0 };
+
+
 static void gdk_device_dispose      (GObject      *object);
 static void gdk_device_set_property (GObject      *object,
                                      guint         prop_id,
@@ -238,6 +246,26 @@ gdk_device_class_init (GdkDeviceClass *klass)
                                                       0, G_MAXUINT, 0,
                                                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  /**
+   * GdkDevice::changed:
+   * @device: the #GdkDevice that changed.
+   *
+   * The ::changed signal is emitted either when the #GdkDevice
+   * has changed the number of either axes or keys. For example
+   * In X this will normally happen when the slave device routing
+   * events through the master device changes (for example, user
+   * switches from the USB mouse to a tablet), in that case the
+   * master device will change to reflect the new slave device
+   * axes and keys.
+   */
+  signals[CHANGED] =
+    g_signal_new (g_intern_static_string ("changed"),
+                  G_TYPE_FROM_CLASS (object_class),
+                  G_SIGNAL_RUN_LAST,
+                  NULL, NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
   g_type_class_add_private (object_class, sizeof (GdkDevicePrivate));
 }
 
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 1cc2fc2..bdfeac9 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -499,6 +499,8 @@ handle_device_changed (GdkDeviceManagerXI2  *device_manager,
 
   _gdk_device_reset_axes (device);
   translate_device_classes (display, device, ev->classes, ev->num_classes);
+
+  g_signal_emit_by_name (G_OBJECT (device), "changed");
 }
 
 static GdkCrossingMode



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