[gtk/shortcuts-rebased-again: 61/117] window: Put F10 accelerator into its own shortcut controller
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/shortcuts-rebased-again: 61/117] window: Put F10 accelerator into its own shortcut controller
- Date: Fri, 21 Jun 2019 15:32:39 +0000 (UTC)
commit a7da6deb23ae1d7ac612e3043170e81a992be14f
Author: Benjamin Otte <otte redhat com>
Date: Wed Aug 15 06:43:31 2018 +0200
window: Put F10 accelerator into its own shortcut controller
So instead of relying on gtk_window_activate_key(), it's now using
proper infrastructure.
gtk/gtkwindow.c | 103 +++++++++++++++++++++++++++-----------------------------
1 file changed, 49 insertions(+), 54 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index c440876eb6..4090ae670e 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -65,6 +65,7 @@
#include "gtkseparatormenuitem.h"
#include "gtksettings.h"
#include "gtkshortcut.h"
+#include "gtkshortcutcontroller.h"
#include "gtkshortcuttrigger.h"
#include "gtksnapshot.h"
#include "gtkstylecontextprivate.h"
@@ -165,7 +166,7 @@
* widget that is added as a titlebar child.
*/
-#define MENU_BAR_ACCEL "F10"
+#define MENU_BAR_ACCEL GDK_KEY_F10
#define RESIZE_HANDLE_SIZE 20
#define MNEMONICS_DELAY 300 /* ms */
#define NO_CONTENT_CHILD_NAT 200
@@ -493,6 +494,9 @@ static void update_window_buttons (GtkWindow *window);
static void get_shadow_width (GtkWindow *window,
GtkBorder *shadow_width);
+static gboolean gtk_window_activate_menubar (GtkWidget *widget,
+ GVariant *args,
+ gpointer unused);
static GtkKeyHash *gtk_window_get_key_hash (GtkWindow *window);
static void gtk_window_free_key_hash (GtkWindow *window);
#ifdef GDK_WINDOWING_X11
@@ -1802,7 +1806,8 @@ gtk_window_init (GtkWindow *window)
GtkWidget *widget;
GtkCssNode *widget_node;
GdkSeat *seat;
- GtkEventController *motion_controller;
+ GtkEventController *controller;
+ GtkShortcut *shortcut;
#ifdef GDK_WINDOWING_X11
GdkContentFormats *targets;
#endif
@@ -1871,12 +1876,12 @@ gtk_window_init (GtkWindow *window)
g_signal_connect (seat, "device-removed",
G_CALLBACK (device_removed_cb), window);
- motion_controller = gtk_event_controller_motion_new ();
- gtk_event_controller_set_propagation_phase (motion_controller,
+ controller = gtk_event_controller_motion_new ();
+ gtk_event_controller_set_propagation_phase (controller,
GTK_PHASE_CAPTURE);
- g_signal_connect_swapped (motion_controller, "motion",
+ g_signal_connect_swapped (controller, "motion",
G_CALLBACK (gtk_window_capture_motion), window);
- gtk_widget_add_controller (widget, motion_controller);
+ gtk_widget_add_controller (widget, controller);
priv->key_controller = gtk_event_controller_key_new ();
gtk_event_controller_set_propagation_phase (priv->key_controller, GTK_PHASE_CAPTURE);
@@ -1889,6 +1894,15 @@ gtk_window_init (GtkWindow *window)
g_signal_connect_swapped (priv->key_controller, "key-released",
G_CALLBACK (gtk_window_key_released), window);
gtk_widget_add_controller (widget, priv->key_controller);
+
+ controller = gtk_shortcut_controller_new ();
+ gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
+
+ shortcut = gtk_shortcut_new ();
+ gtk_shortcut_set_trigger (shortcut, gtk_keyval_trigger_new (MENU_BAR_ACCEL, 0));
+ gtk_shortcut_set_callback (shortcut, gtk_window_activate_menubar, NULL, NULL);
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
+ gtk_widget_add_controller (widget, controller);
}
static GtkGesture *
@@ -8148,65 +8162,46 @@ _gtk_window_set_window_group (GtkWindow *window,
}
static gboolean
-gtk_window_activate_menubar (GtkWindow *window,
- GdkEventKey *event)
+gtk_window_activate_menubar (GtkWidget *widget,
+ GVariant *args,
+ gpointer unused)
{
+ GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
- guint keyval = 0;
- GdkModifierType mods = 0;
-
- gtk_accelerator_parse (MENU_BAR_ACCEL, &keyval, &mods);
-
- if (keyval == 0)
- {
- g_warning ("Failed to parse menu bar accelerator '%s'", MENU_BAR_ACCEL);
- return FALSE;
- }
-
- /* FIXME this is wrong, needs to be in the global accel resolution
- * thing, to properly consider i18n etc., but that probably requires
- * AccelGroup changes etc.
- */
- if (event->keyval == keyval &&
- ((event->state & gtk_accelerator_get_default_mod_mask ()) ==
- (mods & gtk_accelerator_get_default_mod_mask ())))
- {
- GList *tmp_menubars, *l;
- GPtrArray *menubars;
- GtkMenuShell *menu_shell;
- GtkWidget *focus;
- GtkWidget *first;
+ GList *tmp_menubars, *l;
+ GPtrArray *menubars;
+ GtkMenuShell *menu_shell;
+ GtkWidget *focus;
+ GtkWidget *first;
- focus = gtk_window_get_focus (window);
+ focus = gtk_window_get_focus (window);
- if (priv->title_box != NULL &&
- (focus == NULL || !gtk_widget_is_ancestor (focus, priv->title_box)) &&
- gtk_widget_child_focus (priv->title_box, GTK_DIR_TAB_FORWARD))
- return TRUE;
+ if (priv->title_box != NULL &&
+ (focus == NULL || !gtk_widget_is_ancestor (focus, priv->title_box)) &&
+ gtk_widget_child_focus (priv->title_box, GTK_DIR_TAB_FORWARD))
+ return TRUE;
- tmp_menubars = _gtk_menu_bar_get_viewable_menu_bars (window);
- if (tmp_menubars == NULL)
- return FALSE;
+ tmp_menubars = _gtk_menu_bar_get_viewable_menu_bars (window);
+ if (tmp_menubars == NULL)
+ return FALSE;
- menubars = g_ptr_array_sized_new (g_list_length (tmp_menubars));;
- for (l = tmp_menubars; l; l = l->next)
- g_ptr_array_add (menubars, l->data);
+ menubars = g_ptr_array_sized_new (g_list_length (tmp_menubars));;
+ for (l = tmp_menubars; l; l = l->next)
+ g_ptr_array_add (menubars, l->data);
- g_list_free (tmp_menubars);
+ g_list_free (tmp_menubars);
- gtk_widget_focus_sort (GTK_WIDGET (window), GTK_DIR_TAB_FORWARD, menubars);
+ gtk_widget_focus_sort (GTK_WIDGET (window), GTK_DIR_TAB_FORWARD, menubars);
- first = g_ptr_array_index (menubars, 0);
- menu_shell = GTK_MENU_SHELL (first);
+ first = g_ptr_array_index (menubars, 0);
+ menu_shell = GTK_MENU_SHELL (first);
- _gtk_menu_shell_set_keyboard_mode (menu_shell, TRUE);
- gtk_menu_shell_select_first (menu_shell, FALSE);
+ _gtk_menu_shell_set_keyboard_mode (menu_shell, TRUE);
+ gtk_menu_shell_select_first (menu_shell, FALSE);
- g_ptr_array_free (menubars, TRUE);
+ g_ptr_array_free (menubars, TRUE);
- return TRUE;
- }
- return FALSE;
+ return TRUE;
}
static void
@@ -8451,7 +8446,7 @@ gtk_window_activate_key (GtkWindow *window,
}
}
- return gtk_window_activate_menubar (window, event);
+ return FALSE;
}
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]