[gtk/shortcuts-rebased-again: 78/171] menu: Implement GtkShortcutManager



commit 500bee4a25065aaecf03c9dc2e285dbc3e67ffe3
Author: Benjamin Otte <otte redhat com>
Date:   Thu Aug 16 07:30:52 2018 +0200

    menu: Implement GtkShortcutManager
    
    And make sure to activate mnemonics without Alt

 gtk/gtkmenu.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index cc865fcb61..924ec56a1b 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -104,6 +104,7 @@
 #include "gtkprivate.h"
 #include "gtkscrollbar.h"
 #include "gtksettings.h"
+#include "gtkshortcutmanager.h"
 #include "gtksnapshot.h"
 #include "gtkstylecontextprivate.h"
 #include "gtktypebuiltins.h"
@@ -238,7 +239,15 @@ static const gchar attach_data_key[] = "gtk-menu-attach-data";
 
 static guint menu_signals[LAST_SIGNAL] = { 0 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkMenu, gtk_menu, GTK_TYPE_MENU_SHELL)
+static void
+gtk_menu_shortcut_manager_interface_init (GtkShortcutManagerInterface *iface)
+{
+}
+
+G_DEFINE_TYPE_WITH_CODE (GtkMenu, gtk_menu, GTK_TYPE_MENU_SHELL,
+                         G_ADD_PRIVATE (GtkMenu)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_SHORTCUT_MANAGER,
+                                                gtk_menu_shortcut_manager_interface_init))
 
 static void
 update_scrollbars (GtkMenu *menu)
@@ -782,6 +791,7 @@ gtk_menu_init (GtkMenu *menu)
   GtkMenuPrivate *priv;
   GtkGesture *gesture;
   GtkEventController *controller;
+  GList *l, *controllers;
 
   priv = gtk_menu_get_instance_private (menu);
 
@@ -792,7 +802,6 @@ gtk_menu_init (GtkMenu *menu)
   g_signal_connect (priv->toplevel, "destroy", G_CALLBACK (gtk_widget_destroyed), &priv->toplevel);
 
   gtk_window_set_resizable (GTK_WINDOW (priv->toplevel), FALSE);
-  gtk_window_set_mnemonic_modifier (GTK_WINDOW (priv->toplevel), 0);
 
   _gtk_window_request_csd (GTK_WINDOW (priv->toplevel));
   gtk_style_context_add_class (gtk_widget_get_style_context (priv->toplevel),
@@ -835,6 +844,15 @@ gtk_menu_init (GtkMenu *menu)
   controller = gtk_event_controller_motion_new ();
   g_signal_connect (controller, "motion", G_CALLBACK (gtk_menu_motion), menu);
   gtk_widget_add_controller (GTK_WIDGET (menu), controller);
+
+  /* Trigger mnemonics without Alt */
+  controllers = _gtk_widget_list_controllers (GTK_WIDGET (menu), GTK_PHASE_CAPTURE);
+  for (l = controllers; l; l = l->next)
+    {
+      if (GTK_IS_SHORTCUT_CONTROLLER (l->data))
+        gtk_shortcut_controller_set_mnemonics_modifiers (l->data, 0);
+    }
+  g_list_free (controllers);
 }
 
 static void


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