GTK (简体中文)

From ArchWiki
翻译状态:本文是 GTK翻译。上次翻译日期:2013-02-18。如果英文版本有所更改,则您可以帮助同步翻译。


附注: 请使用模板的第一个参数进行更详细的指示。(在 Talk:GTK (简体中文)# 中讨论)

摘自 GTK 官方网站

GTK,或称 GIMP Toolkit,是一个跨平台的图形界面开发库。该库提供各式各样的窗口部件,小到一次性使用的程序、大到大型应用,GTK 都能满足你的需求。

GTK,即 GIMP Toolkit,最初由 GNU项目GIMP 开发,但现在它已经是一个非常流行的工具包,绑定了很多语言。本文将探讨 GTK 主题、风格、图标、字体和字号的配置工具,也会详细介绍手动配置。


目前在官方仓库中有三个版本的 GTK。它们可以通过以下软件包来安装

  • GTK 4.x 可以通过 gtk4 包获得。
  • GTK 3.x 可以通过 gtk3 包获得。
  • GTK 2.x 可以通过 gtk2 包获得。


  • GTK 1.x 可以通过 gtkAUR 包获得。


In GTK 3, the default theme is Adwaita, but HighContrast and HighContrastInverse themes are also included. In GTK 2, the default theme is Raleigh, but Arch Linux has a custom configuration file at /usr/share/gtk-2.0/gtkrc, which sets the default theme to Adwaita.

To force a specific theme, set the following environment variables:

  • For GTK 3, use GTK_THEME. For example to launch GNOME Calculator with the dark variant of Adwaita:
$ GTK_THEME=Adwaita:dark gnome-calculator
注意: To apply the above to desktop shortcuts (or launchers) see Desktop entries#Modify environment variables.
  • For GTK 2, use GTK2_RC_FILES. For example to launch GIMP with the theme Raleigh:
$ GTK2_RC_FILES=/usr/share/themes/Raleigh/gtk-2.0/gtkrc gimp
提示: gtkrc can also be a custom file in your home directory created by any of the 配置工具. See #Examples[损坏的链接:无效的章节].

More themes can be installed from the official repositories or the AUR. Manually extracted themes go in ~/.themes/ or ~/.local/share/themes/ directory.

Themes supporting GTK 2 and GTK 3:

  • Adapta — An adaptive GTK theme based on Material Design Guidelines. Includes: Adapta, Adapta-Eta, Adapta-Nokto, Adapta-Nokto-Eta || adapta-gtk-theme
  • Arc — A flat theme with a modern look and transparent elements. Includes: Arc, Arc-Dark, Arc-Darker || with transparency: arc-gtk-theme, without transparency: arc-solid-gtk-theme
  • Bluebird — Blue Desktop Suite for Xfce. || xfce-theme-bluebirdAUR
  • Breeze — GTK version of KDE's default widget theme. Includes: Breeze, Breeze-Dark || breeze-gtk
  • Deepin — Default theme for the Deepin desktop. Includes: deepin, deepin-dark || deepin-gtk-theme
  • GNOME Extra Themes — Extra themes for the GNOME desktop. Includes: Adwaita, Adwaita-dark, HighContrast || gnome-themes-extra
  • Greybird — A grey and blue Xfce theme, used by default in Xubuntu 12.04. || xfce-theme-greybirdAUR
  • Materia — A Material Design-like flat theme for GTK3, GTK2, and GNOME-Shell. || materia-gtk-theme
  • MATE Themes — Default themes for the MATE desktop. Includes: BlackMATE, Blue-Submarine, BlueMenta, ContrastHighInverse, Green-Submarine, GreenLaguna, Menta, TraditionalGreen, TraditionalOk || mate-themes
  • Numix — A flat and light theme with a modern look (GNOME, Openbox, Unity, Xfce). Includes: Numix || numix-gtk-theme-gitAUR
  • Vertex — Theme for GTK 3, GTK 2, Gnome-Shell and Cinnamon. || vertex-themesAUR
  • Zuki — Themes for GTK, gnome-shell and more. || zuki-themesAUR

There are a number of additional GTK themes in the AUR, example: search for gtk-theme.




Most major desktop environments provide tools to configure the GTK theme, icons, font and font size, and manage these settings via XSettings:

  • If you use Cinnamon, use Themes tool (cinnamon-settings themes): go to System Settings > Themes.
  • If you use Enlightenment: go to Settings > All > Look > Application Theme.
  • If you use GNOME, use GNOME Tweaks (gnome-tweaks): install gnome-tweaks.
  • If you use MATE, use the Appearance Preferences tool (mate-appearance-properties): go to System > Settings > Appearance.
  • If you use Xfce, use the Appearance tool: go to Settings > Appearance.

Other GUI tools generally overwrite the configuration files.

Both GTK 2 and GTK 3 are supported:

  • KDE GTK Configurator — Application that allows you to change style and font of GTK 2 and GTK 3 applications. || kde-gtk-config
After installation, kde-gtk-config can also be found in System Settings > Application Style > GNOME/GTK Application Style.
  • LXAppearance — Desktop independent GTK 2 and GTK 3 style configuration tool from the LXDE project (it does not require other parts of the LXDE desktop). || lxappearance-gtk3
  • Oo-mox — Graphical application for generating different color variations of Numix and Flat-Plat themes (GTK 2 and 3), Archdroid and Gnome-Colors icon themes. Also allows generating pre-scaled GTK 2 themes for HiDPI displays. || oomoxAUR

Only GTK 2 is supported:

  • GTK Change Theme — Little program that lets you change your GTK 2.0 theme (considered a better alternative to switch2). || gtk-chtheme
  • GTK Preference Tool — GTK theme selector and font switcher. || gtk2_prefsAUR
  • GTK Theme Switch — Simple GTK theme switcher. || gtk-theme-switch2AUR


GTK settings can be specified manually in configuration files, but desktop environments and applications can override these settings. Depending on GTK version, these files are located at:

  • GTK 2 user specific: ~/.gtkrc-2.0
  • GTK 2 system wide: /etc/gtk-2.0/gtkrc
  • GTK 3 user specific: $XDG_CONFIG_HOME/gtk-3.0/settings.ini, or $HOME/.config/gtk-3.0/settings.ini if $XDG_CONFIG_HOME is not set
  • GTK 3 system wide: /etc/gtk-3.0/settings.ini
  • See the GTK 3 GtkSettings properties (and GTK 2 properties[失效链接 2021-11-10 ⓘ]) in the GTK programming reference manual for the full list of currently supported GTK configuration options.
  • Some of the settings described below (such as gtk-icon-sizes) are deprecated and ignored since GTK 3.10.
  • If you edit your GTK configuration files, only newly started applications will display the changes.


To manually change the GTK theme, icons, font and font size, add the following to the configuration files, for example:

  • GTK 2:
gtk-icon-theme-name = "Adwaita"
gtk-theme-name = "Adwaita"
gtk-font-name = "DejaVu Sans 11"
  • GTK 3:
gtk-icon-theme-name = Adwaita
gtk-theme-name = Adwaita
gtk-font-name = DejaVu Sans 11

If the theme is not applied for GTK 3, use gsettings in addition:

$ gsettings set org.gnome.desktop.interface gtk-theme Pop
注意: The icon theme name is the name of its directory, not the name property in its index.theme.


有些 GTK 3 的主题包含深色版本, 但只有应用程序明确要求时才会使用. 要在所有 GTK 3 程序中应用深色模式, 请使用以下配置:

gtk-application-prefer-dark-theme = true



gtk-can-change-accels = 1

Emacs 按键绑定

To have Emacs-like key bindings in GTK applications add the following:

gtk-key-theme-name = "Emacs"
gtk-key-theme-name = Emacs

For GTK3 also run:

$ gsettings set org.gnome.desktop.interface gtk-key-theme "Emacs"

XFCE has a similar setting:

$ xfconf-query -c xsettings -p /Gtk/KeyThemeName -s Emacs

The config files in /usr/share/themes/Emacs/ determine what the Emacs bindings are, and can be changed. Copying sections to the users ~/.gtkrc-2.0 file allows for changes on a per user basis.

GNOME 菜单延迟


gtk-menu-popup-delay = 0




gtk-toolbar-style = GTK_TOOLBAR_ICONS


gtk-icon-sizes = "panel-menu=16,16:panel=16,16:gtk-menu=16,16:gtk-large-toolbar=16,16\


gtk-button-images = 0


gtk-menu-images = 0


Hide CSD buttons

To remove the minimize and maximize buttons from gtk3 windows:


See [1].


To turn off pasting on middle mouse button click (aka PRIMARY):



Open the file-chooser within the current working directory and not the recent location. Normally the current working directory is the Home directory.


Change setting with the following command:

$ gsettings set org.gtk.Settings.FileChooser startup-mode cwd


Add the following to ~/.config/gtk-2.0/gtkfilechooser.ini:


Legacy scrolling behavior

注意: This setting is not obeyed by all GTK applications.
提示: Legacy scrolling behaviour can be achieved reliably simply by using right click instead of left click.

Prior to GTK 3.6, clicking on either side of the slider in the scrollbar would move the scrollbar in the direction of the click by approximately one page. Since GTK 3.6, the slider will move directly to the position of the click. This behaviour can be reverted in some applications by creating the file with the content below:

gtk-primary-button-warps-slider = false

Disable overlay scrollbars

Since GTK 3.15, overlay scrollbars are enabled by default, meaning that scrollbars will be shown only on mouseover in GTK 3 applications. This behavior can be reverted by setting the following environment variable: GTK_OVERLAY_SCROLLING=0. See Environment variables#Graphical environment.

GTK 4 will no longer support GTK_OVERLAY_SCROLLING. It has already been dropped from master. As of GTK 4, the overlay nature of the scrollbars is part of the toolkit. The blanket toggle has been removed to prevent developers from breaking applications that have not been tested with both combinations. To allow application developers to decide what their applications should look like, the toolkit instead provides a mechanism to opt-out or add a setting for users. The function gtk_scrolled_window_set_overlay_scrolling() can be used to enable/disable overlay scrolling on a per-application basis. Application developers can optionally use GSettings to have a user setting bound to the property.

Remove overlay scroll indicators

The positions of the overlay scrollbars are indicated by thin dashed lines in the application window. These dashed lines will be present even when overlay scrolling is disabled using the environment variable discussed in the section above. To remove the indicator lines, create the following file:

/* Remove dotted lines from GTK 3 applications */, undershoot.right, undershoot.bottom, undershoot.left { background-image: none; }


GTK example configurations:

注意: May be ignored by some desktop environments (e.g. GNOME).
gtk-font-name="Sans 11"
gtk-font-name=Sans 11
# gtk-decoration-layout=menu:close
# gtk-application-prefer-dark-theme=1

GDK 后端

GDK(GTK 的底层抽象层)支持多个后端显示 GTK 应用。

Wayland 后端

The GDK Wayland backend is supported only by gtk3 and is the default backend when using Wayland display server.

Applications that use versions of GTK prior to gtk3 do not have wayland support, and need to use Xwayland in order to run on a wayland session using the X11 backend.

提示: To disable GTK window decorations in Wayland, install the gtk3-optional-csdAUR[损坏的链接:package not found] package and set the environment variable GTK_CSD=0.

Xorg 后端

If Xorg display server is in use, the backend defaults to x11 automatically.

It is possible to force GTK3 applications running on a wayland session to use the X11 backend through Xwayland by setting the environment variable GDK_BACKEND=x11.

Broadway 后端

The GDK Broadway backend provides support for displaying GTK applications in a web browser, using HTML5 and web sockets. [2]

When using broadwayd, specify the display number to use, prefixed with a colon, similar to X. The default display number is 0 (zero).

$ display_number=:5

Start it.

$ broadwayd $display_number 

Port used by default

port = 8080 + $display_number

Point your browser to

To Start apps

$ GDK_BACKEND=broadway BROADWAY_DISPLAY=$display_number <<app>>

Alternatively can set address and port

$ broadwayd --port $port_number --address $address $display_number


Different themes between GTK 2 and GTK 3 applications

In general, if a selected theme has support for both GTK 2 and GTK 3, the theme will be applied to all GTK 2 and GTK 3 applications. If a selected theme has support for only GTK 2, it will be used for GTK 2 applications and the default GTK theme will be used for GTK 3 applications. If the selected theme has support for only GTK 3, it will be used for GTK 3 applications and the default GTK theme will be used for GTK 2 applications. Thus for application theme consistency, it is best to use a theme which has support for both GTK 2 and GTK 3.

You could find what themes installed on your system have both an GTK 2 and GTK 3 version by using this command (does not work with names containing spaces):

find $(find ~/.themes /usr/share/themes/ -wholename "*/gtk-3.0" | sed -e "s/^\(.*\)\/gtk-3.0$/\1/") -wholename "*/gtk-2.0" | sed -e "s/.*\/\(.*\)\/gtk-2.0/\1"/

Theme not applied to root applications

As user theme files ($XDG_CONFIG_HOME/gtk-3.0/settings.ini, ~/.gtkrc-2.0) are not read by other accounts, the selected theme will not apply to X applications run as root. Possible solutions include:

  • Create symlinks, e.g
# ln -s /home/[username]/.gtkrc-2.0 /etc/gtk-2.0/gtkrc
# ln -s /home/[username]/.config/gtk-3.0/settings.ini /etc/gtk-3.0/settings.ini
  • Configure system-wide theme files: /etc/gtk-3.0/settings.ini (GTK 3) or /etc/gtk-2.0/gtkrc (GTK 2)
  • Adjust the theme as root
# lxappearance
  • Use a settings daemon (this is what most desktop environments do). A desktop-agnostic variant using XSettings is available in the AUR under xsettingsd-gitAUR.

Client-side decorations

GTK 3.12 introduced client-side decorations, which move the title-bar away from the window manager. This may present issues such as double title-bars, no title-bar at all or double shadows with compositing enabled.

To remove the shadow and gap around windows (for example in combination with a tiling window manager), create the following file:

.window-frame, .window-frame:backdrop {
 box-shadow: 0 0 0 black;
 border-style: none;
 margin: 0;
 border-radius: 0;

.titlebar {
 border-radius: 0;

.window-frame.csd.popup {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.13);

.header-bar {
  background-image: none;
  background-color: #ededed;
  box-shadow: none;
/* You may want to use this if you don't like the double title.
GtkLabel.title {
    opacity: 0;

To adjust the buttons in the header bar, use the gtk-decoration-layout setting. [3] The below examples removes all buttons:


cedilla ç/Ç instead of ć/Ć

See [4], and [5] for a workaround using Xcompose (US international layout).

Suppress warning about accessibility bus

If you do not use any Gnome Accessibility features, you may receive warnings like:

WARNING **: Couldn't connect to accessibility bus:

To suppress these warnings, execute programs with NO_AT_BRIDGE=1 or set that as a global environment variable.

Titlebar background color mismatch

If you are using a window manager which uses a window decoration theme that mimics the GTK theme background color, you may find that the titlebar color no longer completely matches the application color in some GTK 3 applications. As a workaround, create the following file:

/* Always use background color */
GtkWindow {
    background-color: @theme_bg_color;

/* Fix tooltip background override */
.tooltip {
    background-color: rgba(0, 0, 0, 0.8);

.tooltip * {
    background-color: transparent;

/* Fix Nautilus desktop window background override */
NautilusWindow {
     background-color: transparent; 

Wrong focus events with tiling window managers

注意: This disables smooth scrolling and touchscreen support for GTK3 applications. [6]

Define GDK_CORE_DEVICE_EVENTS=1 to use GTK2 style input, instead of xinput2. [7]

Thumbnail support for GTK file dialog

Install gtk2-patched-filechooser-icon-viewAUR and gtk3-patched-filechooser-icon-viewAUR to have the option to view files as thumbnails instead of list in the GTK file chooser.

Button and menu icons

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Explain what the issue is. GNOME ignores settings.ini if GDM is used. (Discuss in Talk:GTK (简体中文))

For some applications in GNOME's Wayland session. Your ~/.config/gtk-3.0/settings.ini file is misconfigured. This can happen if you try other GTK based desktop environments. These are the offending values:


Simply set them to 0 or remove the whole file to use GNOME defaults.

GTK 3 without polkit

GTK3 depends on polkit through colord, which is required for printing. However printing works fine without polkit installed; at least with a monochrome printer and package versions gtk3-print-backends=3.22.19-2 and colord=1.4.1-1.

Some GTK 2 themes only change the UI color palette

Depending on the theme of choice's support for GTK 2, UI controls may still have the default Raleigh appearance, possibly with a different color palette. This is due to these themes requiring the GTK 2 Murrine engine, which is missing (GTK 2 programs should complain about it on their standard error output). Install the gtk-engine-murrine package.

Patching GTK file chooser to use regular type ahead

GTK file chooser uses the same type-ahead-find feature as GNOME/Files. This can be very jarring and does not fit in very well with other desktop enviroments.

Some applications support XDG-desktop-portal which allows application to use the native file chooser. If that does not work you can restore type-ahead functionality by using a patched GTK, for example gtk3-mushroomsAUR[损坏的链接:package not found].