[gtk+/wip/test] gtkwindow: Use actions from focused widget to activate accel
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/test] gtkwindow: Use actions from focused widget to activate accel
- Date: Wed, 3 Dec 2014 10:27:55 +0000 (UTC)
commit 0a4d85cded14f7b46bc79c912dab40a594e69354
Author: Carlos Soriano <carlos sorian89 gmail com>
Date: Tue Dec 2 17:42:20 2014 +0100
gtkwindow: Use actions from focused widget to activate accel
Currently we only take into account the window GActionGroup for
activating the accels.
However, the application could have some custom GActionGroup in the
chain of focused widgets that could want to activate some action if
some accel is activated while that widget is focused.
To allow applications to set accels on widgets that use custom
GActionGroups, simply use the muxer of the focused widget, which
already contains the actions of the parents.
gtk/gtkactionhelper.c | 2 +-
gtk/gtkmenusectionbox.c | 2 +-
gtk/gtkmenushell.c | 2 +-
gtk/gtkwidget.c | 9 +++++----
gtk/gtkwidgetprivate.h | 3 ++-
gtk/gtkwindow.c | 22 +++++++++++++++++++++-
6 files changed, 31 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkactionhelper.c b/gtk/gtkactionhelper.c
index a9276d5..50060ee 100644
--- a/gtk/gtkactionhelper.c
+++ b/gtk/gtkactionhelper.c
@@ -397,7 +397,7 @@ gtk_action_helper_new (GtkActionable *widget)
g_object_get (G_OBJECT (helper->widget), "active", &helper->active, NULL);
}
- helper->action_context = _gtk_widget_get_action_muxer (GTK_WIDGET (widget));
+ helper->action_context = _gtk_widget_get_action_muxer (GTK_WIDGET (widget), TRUE);
return helper;
}
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 9905fa7..e6b9374 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -379,7 +379,7 @@ gtk_menu_section_box_new_toplevel (GtkStack *stack,
box = g_object_new (GTK_TYPE_MENU_SECTION_BOX, "margin", 10, NULL);
gtk_stack_add_named (stack, GTK_WIDGET (box), "main");
- box->tracker = gtk_menu_tracker_new (GTK_ACTION_OBSERVABLE (_gtk_widget_get_action_muxer (GTK_WIDGET
(box))),
+ box->tracker = gtk_menu_tracker_new (GTK_ACTION_OBSERVABLE (_gtk_widget_get_action_muxer (GTK_WIDGET
(box), TRUE)),
model, TRUE, FALSE, action_namespace,
gtk_menu_section_box_insert_func,
gtk_menu_section_box_remove_func, box);
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index d1d0c7f..939d5f4 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -2194,7 +2194,7 @@ gtk_menu_shell_bind_model (GtkMenuShell *menu_shell,
g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
g_return_if_fail (model == NULL || G_IS_MENU_MODEL (model));
- muxer = _gtk_widget_get_action_muxer (GTK_WIDGET (menu_shell));
+ muxer = _gtk_widget_get_action_muxer (GTK_WIDGET (menu_shell), TRUE);
g_clear_pointer (&menu_shell->priv->tracker, gtk_menu_tracker_free);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index af5f74c..5101fd0 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -16502,16 +16502,17 @@ _gtk_widget_update_parent_muxer (GtkWidget *widget)
else
parent = gtk_widget_get_parent (widget);
- parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
+ parent_muxer = parent ? _gtk_widget_get_action_muxer (parent, TRUE) : NULL;
}
gtk_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
}
GtkActionMuxer *
-_gtk_widget_get_action_muxer (GtkWidget *widget)
+_gtk_widget_get_action_muxer (GtkWidget *widget,
+ gboolean create_if_no_existent)
{
- if (widget->priv->muxer == NULL)
+ if (widget->priv->muxer == NULL && create_if_no_existent)
{
widget->priv->muxer = gtk_action_muxer_new ();
_gtk_widget_update_parent_muxer (widget);
@@ -16546,7 +16547,7 @@ gtk_widget_insert_action_group (GtkWidget *widget,
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (name != NULL);
- muxer = _gtk_widget_get_action_muxer (widget);
+ muxer = _gtk_widget_get_action_muxer (widget, TRUE);
if (group)
gtk_action_muxer_insert (muxer, name, group);
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 6eddbb4..2c46289 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -151,7 +151,8 @@ void _gtk_widget_invalidate_style_context (GtkWidget *widget
void _gtk_widget_style_context_invalidated (GtkWidget *widget);
void _gtk_widget_update_parent_muxer (GtkWidget *widget);
-GtkActionMuxer * _gtk_widget_get_action_muxer (GtkWidget *widget);
+GtkActionMuxer * _gtk_widget_get_action_muxer (GtkWidget *widget,
+ gboolean create_if_no_existent);
gchar ** _gtk_widget_list_action_prefixes (GtkWidget *widget);
GActionGroup * _gtk_widget_get_action_group (GtkWidget *widget,
const gchar *prefix);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 16f7e04..4a44a7a 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -481,6 +481,7 @@ static void get_shadow_width (GtkWidget *widget,
static GtkKeyHash *gtk_window_get_key_hash (GtkWindow *window);
static void gtk_window_free_key_hash (GtkWindow *window);
+static GtkActionMuxer* get_innermost_action_muxer (GtkWidget *origin);
static void gtk_window_on_composited_changed (GdkScreen *screen,
GtkWindow *window);
#ifdef GDK_WINDOWING_X11
@@ -11132,6 +11133,24 @@ gtk_window_free_key_hash (GtkWindow *window)
}
}
+static GtkActionMuxer*
+get_innermost_action_muxer (GtkWidget *origin)
+{
+ GtkActionMuxer *muxer;
+ GtkWidget *widget;
+
+ widget = origin;
+ muxer = _gtk_widget_get_action_muxer (widget, FALSE);
+
+ while (widget != NULL && muxer == NULL)
+ {
+ widget = gtk_widget_get_parent (widget);
+ muxer = _gtk_widget_get_action_muxer (widget, FALSE);
+ }
+
+ return muxer;
+}
+
/**
* gtk_window_activate_key:
* @window: a #GtkWindow
@@ -11214,7 +11233,8 @@ gtk_window_activate_key (GtkWindow *window,
if (window->priv->application)
{
- GtkActionMuxer *muxer = _gtk_widget_get_action_muxer (GTK_WIDGET (window));
+ GtkWidget *focused_widget = gtk_window_get_focus (window);
+ GtkActionMuxer *muxer = get_innermost_action_muxer (focused_widget);
return gtk_application_activate_accel (window->priv->application,
G_ACTION_GROUP (muxer),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]