From c3bdea7d2428cc56ca33ff73c94795f3b3e8fce1 Mon Sep 17 00:00:00 2001 From: Franklin Mathieu Date: Thu, 25 Oct 2018 21:38:39 +0100 Subject: [PATCH] added small tutorial to get GTK themes & settings working --- GTK-3-settings-on-Wayland.md | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 GTK-3-settings-on-Wayland.md diff --git a/GTK-3-settings-on-Wayland.md b/GTK-3-settings-on-Wayland.md new file mode 100644 index 0000000..8c59a67 --- /dev/null +++ b/GTK-3-settings-on-Wayland.md @@ -0,0 +1,52 @@ +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. + +Note that 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`. + +## 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. + +### Setting values in `gsettings` + +The proper workaround is to call `gsettings set org.gnome.desktop.interface ` 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' +} +``` + +If you'd rather have those values picked from your settings.ini file, here is a small convenient script to just that: + +```bash +#!/bin/sh + +# usage: import-gsettings : : ... + +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 +``` \ No newline at end of file