diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-03-26 14:51:37 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-03-26 14:51:37 +0000 |
commit | 61109800122643fa402f79e718be9d8812f874ed (patch) | |
tree | 7ae568caf1c735d081b61af1c318e7b5fc83fdf1 | |
parent | 301464945501f74acc83e0f671839dfccf4d4f4f (diff) | |
parent | 019855a27f14cc195b485ab8d5a0c4a880f3bae0 (diff) | |
download | gtk+-61109800122643fa402f79e718be9d8812f874ed.tar.gz |
Merge branch 'device-timestamp' into 'master'
Device timestamp
Closes #3792
See merge request GNOME/gtk!3350
-rw-r--r-- | gdk/gdkdevice.c | 28 | ||||
-rw-r--r-- | gdk/gdkdevice.h | 3 | ||||
-rw-r--r-- | gdk/gdkdeviceprivate.h | 5 | ||||
-rw-r--r-- | gdk/gdksurface.c | 5 | ||||
-rw-r--r-- | gtk/gtktext.c | 15 | ||||
-rw-r--r-- | gtk/gtktextview.c | 24 |
6 files changed, 78 insertions, 2 deletions
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/gdksurface.c b/gdk/gdksurface.c index 6ad438093a..c55a9a8042 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -2248,13 +2248,18 @@ _gdk_windowing_got_event (GdkDisplay *display, GdkPointerSurfaceInfo *pointer_info = NULL; GdkDevice *device; GdkEventType type; + guint32 timestamp; _gdk_display_update_last_event (display, event); device = gdk_event_get_device (event); + timestamp = gdk_event_get_time (event); if (device) { + if (timestamp != GDK_CURRENT_TIME) + gdk_device_set_timestamp (device, timestamp); + if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD && gdk_device_get_source (device) != GDK_SOURCE_TABLET_PAD) { diff --git a/gtk/gtktext.c b/gtk/gtktext.c index d0711ed3f8..183bb3a269 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -205,6 +205,7 @@ struct _GtkTextPrivate int scroll_offset; int width_chars; int max_width_chars; + guint32 obscured_cursor_timestamp; gunichar invisible_char; @@ -2940,8 +2941,12 @@ gtk_text_motion_controller_motion (GtkEventControllerMotion *controller, GtkText *self) { GtkTextPrivate *priv = gtk_text_get_instance_private (self); + GdkDevice *device; - if (priv->mouse_cursor_obscured) + device = gtk_event_controller_get_current_event_device (GTK_EVENT_CONTROLLER (controller)); + + if (priv->mouse_cursor_obscured && + gdk_device_get_timestamp (device) != priv->obscured_cursor_timestamp) { set_text_cursor (GTK_WIDGET (self)); priv->mouse_cursor_obscured = FALSE; @@ -3162,12 +3167,20 @@ static void gtk_text_obscure_mouse_cursor (GtkText *self) { GtkTextPrivate *priv = gtk_text_get_instance_private (self); + GdkDisplay *display; + GdkSeat *seat; + GdkDevice *device; if (priv->mouse_cursor_obscured) return; gtk_widget_set_cursor_from_name (GTK_WIDGET (self), "none"); + display = gtk_widget_get_display (GTK_WIDGET (self)); + seat = gdk_display_get_default_seat (display); + device = gdk_seat_get_pointer (seat); + + priv->obscured_cursor_timestamp = gdk_device_get_timestamp (device); priv->mouse_cursor_obscured = TRUE; } diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 13b0e67752..33c40d3555 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -259,8 +259,12 @@ struct _GtkTextViewPrivate int bottom_padding; int indent; + + guint32 obscured_cursor_timestamp; + gint64 handle_place_time; PangoTabArray *tabs; + guint editable : 1; guint overwrite_mode : 1; @@ -5048,18 +5052,36 @@ gtk_text_view_state_flags_changed (GtkWidget *widget, static void gtk_text_view_obscure_mouse_cursor (GtkTextView *text_view) { + GdkDisplay *display; + GdkSeat *seat; + GdkDevice *device; + if (text_view->priv->mouse_cursor_obscured) return; gtk_widget_set_cursor_from_name (GTK_WIDGET (text_view), "none"); + display = gtk_widget_get_display (GTK_WIDGET (text_view)); + seat = gdk_display_get_default_seat (display); + device = gdk_seat_get_pointer (seat); + + text_view->priv->obscured_cursor_timestamp = gdk_device_get_timestamp (device); text_view->priv->mouse_cursor_obscured = TRUE; } static void gtk_text_view_unobscure_mouse_cursor (GtkTextView *text_view) { - if (text_view->priv->mouse_cursor_obscured) + GdkDisplay *display; + GdkSeat *seat; + GdkDevice *device; + + display = gtk_widget_get_display (GTK_WIDGET (text_view)); + seat = gdk_display_get_default_seat (display); + device = gdk_seat_get_pointer (seat); + + if (text_view->priv->mouse_cursor_obscured && + gdk_device_get_timestamp (device) != text_view->priv->obscured_cursor_timestamp) { gtk_widget_set_cursor_from_name (GTK_WIDGET (text_view), "text"); text_view->priv->mouse_cursor_obscured = FALSE; |