Skip to content

Xresources

Bakkeby edited this page Feb 27, 2024 · 1 revision

The Xresources functionality enables loading of colours from the X resources dotfile (typically located at ~/.Xresources).

This allows for colours for the bar and window borders to be changed without the need to recompile or restart the window manager.

The Xresource name will be on the form of dusk.<resource prefix>.(fg|bg|border).color.

The SchemeTitleNorm colour scheme as an example has the "titlenorm" prefix, which will lead to the following resource strings for the foreground, background and border colours:

  • dusk.titlenorm.fg.color
  • dusk.titlenorm.bg.color
  • dusk.titlenorm.border.color

The resource prefixes for colour schemes are defined in the internal default_resource_prefixes array in dusk.c, but can also be specified / overridden if need be via configuration in the colors array.


An example overriding the default resource prefix for SchemeTitleNorm.

static char *colors[SchemeLast][4] = {
   /*                       fg         bg         border     resource prefix */
   [SchemeTitleNorm]    = { "#D9CFC5", "#492B2D", "#643B3E", "title" },
   ...
};

This would lead to the following resources being read:

  • dusk.title.fg.color
  • dusk.title.bg.color
  • dusk.title.border.color

Being able to set the resource prefix via the colors array is more relevant if you end up creating your own colour schemes.


Here is a list of the default resources that are read, what colour scheme they belong to and whether they affect the foreground, background or border colours. The resources have a dusk. prefix.

Colour Scheme Foreground Background Border
SchemeNorm dusk.norm.fg.color dusk.norm.bg.color dusk.norm.border.color
SchemeTitleNorm dusk.titlenorm.fg.color dusk.titlenorm.bg.color dusk.titlenorm.border.color
SchemeTitleSel dusk.titlesel.fg.color dusk.titlesel.bg.color dusk.titlesel.border.color
SchemeScratchNorm dusk.scratchnorm.fg.color dusk.scratchnorm.bg.color dusk.scratchnorm.border.color
SchemeScratchSel dusk.scratchsel.fg.color dusk.scratchsel.bg.color dusk.scratchsel.border.color
SchemeHidNorm dusk.hidnorm.fg.color dusk.hidnorm.bg.color
SchemeHidSel dusk.hidsel.fg.color dusk.hidsel.bg.color
SchemeUrg dusk.urg.fg.color dusk.urg.bg.color dusk.urg.border.color
SchemeMarked dusk.marked.fg.color dusk.marked.bg.color dusk.marked.border.color
SchemeWsNorm dusk.wsnorm.fg.color dusk.wsnorm.bg.color
SchemeWsVisible dusk.wsvis.fg.color dusk.wsvis.bg.color
SchemeWsSel dusk.wssel.fg.color dusk.wssel.bg.color
SchemeWsOcc dusk.wsocc.fg.color dusk.wsocc.bg.color

Transparency can also be controlled via Xresources either via #RGBA value or via separate properties that end with .alpha where the value is between 0 and 255, e.g.

  • dusk.sel.TTB.bg.alpha: 180 or
  • dusk.*.bg.alpha: 180

Additionally basic terminal colors are read and used by the status2d functionality when the C or B markup symbols are used.

Here is the list of resources read and their corresponding status2d markup:

Resource set foreground set background
dusk.color0 ^C0^ ^B0^
dusk.color1 ^C1^ ^B1^
dusk.color2 ^C2^ ^B2^
dusk.color3 ^C3^ ^B3^
dusk.color4 ^C4^ ^B4^
dusk.color5 ^C5^ ^B5^
dusk.color6 ^C6^ ^B6^
dusk.color7 ^C7^ ^B7^
dusk.color8 ^C8^ ^B8^
dusk.color9 ^C9^ ^B9^
dusk.color10 ^C10^ ^B10^
dusk.color11 ^C11^ ^B11^
dusk.color12 ^C12^ ^B12^
dusk.color13 ^C13^ ^B13^
dusk.color14 ^C14^ ^B14^
dusk.color15 ^C15^ ^B15^

There are also a few colours used to control the look and feel of dmenu and these are:

dmenu foreground background
normal colours dmenu.norm.fg.color dmenu.norm.bg.color
selected colours dmenu.sel.fg.color dmenu.sel.bg.color
border colour dmenu.border.bg.color

These will update the variables of the same name that are defined in the config and used in the dmenucmd command.

Alternatively dmenu with the Xresources patch can be used.

X resources can also be reloaded during runtime by using the xrdb function.


The resources array allows the user to further customise values that can be overridden using X resources.

/* Xresources preferences to load at startup. */
static const ResourcePref resources[] = {
   { "dmenu.norm.fg.color", STRING, &dmenunorm.fg.color },
   { "dmenu.norm.bg.color", STRING, &dmenunorm.bg.color },
   { "dmenu.sel.fg.color", STRING, &dmenusel.fg.color },
   { "dmenu.sel.bg.color", STRING, &dmenusel.bg.color },
   { "dmenu.border.bg.color", STRING, &dmenubordercolor },
   { "dmenu.font", STRING, &dmenufont },
};

Each resource preference consists of three fields; the name of the resource string to be looked up, the type of value it is (one of STRING, INTEGER or FLOAT), and a reference to the variable that is to take the value as defined by the X resource string. The destination variable must also not be a constant.

As an example to allow the master stack factor (mfact) to be controlled using X resources the const indicator for the variable would have to be removed.

-static const float mfact     = 0.50; /* factor of master area size [0.05..0.95] */
+static       float mfact     = 0.50; /* factor of master area size [0.05..0.95] */

Then an entry is added to the resources array:

   { "dusk.mfact", FLOAT, &mfact },

In the .Xresources file the master stack factor can then be specified using:

dusk.mfact: 0.35

Note that workspace rules as an example can specify the master stack factor which means that the above would have no effect. Additionally some workspace settings are persisted across seamless restarts. This means that while X resource values are read and set on the initial startup any subsequent changes to .Xresources may not have any effect using xrdb or when restarting.


Example setup

Note that you can use #include in your .Xresources file which will make it easier to maintain if you are using more than one theme.

Nord theme

dusk_nord_theme.jpg

Gruvbox theme

dusk_gruvbox_theme.jpg

Dracula theme

dusk_dracula_theme.jpg

dwm theme

dusk_dwm_theme.jpg

Fjord theme

dusk_fjord_theme.jpg

One dark theme

dusk_one_dark_theme.jpg

The above themes are available via:


For general information about Xresources refer to:

Back to Functionality.

Clone this wiki locally