[gtk/default-handling: 13/25] popover: Add a default.activate action
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/default-handling: 13/25] popover: Add a default.activate action
- Date: Sun, 28 Apr 2019 23:31:06 +0000 (UTC)
commit 3ccdad76deea14e93c106ce1863e9dd33b9abce3
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Apr 28 17:07:05 2019 +0000
popover: Add a default.activate action
This is a first example of a widget intercepting
the default.activate for its own handling.
gtk/gtkpopover.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
---
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index c32aace6d9..65670f66b2 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -346,6 +346,40 @@ gesture_released (GtkGestureMultiPress *gesture,
gtk_popover_popdown (popover);
}
+static void
+activate_default_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer data)
+{
+ GtkPopover *popover = data;
+ GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
+ GtkWidget *focus_widget;
+
+ focus_widget = gtk_window_get_focus (GTK_WINDOW (gtk_widget_get_root (priv->widget)));
+ if (priv->default_widget && gtk_widget_is_sensitive (priv->default_widget) &&
+ (!focus_widget || !gtk_widget_get_receives_default (focus_widget)))
+ gtk_widget_activate (priv->default_widget);
+ else if (focus_widget && gtk_widget_is_sensitive (focus_widget))
+ gtk_widget_activate (focus_widget);
+}
+
+static void
+add_actions (GtkPopover *popover)
+{
+ 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),
+ popover);
+ gtk_widget_insert_action_group (GTK_WIDGET (popover), "default", actions);
+ g_object_unref (actions);
+}
+
static void
gtk_popover_init (GtkPopover *popover)
{
@@ -390,6 +424,8 @@ gtk_popover_init (GtkPopover *popover)
g_signal_connect (controller, "released",
G_CALLBACK (gesture_released), popover);
gtk_widget_add_controller (widget, controller);
+
+ add_actions (popover);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]