[gtk/shortcuts-rebased-again: 159/171] Replace move-focus signal by focus.move action
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/shortcuts-rebased-again: 159/171] Replace move-focus signal by focus.move action
- Date: Mon, 24 Jun 2019 23:17:51 +0000 (UTC)
commit 532a1c6d0d9e8023a324c2018dca5f81c8668444
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jun 23 22:59:08 2019 +0000
Replace move-focus signal by focus.move action
gtk/gtknotebook.c | 3 ++-
gtk/gtkpopover.c | 8 ------
gtk/gtkpopovermenu.c | 24 +++++++----------
gtk/gtkscrolledwindow.c | 7 ++---
gtk/gtktextview.c | 45 ++++++++++++++++---------------
gtk/gtktoolbar.c | 53 +++++++++++++++++++------------------
gtk/gtkwindow.c | 57 +++++++++++++++++++++++++++-------------
testsuite/gtk/test-focus-chain.c | 2 +-
8 files changed, 105 insertions(+), 94 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 0fb75973dd..dcdf008fbe 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -1632,7 +1632,8 @@ gtk_notebook_move_focus_out (GtkNotebook *notebook,
g_object_ref (notebook);
priv->focus_out = TRUE;
- g_signal_emit_by_name (toplevel, "move-focus", direction_type);
+ gtk_widget_activate_action (GTK_WIDGET (notebook), "focus.move",
+ "i", direction_type);
priv->focus_out = FALSE;
g_object_unref (notebook);
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index f2d252c8af..106d0a8c2a 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -609,13 +609,6 @@ gtk_popover_unrealize (GtkWidget *widget)
g_clear_object (&priv->surface);
}
-static void
-gtk_popover_move_focus (GtkWidget *widget,
- GtkDirectionType direction)
-{
- g_signal_emit_by_name (gtk_widget_get_root (widget), "move-focus", direction);
-}
-
static void
gtk_popover_show (GtkWidget *widget)
{
@@ -1299,7 +1292,6 @@ gtk_popover_class_init (GtkPopoverClass *klass)
widget_class->measure = gtk_popover_measure;
widget_class->size_allocate = gtk_popover_size_allocate;
widget_class->snapshot = gtk_popover_snapshot;
- widget_class->move_focus = gtk_popover_move_focus;
container_class->add = gtk_popover_add;
container_class->remove = gtk_popover_remove;
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 29cbccd1cb..ec542ee81e 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -379,8 +379,8 @@ add_tab_bindings (GtkWidgetClass *widget_class,
shortcut = gtk_shortcut_new_with_arguments (
gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_Tab, modifiers),
gtk_keyval_trigger_new (GDK_KEY_KP_Tab, modifiers)),
- gtk_signal_action_new ("move-focus"),
- "(i)", direction);
+ gtk_action_action_new ("focus.move"),
+ "i", direction);
g_object_unref (shortcut);
}
@@ -392,21 +392,17 @@ add_arrow_bindings (GtkWidgetClass *widget_class,
{
guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
- gtk_widget_class_add_binding_signal (widget_class, keysym, 0,
- "move-focus",
- "(i)",
+ gtk_widget_class_bind_action (widget_class, keysym, 0,
+ "focus.move", "i",
direction);
- gtk_widget_class_add_binding_signal (widget_class, keysym, GDK_CONTROL_MASK,
- "move-focus",
- "(i)",
+ gtk_widget_class_bind_action (widget_class, keysym, GDK_CONTROL_MASK,
+ "focus.move", "i",
direction);
- gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, 0,
- "move-focus",
- "(i)",
+ gtk_widget_class_bind_action (widget_class, keypad_keysym, 0,
+ "focus.move", "i",
direction);
- gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, GDK_CONTROL_MASK,
- "move-focus",
- "(i)",
+ gtk_widget_class_bind_action (widget_class, keypad_keysym, GDK_CONTROL_MASK,
+ "focus.move", "i",
direction);
}
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index c2545a405c..d0f07794d3 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -2920,19 +2920,16 @@ gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
GtkDirectionType direction_type)
{
GtkScrolledWindowPrivate *priv = gtk_scrolled_window_get_instance_private (scrolled_window);
- GtkWidget *toplevel;
/* Focus out of the scrolled window entirely. We do this by setting
* a flag, then propagating the focus motion to the notebook.
*/
- toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (scrolled_window)));
- if (!GTK_IS_ROOT (toplevel))
- return;
g_object_ref (scrolled_window);
priv->focus_out = TRUE;
- g_signal_emit_by_name (toplevel, "move-focus", direction_type);
+ gtk_widget_activate_action (GTK_WIDGET (scrolled_window),
+ "focus.move", "i", direction_type);
priv->focus_out = FALSE;
g_object_unref (scrolled_window);
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 2e7be3cf9d..6b73a13681 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -1610,23 +1610,23 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
NULL);
/* Control-tab focus motion */
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_Tab, GDK_CONTROL_MASK,
- "move-focus",
- "(i)", GTK_DIR_TAB_FORWARD);
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_KP_Tab, GDK_CONTROL_MASK,
- "move-focus",
- "(i)", GTK_DIR_TAB_FORWARD);
+ gtk_widget_class_bind_action (widget_class,
+ GDK_KEY_Tab, GDK_CONTROL_MASK,
+ "focus.move", "i",
+ GTK_DIR_TAB_FORWARD);
+ gtk_widget_class_bind_action (widget_class,
+ GDK_KEY_KP_Tab, GDK_CONTROL_MASK,
+ "focus.move", "i",
+ GTK_DIR_TAB_FORWARD);
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
- "move-focus",
- "(i)", GTK_DIR_TAB_BACKWARD);
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
- "move-focus",
- "(i)", GTK_DIR_TAB_BACKWARD);
+ gtk_widget_class_bind_action (widget_class,
+ GDK_KEY_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
+ "focus.move", "i",
+ GTK_DIR_TAB_BACKWARD);
+ gtk_widget_class_bind_action (widget_class,
+ GDK_KEY_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
+ "focus.move", "i",
+ GTK_DIR_TAB_BACKWARD);
/* Context menu */
gtk_widget_class_add_binding (widget_class,
@@ -5052,9 +5052,10 @@ gtk_text_view_key_controller_key_pressed (GtkEventControllerKey *controller,
gtk_text_view_commit_text (text_view, "\t");
}
else
- g_signal_emit_by_name (text_view, "move-focus",
- (state & GDK_SHIFT_MASK) ?
- GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD);
+ gtk_widget_activate_action (GTK_WIDGET (text_view), "focus.move",
+ "i", (state & GDK_SHIFT_MASK)
+ ? GTK_DIR_TAB_BACKWARD
+ : GTK_DIR_TAB_FORWARD);
retval = TRUE;
}
@@ -5956,7 +5957,8 @@ gtk_text_view_move_cursor (GtkTextView *text_view,
!gtk_widget_keynav_failed (GTK_WIDGET (text_view),
leave_direction))
{
- g_signal_emit_by_name (text_view, "move-focus", leave_direction);
+ gtk_widget_activate_action (GTK_WIDGET (text_view), "focus.move",
+ "i", leave_direction);
}
return;
@@ -6141,7 +6143,8 @@ gtk_text_view_move_cursor (GtkTextView *text_view,
if (!gtk_widget_keynav_failed (GTK_WIDGET (text_view),
leave_direction))
{
- g_signal_emit_by_name (text_view, "move-focus", leave_direction);
+ gtk_widget_activate_action (GTK_WIDGET (text_view), "focus.move",
+ "i", leave_direction);
}
}
else if (! cancel_selection)
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 6170d44a98..bc1a020cfb 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -206,8 +206,6 @@ static void gtk_toolbar_size_allocate (GtkWidget *widget,
static void gtk_toolbar_style_updated (GtkWidget *widget);
static gboolean gtk_toolbar_focus (GtkWidget *widget,
GtkDirectionType dir);
-static void gtk_toolbar_move_focus (GtkWidget *widget,
- GtkDirectionType dir);
static void gtk_toolbar_root (GtkWidget *widget);
static void gtk_toolbar_unroot (GtkWidget *widget);
static void gtk_toolbar_finalize (GObject *object);
@@ -312,6 +310,9 @@ static void toolbar_tool_shell_iface_init (GtkToolShellIface
static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
static void toolbar_rebuild_menu (GtkToolShell *shell);
+static void gtk_toolbar_activate_focus_move (GtkWidget *widget,
+ const char *action_name,
+ GVariant *parameter);
G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
@@ -327,18 +328,16 @@ static guint toolbar_signals[LAST_SIGNAL] = { 0 };
static void
add_arrow_bindings (GtkWidgetClass *widget_class,
guint keysym,
- GtkDirectionType dir)
+ GtkDirectionType direction)
{
guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
- gtk_widget_class_add_binding_signal (widget_class,
- keysym, 0,
- "move-focus",
- "(i)", dir);
- gtk_widget_class_add_binding_signal (widget_class,
- keypad_keysym, 0,
- "move-focus",
- "(i)", dir);
+ gtk_widget_class_bind_action (widget_class,
+ keysym, 0,
+ "focus.move", "i", direction);
+ gtk_widget_class_bind_action (widget_class,
+ keypad_keysym, 0,
+ "focus.move", "i", direction);
}
static void
@@ -346,14 +345,12 @@ add_ctrl_tab_bindings (GtkWidgetClass *widget_class,
GdkModifierType modifiers,
GtkDirectionType direction)
{
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_Tab, GDK_CONTROL_MASK | modifiers,
- "move-focus",
- "(i)", direction);
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_KP_Tab, GDK_CONTROL_MASK | modifiers,
- "move-focus",
- "(i)", direction);
+ gtk_widget_class_bind_action (widget_class,
+ GDK_KEY_Tab, GDK_CONTROL_MASK | modifiers,
+ "focus.move", "i", direction);
+ gtk_widget_class_bind_action (widget_class,
+ GDK_KEY_KP_Tab, GDK_CONTROL_MASK | modifiers,
+ "focus.move", "i", direction);
}
static void
@@ -380,12 +377,14 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_TOOL_BAR);
- /* need to override the base class function via override_class_handler,
- * because the signal slot is not available in GtkWidgetClass
+ /**
+ * GtkToolbar|focus.move:
+ * @direction: a #GtkDirectionType indicating the direction to move fous in
+ *
+ * The focus.move action moves the focus in the given direction.
*/
- g_signal_override_class_handler ("move-focus",
- GTK_TYPE_TOOLBAR,
- G_CALLBACK (gtk_toolbar_move_focus));
+ gtk_widget_class_install_action (widget_class, "focus.move", "i",
+ gtk_toolbar_activate_focus_move);
widget_class->root = gtk_toolbar_root;
widget_class->unroot = gtk_toolbar_unroot;
@@ -1579,10 +1578,12 @@ gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
* Ctrl TAB or an arrow key.
*/
static void
-gtk_toolbar_move_focus (GtkWidget *widget,
- GtkDirectionType dir)
+gtk_toolbar_activate_focus_move (GtkWidget *widget,
+ const char *action_name,
+ GVariant *parameter)
{
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
+ GtkDirectionType dir = g_variant_get_int32 (parameter);
GtkWidget *focus_child;
GList *list;
gboolean try_focus = FALSE;
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 2dcb43ece6..da300cddcc 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -507,6 +507,9 @@ static void gtk_window_activate_default_activate (GtkWidget *widget,
static void gtk_window_activate_focus_activate (GtkWidget *widget,
const char *action_name,
GVariant *parameter);
+static void gtk_window_activate_focus_move (GtkWidget *widget,
+ const char *action_name,
+ GVariant *parameter);
static void gtk_window_do_popup (GtkWindow *window,
GdkEventButton *event);
@@ -594,8 +597,8 @@ add_tab_bindings (GtkWidgetClass *widget_class,
shortcut = gtk_shortcut_new_with_arguments (
gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_Tab, modifiers),
gtk_keyval_trigger_new (GDK_KEY_KP_Tab, modifiers)),
- gtk_signal_action_new ("move-focus"),
- "(i)", direction);
+ gtk_action_action_new ("focus.move"),
+ "i", direction);
gtk_widget_class_add_shortcut (widget_class, shortcut);
@@ -609,22 +612,18 @@ add_arrow_bindings (GtkWidgetClass *widget_class,
{
guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
- gtk_widget_class_add_binding_signal (widget_class, keysym, 0,
- "move-focus",
- "(i)",
- direction);
- gtk_widget_class_add_binding_signal (widget_class, keysym, GDK_CONTROL_MASK,
- "move-focus",
- "(i)",
- direction);
- gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, 0,
- "move-focus",
- "(i)",
- direction);
- gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, GDK_CONTROL_MASK,
- "move-focus",
- "(i)",
- direction);
+ gtk_widget_class_bind_action (widget_class, keysym, 0,
+ "focus.move", "i",
+ direction);
+ gtk_widget_class_bind_action (widget_class, keysym, GDK_CONTROL_MASK,
+ "focus.move", "i",
+ direction);
+ gtk_widget_class_bind_action (widget_class, keypad_keysym, 0,
+ "focus.move", "i",
+ direction);
+ gtk_widget_class_bind_action (widget_class, keypad_keysym, GDK_CONTROL_MASK,
+ "focus.move", "i",
+ direction);
}
static guint32
@@ -1134,6 +1133,16 @@ gtk_window_class_init (GtkWindowClass *klass)
gtk_widget_class_install_action (widget_class, "focus.activate", NULL,
gtk_window_activate_focus_activate);
+
+ /**
+ * GtkWindow|focus.move:
+ * @direction: a #GtkDirectionType indicating the direction to move fous in
+ *
+ * The focus.move action moves the focus in the given direction.
+ */
+ gtk_widget_class_install_action (widget_class, "focus.move", "i",
+ gtk_window_activate_focus_move);
+
/**
* GtkWindow|debugging.enable:
* @toggle: whether to toggle or enable
@@ -6029,6 +6038,18 @@ gtk_window_move_focus (GtkWidget *widget,
gtk_window_set_focus (GTK_WINDOW (widget), NULL);
}
+static void
+gtk_window_activate_focus_move (GtkWidget *widget,
+ const char *action_name,
+ GVariant *parameter)
+{
+ GtkDirectionType dir;
+
+ dir = g_variant_get_int32 (parameter);
+ dir = CLAMP (dir, GTK_DIR_TAB_FORWARD, GTK_DIR_RIGHT);
+ gtk_window_move_focus (widget, dir);
+}
+
/**
* gtk_window_set_focus:
* @window: a #GtkWindow
diff --git a/testsuite/gtk/test-focus-chain.c b/testsuite/gtk/test-focus-chain.c
index a76082feca..62cf0b407b 100644
--- a/testsuite/gtk/test-focus-chain.c
+++ b/testsuite/gtk/test-focus-chain.c
@@ -104,7 +104,7 @@ generate_focus_chain (GtkWidget *window,
while (TRUE)
{
- g_signal_emit_by_name (window, "move-focus", dir);
+ gtk_widget_activate_action (window, "focus.move", "i", dir);
focus = gtk_window_get_focus (GTK_WINDOW (window));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]