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

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

有传言称“gtk-enable-mnemonics”自 3.10 版以来就已被弃用,而且我完全不确定如何让我的应用程序显示助记符。

只有当我按下键时它们才会显示alt

请参阅此处:

我已经尝试了本文中有关 settings.ini 的所有建议,将 bool 切换到相反的选项:

有关的:

答案1

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

以下针对 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

您可以轻松地通过以下方式开始使用已编译的内容(如果需要,请替换lib64为):lib

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

答案2

要在使用 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文件夹,它似乎默认在那里查找,没有环境变量。

答案3

我觉得我改错了主题。哎呀。

随后采取以下步骤。

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

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

相关内容