summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-10-11 10:28:27 +0100
committerCaolán McNamara <caolanm@redhat.com>2021-10-11 20:20:04 +0200
commita43b684267a42f733cb5d752cddfe307ce4a0077 (patch)
treeef682062ad8df8d0d340a193671a601d1ac99557
parentc876183e4c0aff0fe95145c6ee4a84b213a54190 (diff)
gtk4: fix asserts and crashes on context menu popdown
Change-Id: Iad87892e5e1474118138c07558dc37d793e5bfdf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123377 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--vcl/unx/gtk3/gtksalmenu.cxx19
1 files changed, 13 insertions, 6 deletions
diff --git a/vcl/unx/gtk3/gtksalmenu.cxx b/vcl/unx/gtk3/gtksalmenu.cxx
index 818cdcd9b57f..5ad80816cded 100644
--- a/vcl/unx/gtk3/gtksalmenu.cxx
+++ b/vcl/unx/gtk3/gtksalmenu.cxx
@@ -415,6 +415,13 @@ static void MenuPositionFunc(GtkMenu* menu, gint* x, gint* y, gboolean* push_in,
}
#endif
+static void MenuClosed(GtkPopover* pWidget, GMainLoop* pLoop)
+{
+ // gtk4 4.4.0: click on an entry in a submenu of a menu crashes without this workaround
+ gtk_widget_grab_focus(gtk_widget_get_parent(GTK_WIDGET(pWidget)));
+ g_main_loop_quit(pLoop);
+}
+
bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const tools::Rectangle& rRect,
FloatWinPopupFlags nFlags)
{
@@ -443,9 +450,9 @@ bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const tools::Rectangl
//until the gtk menu is destroyed
GMainLoop* pLoop = g_main_loop_new(nullptr, true);
#if GTK_CHECK_VERSION(4, 0, 0)
- g_signal_connect_swapped(G_OBJECT(mpMenuWidget), "closed", G_CALLBACK(g_main_loop_quit), pLoop);
+ g_signal_connect(G_OBJECT(mpMenuWidget), "closed", G_CALLBACK(MenuClosed), pLoop);
#else
- g_signal_connect_swapped(G_OBJECT(mpMenuWidget), "deactivate", G_CALLBACK(g_main_loop_quit), pLoop);
+ g_signal_connect(G_OBJECT(mpMenuWidget), "deactivate", G_CALLBACK(MenuClosed), pLoop);
#endif
@@ -544,17 +551,17 @@ bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const tools::Rectangl
mpVCLMenu->Deactivate();
- gtk_widget_insert_action_group(mpFrame->getMouseEventWidget(), "win", nullptr);
+ g_object_unref(mpActionGroup);
+ ClearActionGroupAndMenuModel();
#if !GTK_CHECK_VERSION(4, 0, 0)
gtk_widget_destroy(mpMenuWidget);
#else
- g_clear_pointer(&mpMenuWidget, gtk_widget_unparent);
+ gtk_widget_unparent(mpMenuWidget);
#endif
mpMenuWidget = nullptr;
- g_object_unref(mpActionGroup);
- ClearActionGroupAndMenuModel();
+ gtk_widget_insert_action_group(mpFrame->getMouseEventWidget(), "win", nullptr);
// undo tooltip blocking
mpFrame->UnblockTooltip();