How to override fonts using Xresources - bakkeby/dusk GitHub Wiki

By default fonts are hardcoded in the configuration file in the fonts array and will need recompilation for any changes to take effect.

The default configuration may look like this:

static const char *fonts[] = { "monospace:size=10" };

It is possible to override fonts via Xresources with some changes to the configuration.

First let's create some placeholder variables.

static char font1[60] = "monospace:size=10";
static char font2[60] = "";
static char font3[60] = "";
static char font4[60] = "";

Note that the value of 60 above is how much space is reserved for each font string. This is needed because of the way the resource strings are written to the same place in memory. Without this we would run into a segmentation fault if the resource string would exceed the size of the original string.

Then we add those placeholders to the fonts array, replacing "monospace:size=10".

static const char *fonts[] = { font1, font2, font3, font4 };

After that we add resource hooks for those placeholder variables in the resources array.

/* Xresources preferences to load at startup. */
static const ResourcePref resources[] = {
	...
	{ "dusk.font1", STRING, &font1 },
	{ "dusk.font2", STRING, &font2 },
	{ "dusk.font3", STRING, &font3 },
	{ "dusk.font4", STRING, &font4 },
};

Now we should be able to add our resource overrides in our .Xresources file. For example:

dusk.font1: ComicCode:size=12
dusk.font2: Roboto Mono Medium for Powerline:size=11
dusk.font3: UbuntuMono Nerd Font Mono:size=14
dusk.font4:

Again note the text limit of 59 characters; the Roboto Mono one takes up 40 in this example. If you need more than 59 then make sure to increase the amount of space reserved for the placeholder variables.

It should be noted that due to the way fonts are loaded on startup, triggering xrdb to reload Xresources will update the font names in the fonts array, but this will not have any effect because the fonts themselves are not reloaded. There are things like the bar height that depend on the font so for changes to come into effect the user would have to instead do a restart.


Back to Guides.

⚠️ **GitHub.com Fallback** ⚠️