By Gary van der Merwe

2011-06-01 06:34:02 8 Comments

Is there a way to set gtk-application-prefer-dark-theme for an application?

This is normally set in the code by the application. Apps such as Eye of Gnome and Totem turn it on. I want to, as a user turn it on, on a per application bases.

For gnome-terminal, I normally use a white text on black background color scheme, and having the dark window border would improve the overall look.

I also want to turn it on for vlc.


@galczo5 2020-05-04 21:25:32

If somebody still need it, I've created simple app that will automatically set dark theme for specified apps.

You can find it here:

@Scott 2020-05-04 23:30:10

Please describe how this app can be used to answer the question.

@user2452171 2020-03-31 12:43:27

I wrote a little wrapper script for that:


if [ $# -eq 0 ]; then
    xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT "dark"
    exit $?

GTK_THEME="$(gsettings get org.gnome.desktop.interface gtk-theme)"
export  GTK_THEME="${a%%:*}:dark"
export GTK_THEME_VARIANT="dark"
"[email protected]" & PID="$!"
echo "started darkening for PID=$PID"
while :; do
    if [ $cnt -lt 1000 ]; then
        sleep .1
        let 'x=x-1'
        sleep 5
    if ! kill -0 $PID 2>/dev/null; then
        echo "darkening for PID=$PID done"
        exit 0
    REGEX="$(echo $PID | cat - <(command ps -o pid:1 --no-headers --ppid $PID) | paste -sd "|" -)"
    wmctrl -lp \
        | rg -i "^(0x[a-f0-9]+)\s+\d+\s+($REGEX)\s" -o --replace '$1' \
        | xargs -I @ xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT "dark" -id @

It'S using for REGEX

@Nick Bull 2019-08-27 14:08:41

Specifically for gnome-terminal, you can use the following to make the specific application dark:

gsettings set org.gnome.Terminal.Legacy.Settings theme-variant 'dark'

@don_crissti 2015-02-16 12:07:54

With gtk+ ≥ 3.12 you can load a specific theme and its variant (dark, light) on a per-application1 basis via the environment variable GTK_THEME=theme:variant. As per the gtk+ reference manual:

GTK_THEME.  If set, makes GTK+ use the named theme instead of the theme that is
specified by the gtk-theme-name setting [...] It is also possible to specify a
theme variant to load, by appending the variant name with a colon, like this:

So, to load2 the dark variant you would run:

GTK_THEME=Adwaita:dark gedit

Likewise, to achieve the opposite (when the default theme is dark), you load the light variant:

GTK_THEME=Adwaita:light gedit

Note that if you want to use it via a custom launcher (.desktop file) you'll have to prepend env to the command in the Exec line:

Exec=env GTK_THEME=Adwaita:dark eog %U

1: Worth noting that - as per the devs decision - newer gnome-terminal has its own configuration via menu > preferences and it ignores the theme. Also, since this is rather new stuff, some gtk+ 3 applications might not (yet) honor the GTK_THEME environment variable.
2: This doesn't seem to work if you already have a running instance of that application e.g. if nautilus is already running in dark mode then running GTK_THEME=Adwaita:light nautilus will open a new nautilus window but still in dark mode. I don't know if this is a feature or a bug...

@XTL 2015-03-18 07:38:33

So you can name a specific theme, but can't say "dark variant of whatever theme is set"?

@don_crissti 2015-03-18 12:04:22

@XTL - Exactly. Though GTK_THEME=:light eog seems to be working too...

@Thayne 2015-06-01 23:53:12

This doesn't seem to work for most applications.

@Thayne 2015-06-01 23:58:47

I haven't been able to find an application that this works for yet, when I have a dark theme.

@don_crissti 2015-06-02 00:27:55

@Thayne - as per the first line in my post, this works for systems/apps using gtk3 version 3.12 or higher (but the apps must honor the GTK_THEME env variable).

@aBarocio80 2016-07-13 18:13:20

I have tried the above (for .desktop files), but it doesn't work, not even with the env. When launched from terminal it works prefectly. I use gtk 3.14.5-1+deb8u1, and tried with gedit 3.14.0-3, running on Debian "jessie/stable" 8.

@don_crissti 2016-07-13 18:26:22

@aBarocio80 - works fine here (archlinux + gnome 3 - up to date). Any custom launcher I create in ~/.local/share/applications/ (including for gedit) honors the env GTK_THEME directive in the Exec field so most likely something is wrong on your setup but since I don't use debian/derivatives I can't help you.

@user32012 2017-11-27 14:15:15

As not all themes have variants, one could try something like GTK_THEME=NAME_OF_THEME APP. But this works only for some apps (from what I have tested: synaptic, gdebi, transmission-gtk, uget-gtk, basic text editors). Thunar and Pcmanfm do not follow, which is not a big issue, as the main non-specific theme is usually meant for the file manager. But libreoffice and vlc which are not great with a dark theme do not follow. What (somewhat) works for those is this:

@user32012 2017-11-27 16:49:53

sh -c can be used here instead of env

@Nick Bull 2019-08-27 14:07:46

Specifically for gnome-terminal, you can use the following gsettings set org.gnome.Terminal.Legacy.Settings theme-variant 'dark'

@Martin Marconcini 2019-12-12 11:36:58

For Charles Proxy (a big Java app), at least on Pop!_OS it's very hard to read on Dark Mode, so I changed /usr/share/applications/charles-proxy.desktop and changed the Exec line to look like: Exec=env GTK_THEME=Adwaita:light /usr/bin/charles4 %F this makes Charles a bright lamp, but readable.

@Florian Müllner 2011-11-06 21:35:57

For GTK+-3 applications, you can enforce the dark theme variant using GtkSettings' settings.ini:

$ mkdir -p $HOME/.config/gnome-terminal/gtk-3.0 # the path before gtk-3.0 is arbitrary
$ cat >> $HOME/.config/gnome-terminal/gtk-3.0/settings.ini << EOF
$ echo 'alias gnome-terminal="XDG_CONFIG_HOME=$HOME/.config/gnome-terminal gnome-terminal" >> $HOME/.bashrc

For non-GTK+ applications like vnc, you can still enforce dark window decorations by setting the _GTK_THEME_VARIANT X property of type UTF8_STRING to dark. To do this with xprop, type the following command and click the window afterwards:

$ xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT "dark"

xprop can also select windows by the WM_NAME property (the title bar label) or by window id:

$ xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT "dark" -name "Spotify Premium - Linux Preview"
$ xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT "dark" -id 0x380002b

To get window ids and names, use xlsclients -l.

@MattSturgeon 2016-03-12 21:03:57

For some reason gnome-terminal has decided it's too much effort to keep the code for the Dark theme, so unless your distro has patched this back in this wont work for gnome-terminal

@giodamelio 2011-06-10 05:06:19

Here is a bash script I have used to launch a application with a different theme. Haven't used it in years though, so I don't know if it will work with the current GTK.

# lauch a gtk application with a different theme
# set GTKRCFILE variable to your favourite theme
GTK2_RC_FILES=/usr/share/themes/"$GTKRCFILE"/gtk-2.0/gtkrc "[email protected]"

Here is a bit of info I got off the ubuntu fourms archives. Not sure if it will be a problem. (here) There is also a blog post detailing this method a little more. (here) and (here). There is also a similar question on this site that has already been answered. (here)

Under gnome, apps get their theme from the gnome-settings-daemon. This instantaneously applies any theme change to all active applications, making per-appplication theme changing impossible.

@Peter.O 2011-06-10 08:03:09

Typo or mistake? ('gnome-settings-demon")... The word is daemon (not demon).. It has a very different root meaning: …(in ancient Greek belief) Daemons are good or benevolent supernatural beings between mortals and gods ... daemon=good / demon=bad ... .. (pronounced day-mon)

@giodamelio 2011-06-10 09:27:17

Typo, that's what happens when you don't spell check everything :|

@Joce 2016-01-27 08:49:39

@Peter.O: Different meaning in present day English, but same origin indeed.

@Robbi Nespu 2018-08-09 09:23:09

tried with GTK2_RC_FILES=/usr/share/themes/Adwaita/gtk-2.0/gtkrc /opt/ide/eclipse and does't worked

@Jonathan Neufeld 2019-11-09 03:06:05

This works well for gapcmon

Related Questions

Sponsored Content

2 Answered Questions

Running Darktable under Xfce using specific color style/theme

  • 2013-02-17 14:22:41
  • a CVn
  • 1058 View
  • 3 Score
  • 2 Answer
  • Tags:   xfce gtk theme

3 Answered Questions

[SOLVED] Using a dark theme in KDE with Gnome applications (e.g., Firefox)

1 Answered Questions

GTK3 Icon theme and window decorator per-application basis

1 Answered Questions

1 Answered Questions

[SOLVED] Except some applications (like VLC) from using the current gtk3 theme

1 Answered Questions

[SOLVED] Debian Xfce, Proper GTK 3 Greybird Theme Integration with Chromium

2 Answered Questions

[SOLVED] How to customize window decorator for a single non-GTK3 application window in Gnome3?

  • 2013-07-29 13:57:04
  • dfhsfhdsfdhsdfgjsfgjdsdfgjsfgj
  • 4206 View
  • 3 Score
  • 2 Answer
  • Tags:   gtk theme gtk3

Sponsored Content