[gtk/device-timestamp: 1/3] gdk: Add gdk_device_get_timestamp




commit 89409d968f5900fad2865664374ad14b2d20599f
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Mar 25 22:39:15 2021 -0400

    gdk: Add gdk_device_get_timestamp
    
    Give each device a timestamp that reflects the last
    user activity with that device, as reflected in the
    events that are produced for this device.

 gdk/gdkdevice.c        | 28 ++++++++++++++++++++++++++++
 gdk/gdkdevice.h        |  3 +++
 gdk/gdkdeviceprivate.h |  5 +++++
 gdk/gdkevents.c        |  3 +++
 4 files changed, 39 insertions(+)
---
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index 24a7d8b3b3..ea0b78fb28 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -1381,3 +1381,31 @@ gdk_device_has_bidi_layouts (GdkDevice *device)
 
   return FALSE;
 }
+
+void
+gdk_device_set_timestamp (GdkDevice *device,
+                          guint32    timestamp)
+{
+  device->timestamp = timestamp;
+}
+
+/**
+ * gdk_device_get_timestamp:
+ * @device: a `GdkDevice`
+ *
+ * Returns the timestamp of the last activity for this device.
+ *
+ * In practice, this means the timestamp of the last event that was
+ * received from the OS for this device. (GTK may occasionally produce
+ * events for a device that are not received from the OS, and will not
+ * update the timestamp).
+ *
+ * Returns: the timestamp of the last activity for this device
+ *
+ * Since: 4.2
+ */
+guint32
+gdk_device_get_timestamp (GdkDevice *device)
+{
+  return device->timestamp;
+}
diff --git a/gdk/gdkdevice.h b/gdk/gdkdevice.h
index 58d75199f8..720347e95f 100644
--- a/gdk/gdkdevice.h
+++ b/gdk/gdkdevice.h
@@ -117,6 +117,9 @@ GDK_AVAILABLE_IN_ALL
 GdkSurface *        gdk_device_get_surface_at_position  (GdkDevice *device,
                                                          double    *win_x,
                                                          double    *win_y);
+
+GDK_AVAILABLE_IN_4_2
+guint32             gdk_device_get_timestamp            (GdkDevice *device);
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_H__ */
diff --git a/gdk/gdkdeviceprivate.h b/gdk/gdkdeviceprivate.h
index a4cfffc28b..8a2be66155 100644
--- a/gdk/gdkdeviceprivate.h
+++ b/gdk/gdkdeviceprivate.h
@@ -89,6 +89,8 @@ struct _GdkDevice
 
   GdkSeat *seat;
   GdkDeviceTool *last_tool;
+
+  guint32 timestamp;
 };
 
 struct _GdkDeviceClass
@@ -189,6 +191,9 @@ gboolean gdk_device_get_axis  (GdkDevice         *device,
 GdkAxisUse gdk_device_get_axis_use  (GdkDevice         *device,
                                      guint              index_);
 
+void gdk_device_set_timestamp (GdkDevice *device,
+                               guint32    timestamp);
+
 
 G_END_DECLS
 
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index f7abfe75b5..43e9c9f01a 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -414,6 +414,9 @@ gdk_event_alloc (GdkEventType event_type,
   event->device = device != NULL ? g_object_ref (device) : NULL;
   event->time = time_;
 
+  if (device != NULL && time_ != GDK_CURRENT_TIME)
+    gdk_device_set_timestamp (device, time_);
+
   return event;
 }
 


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