Skip to content

Instantly share code, notes, and snippets.

@diffficult
Created August 2, 2020 23:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diffficult/8ceb639505cabc1fe6a93b93140b058c to your computer and use it in GitHub Desktop.
Save diffficult/8ceb639505cabc1fe6a93b93140b058c to your computer and use it in GitHub Desktop.
Use different GTK themes for specific programs

Use a different GTK2/3 theme for specific programs

Why would you want to specify a different theme for a program?

Most common scenario, you installed a program that looks horrible or unreadable on your current theme or variation of that theme (light, dark). There's a simple workaround for most programs to fix this problem.


GTK 2

For GTK 2, just use the GTK_RC_FILES variable to tell the program which theme it's going to use. For example:

$ GTK2_RC_FILES=/usr/share/themes/Adwaita-dark/gtk-2.0/gtkrc gimp

Executing the program from the command line like that, will indicate that gimp has to use your Adwaita-dark theme, that's installed in /usr/share/themes/ directory (default path in most distros). This will work only that time and only when using that command indicating the correct location of the gtkrc file belonging to the theme you want to apply, no permanent changes to how it will open next time if using only gimp from the command line.

GTK 3

For GTK 3, you can use the GTK_THEME variable.

$ GTK_THEME=Adwaita:dark gimp

Once again, we can run gimp using the Adwaita:dark theme, this time there's no need to actually use the full path to the one we want to apply, just the name as it appears in the Appearance config panel. The same as above, this will only work just once and makes no permanent changes.


Always running your program with a different theme

There are two workarounds to make this changes more "permanent".

Modifying your program shortcut

Just locate your program .desktop file. Most distros place this files in /usr/share/applications or you can also find it in your Home directory, in ~/.local/share/applications/. Either way, just open the shortcut with your favourite editor and look for the Exec= line that tells that shortcut what to execute. There you can add the following:

  • GTK 2
[Desktop Entry]
...
Exec=env GTK2_RC_FILES=/usr/share/themes/Adwaita-dark/gtk-2.0/gtkrc gimp
...
  • GTK 3
[Desktop Entry]
...
Exec=env GTK_THEME=Adwaita:dark gimp
...

Making an alias for your program

Add to your .alias config file of choice a new alias for your program to be called from the command line.

...
alias gimpdark='GTK_THEME=Adwaita:dark gimp'
...

In some cases neither solution will work to actually force the theme on the program you need to run. In that case you could just try to for it using xprop and xdotool like this:

#!/bin/bash
/bin/spotify & 
sleep 0.2
xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT "dark" -id $(xdotool getactivewindow)

The example is an script that will force the dark variant of the current theme on the spotify program on execution. For this to work obviously you need to close any instance of the program you want to force to do this and execute the script instead of the program itself.


Sources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment