Skip to content

How to theme dusk using templates

Bakkeby edited this page Feb 28, 2024 · 2 revisions

A quick way to get going with theming is to use the predefined Xresource templates that can be found at:

Initial setup

You can place that themes directory where it best fits for you, but for this guide we are going to place it under ~/.config/dusk/ and to make things simple we are going to just clone directly into that directory.

git clone --depth=1 https://github.com/bakkeby/dusk.resources.git ~/.config/dusk

The templates use pre-processor directives to narrow down what resources need to be set based on predefined values.

Now let's say that you are interested in trying out the nord theme.

In your Xresources file, e.g. ~/.Xresources, you will need to add two lines.

The first one specifies the theme that you are interested in using. The second is the template that works out what resources need to be set for the chosen template.

#include "/home/username/.config/dusk/themes/dark/nord.res"
#include "/home/username/.config/dusk/themes/template.txt"

Now we will want to (re-)load Xresources using the command:

xrdb ~/.Xresources

Tip: if you want to actually see what resources have been set then try this command.

xrdb -query

or alternatively

xprop -root  | grep "RESOURCE_MANAGER" | xargs echo -e

Now we need to get dusk to load those resources.

The Xresources functionality needs to be enabled for this to work (it should be enabled by default).

We can run the following command to reload the resources:

duskc run_command xrdb

If everything worked then dusk should now look something like this:

nord.png

To change to another theme you can just edit the first include line in your ~/.Xresources file and reload.

template.txt

Now before getting settled I'd recommend having a look at the ~/.config/dusk/themes/template.txt file as it contains a few resource bindings for additional tools such as xmenu, slock, sxiv, nsxiv, pmenu and dunst. You may want to remove the resource properties for tools that you do not use, and/or optionally add properties for additional tools that you use.


Tip: if you do not want the dusk theme to bleed into the terminal and other tools that rely on the global color resources (*.color0, *.color1, etc.), then at the start of template.txt you can change the scope to make it only apply to dusk.

! Change the scope to "dusk" if you do not want the template
! to interfere with global colors (e.g. terminals).
#define COLOR_SCOPE *
!#define COLOR_SCOPE dusk

Simplifying things

Editing your ~/.Xresources file every time you want to try out another theme can get tedious.

If you have followed this guide then you should already have a few scripts checked out under ~/.config/dusk/scripts/tools/. You can either add this path to your PATH environment variable or move the scripts to your ~/bin or ~/.local/bin/ directory.

Here are two scripts / tools that can make changing dusk themes easier.

xrdb_reload.sh

The xrdb_reload.sh script takes the path to a theme and updates the #include line your ~/.Xresources file with the new path, reloads Xresources and sends the signal to dusk to reload colours.

Additionally it will generate shell escape sequences in a similar manner to pywal which terminals can read when starting up.


The escape sequences will be stored at ~/.cache/wal/sequences unless the XDG_CACHE_HOME environment variable is set (in which case it will be under $XDG_CACHE_HOME/wal/sequences).

For terminals you can either include this in your .bashrc:

(cat ~/.cache/wal/sequences &)

or alternatively you can source wal_restore.inc.


Example usage:

$ xrdb_reload.sh ~/.config/dusk/themes/dark/fjord.res
Loading theme: /home/username/.config/dusk/themes/dark/fjord.res

Also note that running xrdb_reload.sh without providing a theme file will do all of the above except changing the theme - which can also be useful when making other changes to .Xresources or to the template file itself.

There are a few more details that can be found here: https://github.com/bakkeby/dusk.resources/tree/master/scripts/tools#xrdb_reloadsh-theme-file

theme_menu.sh

theme_menu.sh is a dmenu script that presents all the theme files available and passes the selected theme file (if any) to the xrdb_reload.sh script above.

The intention is that when running the script you should get a menu that let you choose between all the theme names.

theme_menu.png


The script is intended to be used with this particular build of dmenu, but it can be changed to work with other versions of dmenu if need be. Running the script as-is with another version of dmenu is likely not going to work due to the use of additional command line arguments.


There are a few more details about this script that can be found here: https://github.com/bakkeby/dusk.resources/tree/master/scripts/tools#theme_menush-theme-dir


Back to Guides.

Clone this wiki locally