[gtk/default-handling: 6/18] popover: Add a gtk.activate-default action
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/default-handling: 6/18] popover: Add a gtk.activate-default action
- Date: Sun, 28 Apr 2019 19:32:19 +0000 (UTC)
commit 6c34be3761aee6ad949a9c19e61806bb2bf93a4a
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Apr 28 17:07:05 2019 +0000
popover: Add a gtk.activate-default action
This is a first example of a widget intercepting
the gtk.activate-default 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..832e5e32d0 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-default", 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), "gtk", 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]