diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index cce6416b6d..56f2226d2f 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -1698,7 +1698,12 @@ gtk_main_do_event (GdkEvent *event) window = gtk_widget_get_toplevel (grab_widget); if (GTK_IS_WINDOW (window)) - gtk_window_set_mnemonics_visible (GTK_WINDOW (window), mnemonics_visible); + { + if (mnemonics_visible) + _gtk_window_set_auto_mnemonics_visible (GTK_WINDOW (window)); + else + gtk_window_set_mnemonics_visible (GTK_WINDOW (window), FALSE); + } } } /* else fall through */ diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 2cffb13b85..05aea213f7 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -98,6 +98,8 @@ * */ +#define AUTO_MNEMONICS_DELAY 300 /* ms */ + typedef struct _GtkDeviceGrabInfo GtkDeviceGrabInfo; struct _GtkWindowPrivate @@ -132,6 +134,8 @@ struct _GtkWindowPrivate guint16 configure_request_count; + guint auto_mnemonics_timeout_id; + /* The following flags are initially TRUE (before a window is mapped). * They cause us to compute a configure request that involves * default-only parameters. Once mapped, we set them to FALSE. @@ -4783,6 +4787,12 @@ gtk_window_finalize (GObject *object) g_free (priv->startup_id); + if (priv->auto_mnemonics_timeout_id) + { + g_source_remove (priv->auto_mnemonics_timeout_id); + priv->auto_mnemonics_timeout_id = 0; + } + #ifdef GDK_WINDOWING_X11 g_signal_handlers_disconnect_by_func (gtk_settings_get_default (), gtk_window_on_theme_variant_changed, @@ -9758,9 +9768,39 @@ gtk_window_set_mnemonics_visible (GtkWindow *window, g_object_notify (G_OBJECT (window), "mnemonics-visible"); } + if (priv->auto_mnemonics_timeout_id) + { + g_source_remove (priv->auto_mnemonics_timeout_id); + priv->auto_mnemonics_timeout_id = 0; + } + priv->mnemonics_visible_set = TRUE; } +static gboolean +set_auto_mnemonics_visible_cb (gpointer data) +{ + GtkWindow *window = data; + + gtk_window_set_mnemonics_visible (window, TRUE); + + window->priv->auto_mnemonics_timeout_id = 0; + + return FALSE; +} + +void +_gtk_window_set_auto_mnemonics_visible (GtkWindow *window) +{ + g_return_if_fail (GTK_IS_WINDOW (window)); + + if (window->priv->auto_mnemonics_timeout_id) + return; + + window->priv->auto_mnemonics_timeout_id = + gdk_threads_add_timeout (AUTO_MNEMONICS_DELAY, set_auto_mnemonics_visible_cb, window); +} + /** * gtk_window_get_focus_visible: * @window: a #GtkWindow diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h index 51f7f95e85..22f8d57705 100644 --- a/gtk/gtkwindowprivate.h +++ b/gtk/gtkwindowprivate.h @@ -84,6 +84,8 @@ gboolean _gtk_window_query_nonaccels (GtkWindow *window, guint accel_key, GdkModifierType accel_mods); +void _gtk_window_set_auto_mnemonics_visible (GtkWindow *window); + G_END_DECLS #endif /* __GTK_WINDOW_PRIVATE_H__ */