gnucash master: [macOS] Better fix for menu accelerators.

John Ralls jralls at code.gnucash.org
Sat Jan 21 17:41:29 EST 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/d981679c (commit)
	from  https://github.com/Gnucash/gnucash/commit/816219c2 (commit)



commit d981679cbe31b047370188ceee1d6d6f2d733bb3
Author: John Ralls <jralls at ceridwen.us>
Date:   Sat Jan 21 14:39:16 2023 -0800

    [macOS] Better fix for menu accelerators.
    
    Connect to can-activate-accel and provide a closure for Quit
    instead of using quartz handlers for accelerators.

diff --git a/gnucash/gnome-utils/gnc-main-window.cpp b/gnucash/gnome-utils/gnc-main-window.cpp
index ecc182d26..d4dd2b568 100644
--- a/gnucash/gnome-utils/gnc-main-window.cpp
+++ b/gnucash/gnome-utils/gnc-main-window.cpp
@@ -4233,6 +4233,13 @@ gnc_quartz_should_quit (GtkosxApplication *theApp, GncMainWindow *window)
         gnc_main_window_quit (window);
     return TRUE;
 }
+/* Enable GtkMenuItem accelerators */
+static gboolean
+can_activate_cb(GtkWidget *widget, guint signal_id, gpointer data)
+{
+    //return gtk_widget_is_sensitive (widget);
+    return TRUE;
+}
 
 static void
 gnc_quartz_set_menu (GncMainWindow* window)
@@ -4240,7 +4247,7 @@ gnc_quartz_set_menu (GncMainWindow* window)
     GncMainWindowPrivate *priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
     auto theApp{static_cast<GtkosxApplication *>(g_object_new(GTKOSX_TYPE_APPLICATION, nullptr))};
     GtkWidget       *item = nullptr;
-    GAction         *action;
+    GClosure *quit_closure;
 
     gtk_widget_hide (priv->menubar);
     gtk_widget_set_no_show_all (priv->menubar, true);
@@ -4252,6 +4259,12 @@ gnc_quartz_set_menu (GncMainWindow* window)
     if (item)
         gtk_widget_hide (GTK_WIDGET(item));
 
+    quit_closure = g_cclosure_new (G_CALLBACK (gnc_quartz_should_quit),
+                                   window, NULL);
+    gtk_accel_group_connect (priv->accel_group, 'q', GDK_META_MASK,
+                             GTK_ACCEL_MASK, quit_closure);
+
+
     // Help About
     item = gnc_main_window_menu_find_menu_item (window, "HelpAboutAction");
     if (item)
@@ -4280,7 +4293,10 @@ gnc_quartz_set_menu (GncMainWindow* window)
     g_signal_connect (theApp, "NSApplicationBlockTermination",
                       G_CALLBACK(gnc_quartz_should_quit), window);
 
-    gtkosx_application_set_use_quartz_accelerators (theApp, TRUE);
+    g_signal_connect (priv->menubar, "can-activate-accel",
+                      G_CALLBACK (can_activate_cb), nullptr);
+
+    gtkosx_application_set_use_quartz_accelerators (theApp, FALSE);
     g_object_unref (theApp);
 }
 #endif //MAC_INTEGRATION



Summary of changes:
 gnucash/gnome-utils/gnc-main-window.cpp | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)



More information about the gnucash-changes mailing list