Skip to content

GTK 3 settings on Wayland

Hosein Naghdbishi edited this page Dec 3, 2020 · 16 revisions

GTK+ is known for not picking up some variables from ${XDG_CONFIG_HOME}/gtk-3.0/settings.ini, most notably themes.

This happens because when GTK+ uses the wayland backend, a subset of variables are pulled from the gsettings schema org.gnome.desktop.interface, whereas on X11 GTK talks to a XSETTINGS daemon that usually does this for you, or when missing, falls back to the user's setting.ini file.

This only applies for settings that belong to org.gnome.desktop.interface. Some settings, like gtk-application-prefer-dark-theme, are still read from your settings.ini.

Cursor themes can be set in GTK for now, but a better solution in the future is to let sway handle it for you. See this wlroots issue tracking the status of this feature.

Workarounds

Setting GTK_THEME

If you only care about your GTK theme, you can export the GTK_THEME environment variable before running your GTK programs. While this is quite simple, it's also fairly limited, since there are no environment variables to set other settings, like icon/cursor themes.

This also may cause issues with applications reading the theme from GtkSettings as this is a development environment variable and does not change that value.

Setting values in gsettings

The proper workaround is to call gsettings set org.gnome.desktop.interface <key> <value> yourself at any point before starting any GTK program, for each setting that you want set. A good place to do so is either your shell's rc files, or using exec in your sway config.

You can list valid keys for the schema using gsettings list-keys org.gnome.desktop.interface; you most notably want to set gtk-theme, cursor-theme and icon-theme:

set $gnome-schema org.gnome.desktop.interface

exec_always {
    gsettings set $gnome-schema gtk-theme 'Your theme'
    gsettings set $gnome-schema icon-theme 'Your icon theme'
    gsettings set $gnome-schema cursor-theme 'Your cursor Theme'
    gsettings set $gnome-schema font-name 'Your font name'
}

If you'd rather have those values picked from your settings.ini file, here is a small convenient script to just that:

#!/bin/sh

# usage: import-gsettings <gsettings key>:<settings.ini key> <gsettings key>:<settings.ini key> ...

expression=""
for pair in "$@"; do
    IFS=:; set -- $pair
    expressions="$expressions -e 's:^$2=(.*)$:gsettings set org.gnome.desktop.interface $1 \1:e'"
done
IFS=
eval exec sed -E $expressions "${XDG_CONFIG_HOME:-$HOME/.config}"/gtk-3.0/settings.ini >/dev/null

Importing the gtk, icon, and cursor themes:

exec_always import-gsettings \
    gtk-theme:gtk-theme-name \
    icon-theme:gtk-icon-theme-name \
    cursor-theme:gtk-cursor-theme-name\
    font-name:gtk-font-name

XSettings

Some GTK applications running via XWayland, and some Java applications, need an XSettings daemon running in order to pick up the themes and font settings.

One implementation is xsettingsd.

Gnome (or rather, the Gnome Settings Daemon) provides its own XSettings daemon, usually installed at /usr/lib/xsettings.