Skip to content

Commit

Permalink
[macOS] Better fix for menu accelerators.
Browse files Browse the repository at this point in the history
Connect to can-activate-accel and provide a closure for Quit
instead of using quartz handlers for accelerators.
  • Loading branch information
jralls committed Jan 21, 2023
1 parent 816219c commit d981679
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions gnucash/gnome-utils/gnc-main-window.cpp
Expand Up @@ -4233,14 +4233,21 @@ 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)
{
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);
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d981679

Please sign in to comment.