From be90b453aa9ddd1873bdab11254b2e1c1326cbf8 Mon Sep 17 00:00:00 2001
From: Michael Webster <miketwebster@gmail.com>
Date: Mon, 17 Jun 2019 22:24:43 -0400
Subject: [PATCH] nemo-places-sidebar.c: Workaround incorrectly-sized popup
menus when right- clicking on a currently-unselected item.
This reverts the behavior introduced in gtk 3.24.8:
https://gitlab.gnome.org/GNOME/gtk/commit/57300b49602b856b53f5d30ab3174591c0fb2845
By connecting our own handler to 'moved-to-rect' and performing the 'popped-up'
emission ourselves (and at the same time, preventing GtkMenu's own handler from
running), we avoid the fixate call which seems to be causing this.
Fixes #2118
Fixes #2153
---
src/nemo-places-sidebar.c | 43 +++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/src/nemo-places-sidebar.c b/src/nemo-places-sidebar.c
index 87d060e99..61e80fd18 100644
--- a/src/nemo-places-sidebar.c
+++ b/src/nemo-places-sidebar.c
@@ -3395,6 +3395,42 @@ add_action_popup_items (NemoPlacesSidebar *sidebar)
}
}
+#if GTK_CHECK_VERSION (3, 24, 8)
+static void
+moved_to_rect_cb (GdkWindow *window,
+ const GdkRectangle *flipped_rect,
+ const GdkRectangle *final_rect,
+ gboolean flipped_x,
+ gboolean flipped_y,
+ GtkMenu *menu)
+{
+ g_signal_emit_by_name (menu,
+ "popped-up",
+ 0,
+ flipped_rect,
+ final_rect,
+ flipped_x,
+ flipped_y);
+
+ // Don't let the emission run in gtkmenu.c
+ g_signal_stop_emission_by_name (window, "moved-to-rect");
+}
+
+static void
+popup_menu_realized (GtkWidget *menu,
+ gpointer user_data)
+{
+ GdkWindow *toplevel;
+
+ toplevel = gtk_widget_get_window (gtk_widget_get_toplevel (menu));
+
+ g_signal_handlers_disconnect_by_func (toplevel, moved_to_rect_cb, menu);
+
+ g_signal_connect (toplevel, "moved-to-rect", G_CALLBACK (moved_to_rect_cb),
+ menu);
+}
+#endif
+
/* Constructs the popup menu for the file list if needed */
static void
bookmarks_build_popup_menu (NemoPlacesSidebar *sidebar)
@@ -3415,6 +3451,13 @@ bookmarks_build_popup_menu (NemoPlacesSidebar *sidebar)
G_CALLBACK (popup_menu_deactivated),
sidebar);
+#if GTK_CHECK_VERSION (3, 24, 8)
+ g_signal_connect (sidebar->popup_menu, "realize",
+ G_CALLBACK (popup_menu_realized),
+ sidebar);
+ gtk_widget_realize (sidebar->popup_menu);
+#endif
+
gtk_menu_attach_to_widget (GTK_MENU (sidebar->popup_menu),
GTK_WIDGET (sidebar),
bookmarks_popup_menu_detach_cb);