[gtk/gbsneto/shortcuts-rebased: 65/102] window: Put F10 accelerator into its own shortcut controller
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gbsneto/shortcuts-rebased: 65/102] window: Put F10 accelerator into its own shortcut controller
- Date: Tue, 14 May 2019 20:20:23 +0000 (UTC)
commit f5ce3d0a0d7c9433df453a3e2e2e4eb0a697ce3d
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 7be79cae0b..4101119cb3 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -64,6 +64,7 @@
#include "gtkseparatormenuitem.h"
#include "gtksettings.h"
#include "gtkshortcut.h"
+#include "gtkshortcutcontroller.h"
#include "gtkshortcuttrigger.h"
#include "gtksnapshot.h"
#include "gtkstylecontextprivate.h"
@@ -164,7 +165,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
@@ -491,6 +492,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
@@ -1815,7 +1819,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
@@ -1888,12 +1893,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 ();
g_signal_connect_swapped (priv->key_controller, "focus-in",
@@ -1902,6 +1907,15 @@ gtk_window_init (GtkWindow *window)
G_CALLBACK (gtk_window_focus_out), 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);
+
add_actions (window);
}
@@ -8560,65 +8574,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
@@ -8863,7 +8858,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]