Automatic Systemwide Colorscheme
This post will help you setup a script to automatically generate and apply a colorscheme given a wallpaper as input. This guide is aimed at people who use a minimal environement based on dwm and terminal apps.
Apps covered :
➤ Any terminal that supports xresources
➤ DWM
➤ Rofi/Dmenu
➤ dunst
Note: be careful to replace YOUR_THEME/YOUR_USER_NAME/etc.. by the relevent information when you copy/paste a command.
Perparations
Install Pywal with your favourite package manager :
Arch pacman -S python-pywal
Void
xbps-install pywal
Other : Install Pywal
Run pywal at least once with :
wal -i YOUR_WALLPAPER
dwm
We need to tell dwm to look for the file containing the colorscheme generated by pywal.
Delete these lines in your config.def.h :
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577";
static const char colors[][3] = {
/ fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
};
replace them by :
#include "/home/YOUR_USER_NAME/.cache/wal/colors-wal-dwm.h"
Xresources
We can create a symlink to the colorscheme.
ln -s ~/.cache/wal/colors.Xresources ~/.Xresources
Run this command to see the changes.
xrdb $HOME/.Xresources
Tip : If you use the suckless terminal, you need the Xresources patch.
Rofi / dmenu
For rofi, you have the possibility to keep your current theme and only setup the automatic color sync. If you don’t have a theme and want to start from scratch you can grab a theme there : /usr/share/rofi/themes/ and copy it to your ~/.config/rofi/ directory.
cp /usr/share/rofi/themes/YOUR_THEME.rasi ~/.config/rofi/
don’t forget to point rofi to your theme by adding this at the end of your config.rasi file.
@theme "YOUR_THEME"
Then, you need to remove all of the colors defined in the *{ } paragraph of your theme file, it should look like this :
* {
font: "YOUR_FONT 11";
}
Then add this at the very top of your theme file :
@import "~/.cache/wal/colors-rofi-dark.rasi"
This way, rofi keeps it’s configuration and only grabs the colorscheme generated by pywal.
For dmenu, the process is similar to dwm’s.
Delete these lines in your config.def.h :
static const char *colors[SchemeLast][2] = {
/* fg bg */
[SchemeNorm] = { "#bbbbbb", "#222222" },
[SchemeSel] = { "#eeeeee", "#005577" },
[SchemeOut] = { "#000000", "#00ffff" },
And replace them by :
#include "/home/YOUR_USER_NAME/.cache/wal/colors-wal-dmenu.h"
Dunst
The last application that needs to be synced is Dunst. To keep the notifications readable we want to keep the foreground color (text color) white and only change the background color.
This does not need any setup as a simple sed command can do that for us.
The Script
Now that the necessary setup has been done we can deploy the script that will change our system theme given a wallpaper. You can directly download the script on my git server here .
git clone git://korosama.xyz/setwal
Here’s a few explainations on how to use the script :
This is where you need to provide the path to the folder containing your dwm repo.
dwm=$HOME/Repos/dwm/ ### Put here the location of your dwm repo
WARNING !!! Please note that the script DELETES your config.h file when recompiling dwm, you need to put your configuration in config.def.h
The script uses nitrogen to setup the wallpaper, if you use another program to do that, please modify this line. Note that “$1” recodesents the wallpaper provided.
nitrogen --set-auto $1 ### Change the wallpaper backend here
Thanks for reading, hmu if you need help.