How to enable mnemonics in 12.04 and/or 14.04 GTK3?
Solution 1:
Looks like GTK+-3 lost the "gtk-auto-mnemonics" setting after version 3.8 (starting from version 3.10 on).
The following patch for 3.14.4 should re-enable "gtk-auto-mnemonics". It will probably also work with other GTK+-3 versions like 3.16. After compiling, you'll only need these files (first two are symlinks):
libgtk-3.so -> libgtk-3.so.0.1400.4
libgtk-3.so.0 -> libgtk-3.so.0.1400.4
libgtk-3.so.0.1400.4
http://ftp.gnome.org/pub/gnome/sources/gtk+/3.14/gtk+-3.14.4.tar.xz
You can easily start using the compiled stuff by this (replace lib64
with lib
if necessary):
LD_LIBRARY_PATH=/folder/where/you/installed/lib64 file-roller
-
Don't know why, but it looks like the GTK+ developers became really great in removing code which provided useful features like this...!!!
If any GTK+ developer reads this: How did those code-lines hurt anyone or why where they removed???
If someone's interested in the original commit:
- https://github.com/GNOME/gtk/commit/7e3a494fac62140f466fc43f6cc061215953e9b1
- https://github.com/GNOME/gtk/commit/7e3a494fac62140f466fc43f6cc061215953e9b1.patch
Looks like the GTK+ people had a feature-remove run at that time:
- https://github.com/GNOME/gtk/commit/425e977bb65a52c05fbc2b643acf32aec4bc477f
- https://github.com/GNOME/gtk/commit/7b66956e63f4cd85fc72bf51778596c9b1b83c28
==========
diff -ur gtk+-3.14.4.old/gtk/gtklabel.c gtk+-3.14.4.new/gtk/gtklabel.c
--- gtk+-3.14.4.old/gtk/gtklabel.c 2014-10-21 16:20:55.000000000 +0200
+++ gtk+-3.14.4.new/gtk/gtklabel.c 2015-05-06 23:01:45.447209817 +0200
@@ -2561,11 +2561,12 @@
if (with_uline)
{
- gboolean enable_mnemonics = TRUE;
- gboolean auto_mnemonics = TRUE;
+ gboolean enable_mnemonics;
+ gboolean auto_mnemonics;
g_object_get (gtk_widget_get_settings (GTK_WIDGET (label)),
"gtk-enable-mnemonics", &enable_mnemonics,
+ "gtk-auto-mnemonics", &auto_mnemonics,
NULL);
if (!(enable_mnemonics && priv->mnemonics_visible &&
@@ -2775,8 +2776,8 @@
{
GtkLabelPrivate *priv = label->priv;
PangoAttrList *attrs;
- gboolean enable_mnemonics = TRUE;
- gboolean auto_mnemonics = TRUE;
+ gboolean enable_mnemonics;
+ gboolean auto_mnemonics;
if (priv->pattern_set)
return;
@@ -2784,8 +2785,9 @@
if (is_mnemonic)
{
g_object_get (gtk_widget_get_settings (GTK_WIDGET (label)),
- "gtk-enable-mnemonics", &enable_mnemonics,
- NULL);
+ "gtk-enable-mnemonics", &enable_mnemonics,
+ "gtk-auto-mnemonics", &auto_mnemonics,
+ NULL);
if (enable_mnemonics && priv->mnemonics_visible && pattern &&
(!auto_mnemonics ||
diff -ur gtk+-3.14.4.old/gtk/gtkmain.c gtk+-3.14.4.new/gtk/gtkmain.c
--- gtk+-3.14.4.old/gtk/gtkmain.c 2014-10-21 16:20:55.000000000 +0200
+++ gtk+-3.14.4.new/gtk/gtkmain.c 2015-05-06 22:47:35.375311109 +0200
@@ -1717,18 +1717,26 @@
((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;
- GtkWidget *window;
+ gboolean auto_mnemonics;
- mnemonics_visible = (event->type == GDK_KEY_PRESS);
+ g_object_get (gtk_widget_get_settings (grab_widget),
+ "gtk-auto-mnemonics", &auto_mnemonics, NULL);
- window = gtk_widget_get_toplevel (grab_widget);
- if (GTK_IS_WINDOW (window))
+ if (auto_mnemonics)
{
- if (mnemonics_visible)
- _gtk_window_schedule_mnemonics_visible (GTK_WINDOW (window));
- else
- gtk_window_set_mnemonics_visible (GTK_WINDOW (window), FALSE);
+ gboolean mnemonics_visible;
+ GtkWidget *window;
+
+ mnemonics_visible = (event->type == GDK_KEY_PRESS);
+
+ window = gtk_widget_get_toplevel (grab_widget);
+ if (GTK_IS_WINDOW (window))
+ {
+ if (mnemonics_visible)
+ _gtk_window_schedule_mnemonics_visible (GTK_WINDOW (window));
+ else
+ gtk_window_set_mnemonics_visible (GTK_WINDOW (window), FALSE);
+ }
}
}
/* else fall through */
diff -ur gtk+-3.14.4.old/gtk/gtkmenushell.c gtk+-3.14.4.new/gtk/gtkmenushell.c
--- gtk+-3.14.4.old/gtk/gtkmenushell.c 2014-08-15 16:38:05.000000000 +0200
+++ gtk+-3.14.4.new/gtk/gtkmenushell.c 2015-05-06 22:53:03.442086931 +0200
@@ -898,9 +898,17 @@
_gtk_menu_shell_update_mnemonics (GtkMenuShell *menu_shell)
{
GtkMenuShell *target;
+ gboolean auto_mnemonics;
gboolean found;
gboolean mnemonics_visible;
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
+ "gtk-auto-mnemonics", &auto_mnemonics,
+ NULL);
+
+ if (!auto_mnemonics)
+ return;
+
target = menu_shell;
found = FALSE;
while (target)
diff -ur gtk+-3.14.4.old/gtk/gtkwindow.c gtk+-3.14.4.new/gtk/gtkwindow.c
--- gtk+-3.14.4.old/gtk/gtkwindow.c 2014-10-21 16:20:55.000000000 +0200
+++ gtk+-3.14.4.new/gtk/gtkwindow.c 2015-05-06 22:59:47.780956630 +0200
@@ -5878,6 +5878,8 @@
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = window->priv;
GdkWindow *gdk_window;
+ gboolean auto_mnemonics;
+ GtkPolicyType visible_focus;
GList *link;
if (!gtk_widget_is_toplevel (widget))
@@ -5966,10 +5968,15 @@
}
}
- /* if mnemonics visible is not already set
+ /* if auto-mnemonics is enabled and mnemonics visible is not already set
* (as in the case of popup menus), then hide mnemonics initially
*/
- if (!priv->mnemonics_visible_set)
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-auto-mnemonics", &auto_mnemonics,
+ "gtk-visible-focus", &visible_focus,
+ NULL);
+
+ if (auto_mnemonics && !priv->mnemonics_visible_set)
gtk_window_set_mnemonics_visible (window, FALSE);
/* inherit from transient parent, so that a dialog that is
@@ -7834,6 +7841,7 @@
GdkEventFocus *event)
{
GtkWindow *window = GTK_WINDOW (widget);
+ gboolean auto_mnemonics;
/* It appears spurious focus in events can occur when
* the window is hidden. So we'll just check to see if
@@ -7845,7 +7853,9 @@
_gtk_window_set_has_toplevel_focus (window, TRUE);
_gtk_window_set_is_active (window, TRUE);
- if (gtk_window_has_mnemonic_modifier_pressed (window))
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-auto-mnemonics", &auto_mnemonics, NULL);
+ if (auto_mnemonics && gtk_window_has_mnemonic_modifier_pressed (window))
_gtk_window_schedule_mnemonics_visible (window);
}
@@ -7857,12 +7867,16 @@
GdkEventFocus *event)
{
GtkWindow *window = GTK_WINDOW (widget);
+ gboolean auto_mnemonics;
_gtk_window_set_has_toplevel_focus (window, FALSE);
_gtk_window_set_is_active (window, FALSE);
/* set the mnemonic-visible property to false */
- gtk_window_set_mnemonics_visible (window, FALSE);
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-auto-mnemonics", &auto_mnemonics, NULL);
+ if (auto_mnemonics)
+ gtk_window_set_mnemonics_visible (window, FALSE);
return FALSE;
}
Solution 2:
To "disable" mnemonics for Nautilus 3.10.1 on Ubuntu 14.04 which uses GTK3:
- Create the following path & file if it doesn't already exist.
/home/YOURUSERNAME/.config/gtk-3.0/settings.ini
- Then add:
[Settings]
gtk-enable-mnemonics = 0
- Then logout and log back in.
Sources:
- Is there an equivalent to .gtkrc-2.0 in gtk 3? | GNOME Mail Services
- Settings: GTK+ 3 Reference Manual | GNOME Developer Center
p.s. Note that the GTK docs say you should have an environment variable called XDG_CONFIG_HOME
but I didn't have one. I did have an existing ~/.config/gtk-3.0
folder and it appears it is looking there by default, without the environment variable.
Solution 3:
I think I was changing the wrong theme. Oops.
Steps followed.
https://stackoverflow.com/a/24095212/2026508
Change from: gtk-auto-mnemonics = 0
<---- Disabled
Change to: gtk-auto-mnemonics = 1
<---- Enabled
In GTK3 change in settings.ini:
/usr/share/themes/CURRENT_THEME_NAME/gtk3.0/settings.ini
In GTK2 change in gtkrc:
/usr/share/themes/CURRENT_THEME_NAME/gtk2.0/gtkrc
But make sure it is the correct/current theme.