[gnome-builder/wip/gtk4-port: 535/736] libide/sourceview: work around popup menu allocation issues




commit 35d2dae144cb0589c23634c7a3985d15a61dee34
Author: Christian Hergert <chergert redhat com>
Date:   Fri Apr 8 13:12:24 2022 -0700

    libide/sourceview: work around popup menu allocation issues
    
    I was seeing a blank screen and weird things like the following when
    showing context menus. Doing this from the idle appears to fix it when
    spellcheck affects the contents of the popover menu.
    
    Gtk-WARNING **: 13:09:51.934: Allocating size to GtkPopoverMenu 0x55bcf1aa7d80 without calling 
gtk_widget_measure(). How does the code know the size to allocate?

 src/libide/sourceview/ide-source-view.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
---
diff --git a/src/libide/sourceview/ide-source-view.c b/src/libide/sourceview/ide-source-view.c
index 6c132d3ae..1e2619a02 100644
--- a/src/libide/sourceview/ide-source-view.c
+++ b/src/libide/sourceview/ide-source-view.c
@@ -170,6 +170,18 @@ tweak_gutter_spacing (GtkSourceView *view)
     }
 }
 
+static gboolean
+show_menu_from_idle (gpointer data)
+{
+  IdeSourceView *self = data;
+
+  g_assert (IDE_IS_SOURCE_VIEW (self));
+
+  gtk_widget_activate_action (GTK_WIDGET (self), "menu.popup", NULL);
+
+  return G_SOURCE_REMOVE;
+}
+
 static void
 ide_source_view_click_pressed_cb (IdeSourceView   *self,
                                   int              n_press,
@@ -210,6 +222,19 @@ ide_source_view_click_pressed_cb (IdeSourceView   *self,
 
   g_signal_emit (self, signals[POPULATE_MENU], 0);
 
+  /* Steal this event and manage showing the popup ourselves without
+   * using an event to silence GTK warnings elsewise. Doing this from
+   * the idle callback is really what appears to fix the allocation
+   * issue within GTK.
+   */
+  gtk_gesture_set_sequence_state (GTK_GESTURE (click),
+                                  sequence,
+                                  GTK_EVENT_SEQUENCE_CLAIMED);
+  g_idle_add_full (G_PRIORITY_LOW+1000,
+                   show_menu_from_idle,
+                   g_object_ref (self),
+                   g_object_unref);
+
   IDE_EXIT;
 }
 
@@ -367,6 +392,8 @@ ide_source_view_init (IdeSourceView *self)
   /* Setup a handler to emit ::populate-menu */
   click = GTK_EVENT_CONTROLLER (gtk_gesture_click_new ());
   gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (click), 0);
+  gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (click),
+                                              GTK_PHASE_CAPTURE);
   g_signal_connect_swapped (click,
                             "pressed",
                             G_CALLBACK (ide_source_view_click_pressed_cb),


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