[gtk+/overlay-heuristics: 6/8] Track the most-recently used device
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/overlay-heuristics: 6/8] Track the most-recently used device
- Date: Fri, 28 Nov 2014 19:30:12 +0000 (UTC)
commit a0e294dba9c473c887132628ac92f05bc8e64304
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Nov 28 12:32:48 2014 -0500
Track the most-recently used device
Add a ::current-device property to GdkDeviceManager which tracks
the most recently used slave device.
gdk/gdkdevice.c | 6 +++++-
gdk/gdkdevicemanager.c | 35 ++++++++++++++++++++++++++++++++++-
gdk/gdkdevicemanagerprivate.h | 5 +++++
3 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index 51c9172..d8b66f1 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -20,6 +20,7 @@
#include <math.h>
#include "gdkdeviceprivate.h"
+#include "gdkdevicemanagerprivate.h"
#include "gdkdisplayprivate.h"
#include "gdkinternals.h"
#include "gdkintl.h"
@@ -1782,5 +1783,8 @@ _gdk_device_set_time (GdkDevice *device,
guint32 time)
{
if (time > device->time)
- device->time = time;
+ {
+ device->time = time;
+ _gdk_device_manager_update_current_device (device->manager, device);
+ }
}
diff --git a/gdk/gdkdevicemanager.c b/gdk/gdkdevicemanager.c
index 3da434d..e7e16b5 100644
--- a/gdk/gdkdevicemanager.c
+++ b/gdk/gdkdevicemanager.c
@@ -154,13 +154,15 @@ G_DEFINE_ABSTRACT_TYPE (GdkDeviceManager, gdk_device_manager, G_TYPE_OBJECT)
enum {
PROP_0,
- PROP_DISPLAY
+ PROP_DISPLAY,
+ PROP_CURRENT_DEVICE
};
enum {
DEVICE_ADDED,
DEVICE_REMOVED,
DEVICE_CHANGED,
+ CURRENT_DEVICE_CHANGED,
LAST_SIGNAL
};
@@ -184,6 +186,15 @@ gdk_device_manager_class_init (GdkDeviceManagerClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_CURRENT_DEVICE,
+ g_param_spec_object ("current-device",
+ P_("Current device"),
+ P_("Most recently used device"),
+ GDK_TYPE_DEVICE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
/**
* GdkDeviceManager::device-added:
* @device_manager: the object on which the signal is emitted
@@ -283,6 +294,9 @@ gdk_device_manager_get_property (GObject *object,
case PROP_DISPLAY:
g_value_set_object (value, GDK_DEVICE_MANAGER (object)->display);
break;
+ case PROP_CURRENT_DEVICE:
+ g_value_set_object (value, GDK_DEVICE_MANAGER (object)->current_device);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -356,3 +370,22 @@ gdk_device_manager_get_client_pointer (GdkDeviceManager *device_manager)
return GDK_DEVICE_MANAGER_GET_CLASS (device_manager)->get_client_pointer (device_manager);
}
+
+void
+_gdk_device_manager_update_current_device (GdkDeviceManager *device_manager,
+ GdkDevice *device)
+{
+ if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE)
+ return;
+
+ if (device_manager->current_device == device)
+ return;
+
+ if (device_manager->current_device == NULL ||
+ device == NULL ||
+ gdk_device_get_time (device) >= gdk_device_get_time (device_manager->current_device))
+ {
+ device_manager->current_device = device;
+ g_object_notify (G_OBJECT (device_manager), "current-device");
+ }
+}
diff --git a/gdk/gdkdevicemanagerprivate.h b/gdk/gdkdevicemanagerprivate.h
index c18d2cd..5ce6371 100644
--- a/gdk/gdkdevicemanagerprivate.h
+++ b/gdk/gdkdevicemanagerprivate.h
@@ -36,6 +36,7 @@ struct _GdkDeviceManager
/*< private >*/
GdkDisplay *display;
+ GdkDevice *current_device;
};
struct _GdkDeviceManagerClass
@@ -56,6 +57,10 @@ struct _GdkDeviceManagerClass
GdkDevice * (* get_client_pointer) (GdkDeviceManager *device_manager);
};
+void
+_gdk_device_manager_update_current_device (GdkDeviceManager *device_manager,
+ GdkDevice *device);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]