Wednesday, July 1, 2009

The (not-so) secret of .Xdefaults (or rather, .Xresources)

Several people commented that .Xdefaults—the original subject of the post—is an obsolete file, and that .Xresources should be used instead. I stand corrected, and so does the blog post.


There's a startling amount of people who have missed out on a pretty integral part of X11, namely the X resources database.

What the xrdb does is allow you to set various settings that you would otherwise have to pass with command line arguments to the programs. Clearly, it's pretty cumbersome to start xterm with the command xterm -fg gray -bg black just to escape the horrors of the black on white default color settings on xterm. Reverse video makes the defaults marginally less painful, but the contrast is still not particularly endearing.



Figure 1: A change of defaults makes a world of difference.


There's a wonderful file named ~/.Xresources that allows you to get around this. It is loaded automatically when the X session starts, and can be forced to reload with xrdb -merge ~/.Xresources

My .Xresources file looks like this:
XTerm*background: black
XTerm*foreground: gray
XTerm*title: terminal
XTerm*saveLines: 1024


If you read the man page for xterm, you'll find a rather intimidating list of settings you can alter with .Xresources.

Further reading:
.

5 comments:

  1. I think .Xresources has replaced .Xdefaults now. (At least in $HOME). According to a bug report in Debian (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=108394), the Xsession man page explains it as such: "$HOME/.Xresources contains X resources specific to the invoking user's environment. The settings are loaded with xrdb -merge. Note that $HOME/.Xdefaults is a relic from X Ver­sion 10 (and X11R1) days, before app-defaults files were implemented. .Xresources should
    be used instead."

    ReplyDelete
  2. @Tom: you're right. As the following document said:
    http://xwinman.org/resource.php

    ReplyDelete
  3. The post has been updated. Thanks for pointing this out.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. Finally we have positive confirmation that .Xdefaults is obsolete and I ought to be using .Xresources. The long-running confusion is finally over. I can now rest.

    If only I'd read 'man Xsession' six years ago.

    ReplyDelete