Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
@don_crissti: That's cool. I knew about the new gnome-terminal setting, but I did not know about the new environment variable. Please post this as a answer, and I will accept it. –  Gary van der Merwe Feb 16 at 9:00

3 Answers 3

up vote 6 down vote accepted

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:
GTK_THEME=Adwaita:dark.

So, to load 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 env variable (nautilus is one of them).

share|improve this answer
    
So you can name a specific theme, but can't say "dark variant of whatever theme is set"? –  XTL Mar 18 at 7:38
1  
@XTL - Exactly. Though GTK_THEME=:light eog seems to be working too... –  don_crissti Mar 18 at 12:04
    
This doesn't seem to work for most applications. –  Thayne Jun 1 at 23:53
    
I haven't been able to find an application that this works for yet, when I have a dark theme. –  Thayne Jun 1 at 23:58
    
@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). –  don_crissti Jun 2 at 0:27

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.

#!/bin/bash
# lauch a gtk application with a different theme
# set GTKRCFILE variable to your favourite theme
GTKRCFILE=Clearlooks
GTK2_RC_FILES=/usr/share/themes/"$GTKRCFILE"/gtk-2.0/gtkrc "$@"

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.

share|improve this answer
1  
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 ... en.wikipedia.org/wiki/Daemon_%28classical_mythology%29 .. (pronounced day-mon) –  Peter.O Jun 10 '11 at 8:03
    
Typo, that's what happens when you don't spell check everything :| –  giodamelio Jun 10 '11 at 9:27

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
[Settings]
gtk-application-prefer-dark-theme=true
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.

share|improve this answer
    
Sorry for taking so long to try this. I tried it, but I get this error message: Gtk-WARNING **: Unknown key gtk-application-prefer-dark-theme-variant in /home/garyvdm/.config/gnome-terminal/gtk-3.0/settings.ini –  Gary van der Merwe Jan 18 '12 at 8:11
    
The correct setting name is gtk-application-prefer-dark-theme without the -variant at the end. I've edited the answer appropriately. –  Jan Larres Apr 11 '13 at 5:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.