[gtksourceview] hover: don't dismiss hover request from click movement
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] hover: don't dismiss hover request from click movement
- Date: Thu, 22 Sep 2022 04:15:07 +0000 (UTC)
commit ae049441243ec838af7869c0d55390f4f5420f92
Author: Christian Hergert <chergert redhat com>
Date: Wed Sep 21 21:14:55 2022 -0700
hover: don't dismiss hover request from click movement
If we click, and that causes the insertion mark to move, we don't want to
cancel our request to potentially show hover information at that position
or the user would have to wiggle to get it to show up.
gtksourceview/gtksourcehover.c | 48 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/gtksourcehover.c b/gtksourceview/gtksourcehover.c
index 21b46b66..8d1dfe8a 100644
--- a/gtksourceview/gtksourcehover.c
+++ b/gtksourceview/gtksourcehover.c
@@ -66,6 +66,8 @@ struct _GtkSourceHover
guint hover_delay;
GSource *settle_source;
+
+ guint in_click : 1;
};
G_DEFINE_TYPE (GtkSourceHover, gtk_source_hover, G_TYPE_OBJECT)
@@ -98,7 +100,10 @@ cursor_moved_cb (GtkSourceHover *self,
g_assert (GTK_SOURCE_IS_HOVER (self));
g_assert (GTK_SOURCE_IS_BUFFER (buffer));
- gtk_source_hover_dismiss (self);
+ if (!self->in_click)
+ {
+ gtk_source_hover_dismiss (self);
+ }
}
static void
@@ -416,6 +421,32 @@ gtk_source_hover_init (GtkSourceHover *self)
self->hover_delay = DEFAULT_HOVER_DELAY;
}
+static void
+gtk_source_hover_click_pressed_cb (GtkSourceHover *self,
+ int n_press,
+ double x,
+ double y,
+ GtkGestureClick *click)
+{
+ g_assert (GTK_SOURCE_IS_HOVER (self));
+ g_assert (GTK_IS_GESTURE_CLICK (click));
+
+ self->in_click = TRUE;
+}
+
+static void
+gtk_source_hover_click_released_cb (GtkSourceHover *self,
+ int n_press,
+ double x,
+ double y,
+ GtkGestureClick *click)
+{
+ g_assert (GTK_SOURCE_IS_HOVER (self));
+ g_assert (GTK_IS_GESTURE_CLICK (click));
+
+ self->in_click = FALSE;
+}
+
GtkSourceHover *
_gtk_source_hover_new (GtkSourceView *view)
{
@@ -423,6 +454,7 @@ _gtk_source_hover_new (GtkSourceView *view)
GtkEventController *key;
GtkEventController *motion;
GtkEventController *scroll;
+ GtkEventController *click;
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
@@ -452,6 +484,20 @@ _gtk_source_hover_new (GtkSourceView *view)
G_CONNECT_SWAPPED);
gtk_widget_add_controller (GTK_WIDGET (view), motion);
+ click = GTK_EVENT_CONTROLLER (gtk_gesture_click_new ());
+ g_signal_connect_object (click,
+ "pressed",
+ G_CALLBACK (gtk_source_hover_click_pressed_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (click,
+ "released",
+ G_CALLBACK (gtk_source_hover_click_released_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ gtk_event_controller_set_propagation_phase (click, GTK_PHASE_CAPTURE);
+ gtk_widget_add_controller (GTK_WIDGET (view), click);
+
scroll = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES);
g_signal_connect_object (scroll,
"scroll",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]