[gtk/default-handling: 12/25] window: Add a default.activate action



commit e464c08545ace0b43039ac4f196cd4eb254ce58d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Apr 27 03:12:54 2019 +0000

    window: Add a default.activate action
    
    Activating this action will replace other
    activate_default apis. It is more flexible,
    since intermediate widgets can intercept the
    action and do their own handling.

 gtk/gtkwindow.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index fd009aa832..d3f00f89a3 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -1773,6 +1773,31 @@ gtk_window_capture_motion (GtkWidget *widget,
   gtk_widget_set_cursor (widget, NULL);
 }
 
+static void
+activate_default_cb (GSimpleAction *action,
+                     GVariant      *parameter,
+                     gpointer       data)
+{
+  gtk_window_activate_default (GTK_WINDOW (data));
+}
+
+static void
+add_actions (GtkWindow *window)
+{
+  GActionEntry entries[] = {
+    { "activate", activate_default_cb, NULL, NULL, NULL },
+  };
+
+  GActionGroup *actions;
+
+  actions = G_ACTION_GROUP (g_simple_action_group_new ());
+  g_action_map_add_action_entries (G_ACTION_MAP (actions),
+                                   entries, G_N_ELEMENTS (entries),
+                                   window);
+  gtk_widget_insert_action_group (GTK_WIDGET (window), "default", actions);
+  g_object_unref (actions);
+}
+
 static void
 gtk_window_init (GtkWindow *window)
 {
@@ -1866,6 +1891,8 @@ gtk_window_init (GtkWindow *window)
   g_signal_connect_swapped (priv->key_controller, "focus-out",
                             G_CALLBACK (gtk_window_focus_out), window);
   gtk_widget_add_controller (widget, priv->key_controller);
+
+  add_actions (window);
 }
 
 static GtkGesture *


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