[gtk] main: Move visible mnemonics handling
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] main: Move visible mnemonics handling
- Date: Fri, 21 Jun 2019 02:46:58 +0000 (UTC)
commit 6a4a082660e3626f9daf7ea826a4189f31f96507
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jun 21 02:22:26 2019 +0000
main: Move visible mnemonics handling
No need to special-case this anymore; we can use
a regular event controller in GtkWindow for this.
gtk/gtkmain.c | 24 ------------------------
gtk/gtkwindow.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 49 insertions(+), 26 deletions(-)
---
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 9eac06ffde..35ea753e1f 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -1998,30 +1998,6 @@ gtk_main_do_event (GdkEvent *event)
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE:
- /* Catch alt press to enable auto-mnemonics;
- * menus are handled elsewhere
- * FIXME: this does not work with mnemonic modifiers other than Alt
- */
- if ((event->key.keyval == GDK_KEY_Alt_L || event->key.keyval == GDK_KEY_Alt_R) &&
- ((event->key.state & (gtk_accelerator_get_default_mod_mask ()) &
~(GDK_RELEASE_MASK|GDK_MOD1_MASK)) == 0) &&
- !GTK_IS_MENU_SHELL (grab_widget))
- {
- gboolean mnemonics_visible;
- GtkRoot *root;
-
- mnemonics_visible = (event->any.type == GDK_KEY_PRESS);
-
- root = gtk_widget_get_root (grab_widget);
- if (GTK_IS_WINDOW (root))
- {
- if (mnemonics_visible)
- _gtk_window_schedule_mnemonics_visible (GTK_WINDOW (root));
- else
- gtk_window_set_mnemonics_visible (GTK_WINDOW (root), FALSE);
- }
- }
- G_GNUC_FALLTHROUGH;
-
case GDK_SCROLL:
case GDK_BUTTON_PRESS:
case GDK_TOUCH_BEGIN:
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 3b4b8b7bbe..4a470e1aa3 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -406,7 +406,16 @@ static void gtk_window_size_allocate (GtkWidget *widget,
static gboolean gtk_window_close_request (GtkWindow *window);
static void gtk_window_focus_in (GtkWidget *widget);
static void gtk_window_focus_out (GtkWidget *widget);
-static gboolean gtk_window_key_press (GtkWidget *widget);
+static gboolean gtk_window_key_press (GtkWidget *widget,
+ guint keyval,
+ guint keycode,
+ GdkModifierType state,
+ gpointer data);
+static gboolean gtk_window_key_released (GtkWidget *widget,
+ guint keyval,
+ guint keycode,
+ GdkModifierType state,
+ gpointer data);
static void surface_state_changed (GtkWidget *widget);
static void surface_size_changed (GtkWidget *widget,
@@ -1873,6 +1882,8 @@ gtk_window_init (GtkWindow *window)
G_CALLBACK (gtk_window_focus_out), window);
g_signal_connect_swapped (priv->key_controller, "key-pressed",
G_CALLBACK (gtk_window_key_press), 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);
}
@@ -6212,13 +6223,49 @@ gtk_window_focus_out (GtkWidget *widget)
gtk_window_set_mnemonics_visible (window, FALSE);
}
+static void
+update_mnemonics_visible (GtkWindow *window,
+ guint keyval,
+ GdkModifierType state,
+ gboolean visible)
+{
+ if ((keyval == GDK_KEY_Alt_L || keyval == GDK_KEY_Alt_R) &&
+ ((state & (gtk_accelerator_get_default_mod_mask ()) & ~(GDK_MOD1_MASK)) == 0))
+ {
+ if (visible)
+ _gtk_window_schedule_mnemonics_visible (window);
+ else
+ gtk_window_set_mnemonics_visible (window, FALSE);
+ }
+}
+
static gboolean
-gtk_window_key_press (GtkWidget *widget)
+gtk_window_key_press (GtkWidget *widget,
+ guint keyval,
+ guint keycode,
+ GdkModifierType state,
+ gpointer data)
{
GtkWindow *window = GTK_WINDOW (widget);
gtk_window_set_focus_visible (window, TRUE);
+ update_mnemonics_visible (window, keyval, state, TRUE);
+
+ return FALSE;
+}
+
+static gboolean
+gtk_window_key_released (GtkWidget *widget,
+ guint keyval,
+ guint keycode,
+ GdkModifierType state,
+ gpointer data)
+{
+ GtkWindow *window = GTK_WINDOW (widget);
+
+ update_mnemonics_visible (window, keyval, state, FALSE);
+
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]