How to load .XResources correctly

In the X Window System, the X resources are parameters of computer programs such as the name of the font used in the buttons, the background color of menus, etc. They are used in conjunction with or as an alternative to command line parameters and configuration files.


Color scheme commands
Color scheme commands

Xresources and Xdefaults are user-level configuration dotfiles, typically located at ~/.Xresources and ~/.Xdefaults. They can be used to set X resources, which are configuration parameters for X client applications.

They can do many operations, including:

  • defining terminal colours
  • configuring terminal preferences
  • setting DPI, antialiasing, hinting and other X font settings
  • changing the Xcursor theme
  • theming xscreensaver
  • altering preferences on low-level X applications (xclock (xorg-xclock), xpdf, rxvt-unicode, etc.)

Parsing .Xresources

The file ~/.Xresources does not exist by default. Being a plain-text file, you can create and edit it with the text editor of your choice. Once present, it will be parsed by the xrdb (Xorg resource database) program automatically provided that you either:

  • are using a Display Manager to log into X. Most DM will autoload the ~/.Xresources file on login.
  • if you are using startx, you have to edit your ~/.xinitrc.

The resources will be stored in the X server so the file does not need to be read every time an app is started.

To reread your .Xresources file, and throw away your old resources:

xrdb ~/.Xresources

To reread your .Xresources file, and keep your old resources:

xrdb -merge ~/.Xresources

Note:

  • .Xresources is just a naming convention, xrdb can load any file. If you use xrdb manually, you can put such a file anywhere you want (for example, ~/.config/Xresources).
  • If you background the execution of xrdb in a chain of commands in ~/.xinitrc, the programs launched in the same chain might not be able to make use of it, so it is recommended to never background the xrdb command within ~/.xinitrc.
  • Resources loaded with xrdb are also accessible to remote X11 clients (such as those forwarded over SSH).
  • The older (deprecated) ~/.Xdefaults file is read every time you start an X11 program such as xterm, but only if xrdb has not ever been used in the current X session.

Adding to xinitrc

If you do not use a desktop environment, you probably need to add the following line to your ~/.xinitrc:

[[ -f ~/.Xresources ]] && xrdb -merge ~/.Xresources

Default settings

To see the default settings for your installed X11 apps, look in /usr/share/X11/app-defaults/.

Detailed information on program specific resources is usually provided in the man page for that app. Xterms manpage is a good example, containing a list of resources and the default value.

To see the current loaded resources:

xrdb -query -all

Warning: Color name “********” is not defined

I got this problem when I defined color scheme commands in terminal. It’s solved by rename ~/.Xresources to ~/.XResources. I don’t know why but it works.

1 thought on “How to load .XResources correctly”

  1. Thank you very much, the “[[ -f ~/.Xresources ]] && xrdb -merge ~/.Xresources” part was very helpful because I always had to start xterm twice to see any Xressources effect. I had “xrdb -merge ~/.Xresources &” in my .xinitrc.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.