Commit ed7a417d authored by Rui Matos's avatar Rui Matos Committed by Matthias Clasen

window: Add a delay before automatically showing mnemonics

Showing mnemonics immediately on modifier press can be annoying and
distracting when the user is just trying to Alt+Tab into another
application/window since the mnemonic will show up and quickly vanish
again when we receive the focus out event.

https://bugzilla.gnome.org/show_bug.cgi?id=672431
parent adcd3a03
......@@ -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 */
......
......@@ -98,6 +98,8 @@
* </refsect2>
*/
#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
......
......@@ -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__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment