GTK+ 3 Emacs 菜单配置

GTK+ 3 Emacs 菜单配置

我不喜欢基于 GTK 的 emacs(屏幕截图 #1),仍然更喜欢传统的 emacs(屏幕截图 #2),它是我从 Ubuntu PPA 获得的。

根本的区别在于,传统的 emacs 看起来大部分都是基于文本的,除了菜单,它仍然是基于 GTK 的。这个菜单字体和大小就是我想要改变的。

基本上,我需要做与参考文献 #1 相同的事情:“例外是主菜单栏中弹出的 [下拉] 菜单中字体大小。例如,如果我启动 Emacs 并在主菜单栏中左键单击“文件”,则会弹出文件功能(打开文件、打开目录等)的弹出菜单。但是,此菜单中的字体大小非常小,难以阅读。Faces 自定义组中的任何选项似乎都无法影响它。”

我从参考文献 #1 中了解到“菜单字体由 GTK 控制,不在 emacs 中”。但是按照参考文献 #2,我得到了相同的结果。也就是说,无论我如何根据消息中给出的参考调整 ~/.emacs.d/gtkrc,都不会对 Emacs 菜单产生影响。

然后我从参考文献 #3 中发现,我正在做的是调整 GTK+ 版本 2 的 Emacs 特定的 GTK+ 资源,而我的 Emacs,来自 Ubuntu PPA 的 Emacs 24,正在使用 GTK+ 版本 3。

好的,现在我的问题来了,如何配置 GTK+ 3 菜单字体和大小?我到处搜索,但也许 GTK+ 3 配置太新(或太复杂),以至于没有人写博客/谈论它。

谁能给我一个如何配置 GTK+ 3 菜单字体和大小的实际示例?

谢谢

参考文献 #1:http://forums.gentoo.org/viewtopic-t-516665-view-next.html?sid=b8448a7a0c04d2f6d6c80cbd43bfd931

参考文献 #2:http://lists.debian.org/debian-user/2013/05/msg00169.html

参考文献 #3:http://www.gnu.org/software/emacs/manual/html_node/emacs/GTK-resources.html#GTK-resources

截图#1:

截图#1: 截图#2:

截图#2:

答案1

假设:在您的主目录中,您有一个子目录.themes。在此子目录中,假设您已从中递归复制了一个主题/usr/share/themes,以供阅读和自定义。我们将该主题(或更确切地说是其目录)称为~/.themes/mytheme。(注意:请密切关注文件的内容,并在必要时进行修改~/.themes/mytheme/index.theme)。

在该目录中,~/.themes/mytheme您还有另一个子目录~/.themes/mytheme/gtk-3.0。其中有一个名为的文件gtk.css。此文件可能很大,也可能很小。在后一种情况下,它通常有许多“@import url”语句,从其他地方导入其他 CSS 文件(样式表),例如:

@import url("/home/WHOAMI/.config/gtk-3.0/apps/someother.css");
@import url("./another.css");

(将 WHOAMI 替换为您自己的帐户名)

本例中的 emacs 样式表(示例即将出现)将被称为 — — 您猜对了 — — emacs.css,我们需要将其添加到gtk.css,就像其他导入一样。假设:

@import url("/home/WHOAMI/.themes/gtk-3.0/emacs.css");

在将我的副本交给您之前,我想提几点说明:

  1. Gtk3 样式:与您可能期望的相反(我当然是这么想的),主题中可能提供的应用程序特定样式表(如前面提到的emacs.css以及 gtk-3.0 子目录或任何嵌套子目录(如 apps)中可能提供的其他样式表),这些应用程序特定样式表并不仅限于相应的应用程序!看起来,Gtk3 只是在同一个命名空间内愉快地解析所有样式表(我只是在这里编造了后一个术语,但似乎很合适)。

    这意味着,例如,当您在样式表中设置菜单样式并调用 CSS 选择器(例如“GtkMenu”)时,您实际上是在所有应用程序中设置 GtkMenu 的所有实例的样式。这可能是也可能不是您想要的,但就我而言,当我在样式表中工作时,我发现它非常适得其反,非常烦人,我出于某种原因将样式表命名为 emacs.css —— 即限制其对 emacs 的适用性。因此请注意,后一种假设是无效的。

  2. 另一点需要注意的是(部分原因是 a):尽管 css 现在看起来很小,但 emacs Gtk3 的样式难的(我承认我是一个 CSS 新手,但仍然如此)。我认为 emacs + Gtk3 需要有一个稍微好一点的 CSS 配置文件,因为有一个元素只能通过 '#窗格' 有点太笼统了,而且你几乎不能给滚动条设置主题,在我看来这是一个错误。我已经使用 emacs 超过 20 年了,我喜欢用 Gtk3 来设计最新的 emacs-24.3,就像我之前用 Gtk2 来设计 emacsen 一样。在大多数方面,拥有桌面主题的一致性是很好的,但在这个特殊情况下却不是:我在 emacs 上花了很多时间,它需要根据我的眼睛喜欢和习惯来塑造(所以请注意 emacs 开发人员!)

  3. 第三点:再次反过来,这是由 b 得出的结论:这个样式表看起来很脆弱!我感觉删除一个选择器,整个东西就会崩溃。

  4. 当你开始修改样式表时,不要从启动器启动应用程序。从终端命令行启动它,因此 Gtk3 可能给出的有关样式/解析错误的任何反馈都会直接呈现在您的面前。并且,你绝对不能在任何地方打开同一应用程序的其他实例。如果您这样做,Gtk 显然会缓存样式数据,而新实例只会使用缓存的数据,让您想知道为什么最终应该使其工作的编辑实际上是行不通的。因此,每次修改样式时:关闭电源循环:退出 emacs,从 CLI 重新启动它。

因此,这就是我的emacs.css

/*
    see:

    http://developer.gnome.org/gtk3/3.4/GtkCssProvider.html
    http://www.gnu.org/software/emacs/manual/html_node/emacs/GTK-resources.html
    http://thegnomejournal.wordpress.com/2011/03/15/styling-gtk-with-css/
    http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=72088=GTK3+with+CSS#p72088
*/

/*----------------------------------------------------------------*/
/*
General notes:
- try to make selectors as long as possible, so as not to interfere
  with the controls of other applications; this can be achieved only partly
  (e.g., #pane is a very general selector)
-

TODO:
- checkmarks in menus are black instead of white
- the 'exit emacs' popup dialog somehow gets the wrong resize grip
*/
/*----------------------------------------------------------------*/
/* this works */
#xxxpane
{
    background-color: alpha( @theme_selected_bg_color, 0.8 );
    color: purple;
}

#xxxframe                   /* works, but touches other applications */
                            /* (and we don't need it) )*/
{
    background-color: #708090;
    border-radius: 3px;
    font-size: 12pt;
    color: red;
}

/*----------------------------------------------------------------*/
#pane #verticalScrollBar
{
    /* the vertical scrollbar in emacs has a bug where it sometimes covers the fringe */
    border: 2px solid #292929;                  /* works ! */
    padding: 1px 10px;                          /* second value has enormous effect oddly in vertical dimension! */
    margin: 1px 10px;                           /* second value has enormous effect oddly in vertical dimension! */
    /*border-radius: 2px;*/                     /* works */
    /*
    GtkScrollbar:
    "fixed-slider-length"               gboolean
    "has-backward-stepper"              gboolean
    "has-forward-stepper"               gboolean
    "has-secondary-backward-stepper"    gboolean
    "has-secondary-forward-stepper"     gboolean
    "min-slider-length"                 gint
    */
    /*-GtkScrollbar-fixed-slider-length: 1;*/
    -GtkScrollbar-min-slider-length: 25;
    -GtkScrollbar-has-backward-stepper: 0;
    -GtkScrollbar-has-forward-stepper: 0;
    /*
    GtkRange:
    "activate-slider"          gboolean
    "arrow-displacement-x"     gint
    "arrow-displacement-y"     gint
    "arrow-scaling"            gfloat
    "slider-width"             gint
    "stepper-position-details" gboolean
    "stepper-size"             gint
    "stepper-spacing"          gint
    "trough-border"            gint
    "trough-side-details"      gboolean
    "trough-under-steppers"    gboolean
    */
    /*-GtkRange-activate-slider: 1;*/
    -GtkRange-slider-width: 4;                  /* works */
    -GtkRange-trough-border: 0;                 /* works */ /* with a large width it reveals a bug in emacs and/or gtk3 */
    -GtkRange-trough-side-details: 0;
    -GtkRange-trough-under-steppers: 0;
}

/*----------------------------------------------------------------*/
/* the toolbar is almost never visible */
#emacs-toolbar,
#emacs-toolbar *
{
    background-color: #536B84;
    color: white;
    padding: 0px 6px;
    border: 1px solid white;
}

/*----------------------------------------------------------------*/
/* objective: get menu pulldown menu's to have thin and rounded borders */

#pane #menubar GtkMenuShell
{
    border: 1px solid #78BAD4;  /* light blue */
    border-radius: 5px;
}

/* also give the menus a slightly larger font */
#pane #menubar,
#pane #menubar GtkMenuShell,
#pane #menubar GtkMenuShell *
{
    font-family: "Ubuntu Sans Mono";
    font-size: 7px;
}

/*----------------------------------------------------------------*/
#pane #menubar              /* works */
{
    background-color: #536B84;
    border: none;
    padding: 0px 0px;
    margin: 25px;
}

/* top menu item */
/* this works, but it needs a parent Emacs class specifier */
#pane #menubar > GtkLabel,
#pane #menubar > GtkMenuItem
{
    padding: 2px 18px;  /* works */
    margin: 3px 0px;    /* works */
    color: aquamarine;  /* works */
}

/*----------------------------------------------------------------*/
/* disabled ("greyed out") menu items */
/* note: #emacs-menuitem:insensitive only does one level deep; test on Edit > GoTo > ... */
#emacs-menuitem *:insensitive
{
    color: #292929;                         /* works */
    text-shadow: none;                      /* works */
}

#emacs-menuitem * :hover,
#xxxxemacs-menuitem * :active
{
    background-color: transparent;          /* FINALLY WORKS! */
    color: white;                           /* works */
}

#emacs-menuitem *,                          /* works */
#emacs-menuitem > GtkLabel                  /* works */
{
    background-color: #536B84;
    color: white                            /* works (also for tear lines!) */
}

#emacs-menuitem                             /* with only this it ALMOST works beautifully; only the tear lines are still white */
{
    background-color: #536B84;
    color: #292929;                         /* works -- this affects only the separators */
    border: 0px none;
    /*padding: auto auto;*/
    /*margin: 0px 0px 0px 0px;*/
    /*margin: auto auto auto auto;*/
}

/*----------------------------------------------------------------*/
/* popup dialog */
#emacs-dialog
{
    background-color: #536B84;
    color: white;
    border: 0px none;
}

/*----------------------------------------------------------------*/

看起来像个懦夫?好吧,这里面有很多小时的样式设计和反复试验(我讨厌 CSS,它不是真正的语言,没有可发现性)。

尝试一下,看看如何调整和自定义它。如果您得到任何见解或提示,或者发现缺点、错误或其他主题可能性,请提供反馈。我确信它是不完整和不完美的(首先,我无法将下拉菜单的底角弄圆)。

祝你好运!

答案2

Gnome 3 中设置字体大小的工具是gnome-tweak-tool

如果您发现此功能在您使用的桌面环境中不起作用,则将从以下位置读取字体大小$XDG_CONFIG_HOME/gtk-3.0/settings.ini

[Settings]
gtk-font-name = Sans 20

查看GtkSettings 文档更多细节。

相关内容