[gtk/wip/baedert/for-master] shortcutcontroller: Pass the muxer to update_accel()



commit 89e837393a36ebcfe05eb1715080363b7478e869
Author: Timm Bäder <mail baedert org>
Date:   Thu Nov 19 15:57:09 2020 +0100

    shortcutcontroller: Pass the muxer to update_accel()
    
    We only needed the widget to get its action muxer. And this way we don't
    have to call gtk_widget_get_action_muxer() dozens of times, just once in
    set_widget().

 gtk/gtkshortcutcontroller.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index 2e660ed031..0c7922f5ec 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -447,18 +447,20 @@ gtk_shortcut_controller_handle_event (GtkEventController *controller,
 }
 
 static void
-update_accel (GtkShortcut *shortcut,
-              GtkWidget   *widget,
-              gboolean     set)
+update_accel (GtkShortcut    *shortcut,
+              GtkActionMuxer *muxer,
+              gboolean        set)
 {
   GtkShortcutTrigger *trigger;
   GtkShortcutAction *action;
-  GtkActionMuxer *muxer;
   GVariant *target;
   const char *action_name;
   char *action_and_target;
   char *accel = NULL;
 
+  if (!muxer)
+    return;
+
   trigger = gtk_shortcut_get_trigger (shortcut);
   action = gtk_shortcut_get_action (shortcut);
 
@@ -466,10 +468,6 @@ update_accel (GtkShortcut *shortcut,
       !GTK_IS_KEYVAL_TRIGGER (trigger))
     return;
 
-  muxer = _gtk_widget_get_action_muxer (widget, set);
-  if (!muxer)
-    return;
-
   target = gtk_shortcut_get_arguments (shortcut);
   action_name = gtk_named_action_get_action_name (GTK_NAMED_ACTION (action));
   action_and_target = gtk_print_action_and_target (NULL, action_name, target);
@@ -487,15 +485,17 @@ gtk_shortcut_controller_set_widget (GtkEventController *controller,
 {
   GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
   GListModel *shortcuts = self->shortcuts;
+  GtkActionMuxer *muxer;
   guint i, p;
 
   GTK_EVENT_CONTROLLER_CLASS (gtk_shortcut_controller_parent_class)->set_widget (controller, widget);
 
+  muxer = _gtk_widget_get_action_muxer (widget, TRUE);
   for (i = 0, p = g_list_model_get_n_items (shortcuts); i < p; i++)
     {
       GtkShortcut *shortcut = g_list_model_get_item (shortcuts, i);
       if (GTK_IS_SHORTCUT (shortcut))
-        update_accel (shortcut, widget, TRUE);
+        update_accel (shortcut, muxer, TRUE);
       g_object_unref (shortcut);
     }
 
@@ -742,7 +742,11 @@ gtk_shortcut_controller_add_shortcut (GtkShortcutController *self,
 
   widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
   if (widget)
-    update_accel (shortcut, widget, TRUE);
+    {
+      GtkActionMuxer *muxer = _gtk_widget_get_action_muxer (widget, TRUE);
+
+      update_accel (shortcut, muxer, TRUE);
+    }
 
   g_list_store_append (G_LIST_STORE (self->shortcuts), shortcut);
   g_object_unref (shortcut);
@@ -773,7 +777,11 @@ gtk_shortcut_controller_remove_shortcut (GtkShortcutController  *self,
 
   widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
   if (widget)
-    update_accel (shortcut, widget, FALSE);
+    {
+      GtkActionMuxer *muxer = _gtk_widget_get_action_muxer (widget, FALSE);
+
+      update_accel (shortcut, muxer, FALSE);
+    }
 
   for (i = 0; i < g_list_model_get_n_items (self->shortcuts); i++)
     {


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