8

Word on the street is that "gtk-enable-mnemonics" has been deprecated since version 3.10, and I am not at all sure how to get my application to display mnemonics.

They will only display if I press the alt key.

Please see here:

I have tried everything suggested in this article in regards to settings.ini, switching the bool to the opposite:

Related:

3

To "disable" mnemonics for Nautilus 3.10.1 on Ubuntu 14.04 which uses GTK3:

  1. Create the following path & file if it doesn't already exist.
    /home/YOURUSERNAME/.config/gtk-3.0/settings.ini
  2. Then add:
    [Settings]
    gtk-enable-mnemonics = 0
  3. Then logout and log back in.

Sources:

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.

  • 1
    I'm really confused by this answer since the question seems to be asking how to enable always showing mnemonics, but this answer talks about disabling them. – jamesdlin Jun 14 '17 at 4:15
  • Good point, I have no idea why I posted this as an answer then. – Elijah Lynn Jun 14 '17 at 16:19
3

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:

Looks like the GTK+ people had a feature-remove run at that time:

==========

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;
 }
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.