Xresources or Xdefaults

'X' Marks The Spot

Using X Window System clients it's sometimes hard to decide whether to use .Xresources or .Xdefaults to set properties. Some suggest placing colors, fonts, etc in .Xdefaults. Others suggest using .Xresources. Which is right?

The main difference between .Xresources and .Xdefaults is age (and scope). .Xresouces is the modern method of applying resource values to X clients. The trick is to get .Xresources to load automatically at login.

If you use a desktop manager such as Gnome or LXDE, your .Xresources file may not load. The reason? Unless you run startx from the command line, your dot.Xfiles may get bypassed, when logging from GDM or KDM.

Normally its okay, as most people use Gnome Terminal, KDE Konsole or similar. But if you run XTerm you need X to read your .Xresources file. Unless you feel like loading it manually before you start XTerm. To get round the problem, create .xinitrc in your home directory.

First write up your settings and save the file. You can put Emacs settings here if you want.

Here's my .Xresources file:

XTerm*font: -*-lucidatypewriter-medium-*-*-*-12-*-*-*-*-*-*-*
XTerm*background: black
XTerm*foreground: white
XTerm*pointerColor: white
XTerm*pointerColorBackground: black
XTerm*cursorColor: green
XTerm*internalBorder: 2
XTerm*ScrollKey: true
XTerm*SaveLines: 1000
XTerm*multiClickTime: 250
XTerm*VT100.geometry: 80x24
XTerm*title: XTerm
XTerm*ScrollBar: false

Here's my .xmodmap

keycode 66 = Control_L
clear Lock
add Control = Control_L
keycode 117 = Caps_Lock
add Lock = Caps_Lock

When X-Window System starts, the X-Server looks for .xinitrc in the user home directory. If the file exists, it executes the commands. If it doesn't find it, then falls back on simple default settings for X. Commands in .xinitrc are only sourced once at startup.

Edit .xinitrc as a regular user, not root and make it executable. Do this:

chmod +x .xinitrc

Here's a look at my .xinitrc.

xmodmap ~/.xmodmap &
xrdb -load ~/.Xresources &

First line runs xmodmap and checks .xmodmap file in my home directory. This changes the CAPS LOCK key to Ctrl key. I never use caps lock and cannot imagine anyone having a use for it.

Second line runs xrdb and loads .Xresources file in my home dir.