[gtksourceview] hover: disable context menus from hover assistant
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] hover: disable context menus from hover assistant
- Date: Thu, 22 Sep 2022 04:58:36 +0000 (UTC)
commit 10728bdd397cd8098970720d0b9a5e7ead201125
Author: Christian Hergert <chergert redhat com>
Date: Wed Sep 21 21:58:00 2022 -0700
hover: disable context menus from hover assistant
This is a workaround until we can be sure that we can show popovers from
the hover assistants. Currently, that can break input pretty badly, so
this is in place to help avoid that issue by users.
This basically makes it so GtkLabel (and potentially others) cannot get
their sequence event to show the context menu since we don't have other
mechanisms to prevent it.
gtksourceview/gtksourcehoverassistant.c | 42 +++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
---
diff --git a/gtksourceview/gtksourcehoverassistant.c b/gtksourceview/gtksourcehoverassistant.c
index 47f43a15..6e9baff6 100644
--- a/gtksourceview/gtksourcehoverassistant.c
+++ b/gtksourceview/gtksourcehoverassistant.c
@@ -314,6 +314,32 @@ gtk_source_hover_assistant_dispose (GObject *object)
G_OBJECT_CLASS (gtk_source_hover_assistant_parent_class)->dispose (object);
}
+static void
+gtk_source_hover_assistant_click_pressed_cb (GtkSourceHoverAssistant *self,
+ int n_press,
+ double x,
+ double y,
+ GtkGestureClick *click)
+{
+ GdkEventSequence *sequence;
+ GdkEvent *event;
+
+ g_assert (GTK_SOURCE_IS_HOVER_ASSISTANT (self));
+ g_assert (GTK_IS_GESTURE_CLICK (click));
+
+ sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (click));
+ event = gtk_gesture_get_last_event (GTK_GESTURE (click), sequence);
+
+ /* WORKAROUND: See comment below in gtk_source_hover_assistant_init().
+ * We have to block context menus from here until we can be sure they'll
+ * work with GtkPopover:autohide disabled.
+ */
+ if (gdk_event_triggers_context_menu (event))
+ {
+ gtk_gesture_set_state (GTK_GESTURE (click), GTK_EVENT_SEQUENCE_CLAIMED);
+ }
+}
+
static void
gtk_source_hover_assistant_class_init (GtkSourceHoverAssistantClass *klass)
{
@@ -334,6 +360,7 @@ gtk_source_hover_assistant_class_init (GtkSourceHoverAssistantClass *klass)
static void
gtk_source_hover_assistant_init (GtkSourceHoverAssistant *self)
{
+ GtkEventController *click;
GtkEventController *scroll;
gtk_widget_add_css_class (GTK_WIDGET (self), "hover-assistant");
@@ -360,6 +387,21 @@ gtk_source_hover_assistant_init (GtkSourceHoverAssistant *self)
self,
G_CONNECT_SWAPPED);
gtk_widget_add_controller (GTK_WIDGET (self), g_object_ref (self->popover_motion));
+
+ /* WORKAROUND: Until we have a way to ensure that showing context
+ * menus from the popover won't break our popover, we need to prevent
+ * them from potentially breaking input/grabs.
+ */
+ click = GTK_EVENT_CONTROLLER (gtk_gesture_click_new ());
+ g_signal_connect_object (click,
+ "pressed",
+ G_CALLBACK (gtk_source_hover_assistant_click_pressed_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (click), 0);
+ gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (click), TRUE);
+ gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (click), GTK_PHASE_CAPTURE);
+ gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (click));
}
GtkSourceAssistant *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]