如何在12.04和/或14.04 GTK3中启用助记符?


8

在大街上说的是,自3.10版以来,“ gtk-enable-mnemonics”已被弃用,我根本不确定如何使我的应用程序显示助记符。

仅当我按键时,它们才会显示alt

请在这里查看:

我已经尝试了本文中有关settings.ini的所有建议,将布尔值切换为相反的值:

有关:

Answers:


3

要在使用GTK3的Ubuntu 14.04上“禁用” Nautilus 3.10.1的助记符:

  1. 创建以下路径和文件(如果尚不存在)。
    /home/YOURUSERNAME/.config/gtk-3.0/settings.ini
  2. 然后加:
    [Settings]
    gtk-enable-mnemonics = 0
  3. 然后注销并重新登录。

资料来源:

ps请注意,GTK文档说您应该有一个名为的环境变量,XDG_CONFIG_HOME但我没有。我确实有一个现有~/.config/gtk-3.0文件夹,并且看起来默认情况下它在其中查找,而没有环境变量。


1
我真的对这个答案感到困惑,因为这个问题似乎在询问如何启用始终显示助记符的功能,但是此答案涉及禁用助记符的问题。
jamesdlin

好点,我不知道为什么要把这个作为答案发布。
伊利亚·林恩

4

在3.8版(从3.10版开始)之后,GTK + -3似乎丢失了“ gtk-auto-mnemonics”设置。

用于3.14.4的以下修补程序应重新启用“ gtk-auto-mnemonics”。它可能还将与其他GTK + -3版本(如3.16)一起使用。编译后,您只需要这些文件(前两个是符号链接):

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

您可以通过以下方式轻松开始使用编译后的内容(如有必要,请替换lib64lib):

LD_LIBRARY_PATH=/folder/where/you/installed/lib64 file-roller

--

不知道为什么,但是看起来GTK +开发人员在删除提供像这样有用的功能的代码方面真的很棒。

如果有任何GTK +开发人员阅读以下内容:这些代码行如何对任何人造成伤害或为什么将其删除?

如果有人对原始提交感兴趣:

看起来GTK +当时有功能删除功能:

==========

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

我想我改变了错误的主题。哎呀。

遵循步骤。

https://stackoverflow.com/a/24095212/2026508

更改自:gtk-auto-mnemonics = 0 <----禁用

更改为:gtk-auto-mnemonics = 1 <----已启用

在GTK3中,更改settings.ini: /usr/share/themes/CURRENT_THEME_NAME/gtk3.0/settings.ini

在GTK2中,更改gtkrc: /usr/share/themes/CURRENT_THEME_NAME/gtk2.0/gtkrc

但是请确保它是正确/当前的主题。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.