Skip to content

Instantly share code, notes, and snippets.

@hendricha
Last active February 8, 2017 14:31
Show Gist options
  • Save hendricha/bfa75b40fe4a3ab5e4f1 to your computer and use it in GitHub Desktop.
Save hendricha/bfa75b40fe4a3ab5e4f1 to your computer and use it in GitHub Desktop.
dark gtk per app

For gtk apps it's easy, just add the GTK_THEME environment variable, with a theme, and add ":dark". Since I don't want to change my code every time I replace my theme here's the solution:

GTK_THEME=`gsettings get org.gnome.desktop.interface gtk-theme | tr -d "'"`:dark COMMANDNAME

eg. if you want dark scratch-text-editor, run the command like this

GTK_THEME=`gsettings get org.gnome.desktop.interface gtk-theme | tr -d "'"`:dark scratch-text-editor

You want to always do it like this? Create bash script somewhere with the above code, make it executable and then add that to the Exec= line of the relevant .desktop file.

Getting a dark wingpanel is a bit trickier, since it is called without a desktop file from cerbere. I personally have a local bin folder in my path, so I put the shell script there, and named it wingpanel. Important that in that script I called /usr/bin/wingpanel, so there's no infinite loop.

Now the juicy part, how to get non gtk app, like mpv to use datk theme?

I created the following shell script,. to the same directory called mpv:

/usr/bin/mpv --no-terminal --force-window -- "$4" &
sleep 0.6
xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT "dark" -id `wmctrl -l | grep mpv | cut -d " " -f 1`

This script needs wmctrl so install it with apt-get. Note that the first line is bit of a hack that's needed because that's how mpv likes to be called. Add the default gui arguments (if any) for your app, if it's not mpv. The sleep time might be too fast, so if it starts, but the app still has the light titlebar then change it to 1 sec or something. Also note that the last line greps for something that's sort of relevant to the app, but you might have other windows open that have mpv in their name, so it might not work then. (And would require further hacking.)

Copy link

ghost commented Dec 19, 2014

Could you please explain a bit more what have you done with this part?

I created the following shell script,. to the same directory called mpv:

What do I have to do exactly? Do I run the script and append the file parameter via terminal?

@oktayacikalin
Copy link

Copy link

ghost commented Jan 8, 2015

Thank you.

@rhoconlinux
Copy link

rhoconlinux commented Feb 8, 2017

actually the call of mpv "by its name" might not work with some programmes, specially if the window name is not fixed/locked, like in the case of Spotify, Firefox and others (i.e., the stable spotify release puts the name of the song instead of the name of the program as a window title).

So, after stroggling a bit, I found a solution that worked for me, which I think is a bit more general.

The trick is to create a variable to store the window ID, so it can be used later in the xprop line. This ID can be captured as is the LAST window opened.

#!/bin/bash
/usr/bin/spotify --no-terminal --force-window -- "$4" &
sleep 0.5
winID=$(wmctrl -l | awk '/./{line=$0} END{print $1;}')
xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT "dark" -id wmctrl -l | grep $winID | cut -d " " -f 1

And voilà.

For elegance and comfort purposes only, you can also create a variable to easily change the program you want to switch, so you only need to edit the thing between brackets on the first line:

#!/bin/bash
EXEC=$(spotify)
/usr/bin/$EXEC --no-terminal --force-window -- "$4" &
sleep 0.5
winID=$(wmctrl -l | awk '/./{line=$0} END{print $1;}')
xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT "dark" -id wmctrl -l | grep $winID | cut -d " " -f 1

Cheers! (and thanks for the hand!)

PS:
Limitations: This launcher assumes that it is the only program starting at the time, cause it needs to parse the wmctrl list (-l) in order to apply the dark theme to the last window opened. So, don't open several windows or programs at the same time with this workaround cause it might paint other program's window borders! ;)

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