mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-06 19:00:12 +00:00
main: Move visible mnemonics handling
No need to special-case this anymore; we can use a regular event controller in GtkWindow for this.
This commit is contained in:
parent
a7cdcdf92c
commit
6a4a082660
@ -1998,30 +1998,6 @@ gtk_main_do_event (GdkEvent *event)
|
|||||||
|
|
||||||
case GDK_KEY_PRESS:
|
case GDK_KEY_PRESS:
|
||||||
case GDK_KEY_RELEASE:
|
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_SCROLL:
|
||||||
case GDK_BUTTON_PRESS:
|
case GDK_BUTTON_PRESS:
|
||||||
case GDK_TOUCH_BEGIN:
|
case GDK_TOUCH_BEGIN:
|
||||||
|
@ -406,7 +406,16 @@ static void gtk_window_size_allocate (GtkWidget *widget,
|
|||||||
static gboolean gtk_window_close_request (GtkWindow *window);
|
static gboolean gtk_window_close_request (GtkWindow *window);
|
||||||
static void gtk_window_focus_in (GtkWidget *widget);
|
static void gtk_window_focus_in (GtkWidget *widget);
|
||||||
static void gtk_window_focus_out (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_state_changed (GtkWidget *widget);
|
||||||
static void surface_size_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_CALLBACK (gtk_window_focus_out), window);
|
||||||
g_signal_connect_swapped (priv->key_controller, "key-pressed",
|
g_signal_connect_swapped (priv->key_controller, "key-pressed",
|
||||||
G_CALLBACK (gtk_window_key_press), window);
|
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);
|
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);
|
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
|
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);
|
GtkWindow *window = GTK_WINDOW (widget);
|
||||||
|
|
||||||
gtk_window_set_focus_visible (window, TRUE);
|
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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user