Difference between revisions of "X resources"

From ArchWiki
Jump to: navigation, search
m (Terminal colors: a good place to start)
m (Contributed examples: rm dead link jason and color example moved)
Line 516: Line 516:
==Contributed examples==
==Contributed examples==
Check out these links for some real world examples of Xdefaults, contributed by fellow community members (Xdefaults has the same syntax as Xresources):
Check out these links for some real world examples of Xdefaults, contributed by fellow community members. Note that Xdefaults has the same syntax as Xresources.
* http://dotfiles.org/~buttons/.Xdefaults
* http://dotfiles.org/~buttons/.Xdefaults
Line 522: Line 522:
* http://github.com/stxza/arch-linux-configs/tree/master/.Xdefaults
* http://github.com/stxza/arch-linux-configs/tree/master/.Xdefaults
* http://github.com/jelly/dotfiles/tree/master/.Xdefaults
* http://github.com/jelly/dotfiles/tree/master/.Xdefaults
* http://bitbucket.jasonwryan.com/eeepc/src/tip/.Xdefaults
* https://github.com/roygbiiv/linuks/blob/master/dotfiles/.Xdefaults
A good place to start making your own Xresources is the default colors:
*color0: black
*color1: red3
*color2: green3
*color3: yellow3
*color4: blue2
*color5: magenta3
*color6: cyan3
*color7: gray90
*color8: gray50
*color9: red
*color10: green
*color11: yellow
*color12: rgb:5c/5c/ff
*color13: magenta
*color14: cyan
*color15: white
==More resources==
==More resources==

Revision as of 21:28, 8 July 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Xresources and Xdefaults are user-level configuration dotfiles, typically located at Template:Filename and Template:Filename. 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, xpdf, etc.)
Note: Using Xdefaults is deprecated, so this article will refer to Xresources only.

Getting started

Parsing .Xresources

The file Template:Filename does not exist by default. Being a plain-text file, you can create and edit it with the text editor of your choice.

Once Template:Filename is present, it will be parsed by the Template:Codeline (Xorg resource database) program automatically when Xorg is started, and you must re-run Template:Codeline every time you change the file.

If you do not use a Desktop Environment, you may need to add:

xrdb -merge ~/.Xresources

to your xinitrc.

Using Template:Filename stores the resources in the X server, so the file does not need to be reread over and over and it works for remote X clients too.

  • If you use xrdb manually you can actually put the file anywhere you want, for example in Template:Filename.
  • If you background the execution of xrdb in a chain of commands in .xinitrc, the programs launched in the same chain could not make use of it.

The older (deprecated) Template:Filename is read every time you start an X program such as Template:Codeline, but only if Template:Codeline has not ever been used in the current X session. [1]

Default settings

To see the default settings for your installed X11 apps, look in Template:Filename.

Xresources syntax

The basic syntax

The syntax of an Xresources file is as follows:

name.Class.resource: value

and here is a real world example:

xscreensaver.Dialog.headingFont: -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1
The name of the application, such xterm, xpdf, etc
The classification used to group resources together. Class names are typically uppercase.
The name of the resource whose value is to be changed. Resources are typically lowercase with uppercase concatenation.
The actual value of the resource. This can be 1 of 3 types:
  • Integer (whole numbers)
  • Boolean (true/false, yes/no, on/off)
  • String (a string of characters) (for example a word (white), a color (#ffffff), or a path (/usr/bin/firefox))
A period (.) is used to signify each step down into the hierarchy -- in the above example we start at name, then descend into Class, and finally into the resource itself. A colon (:) is used to separate the resource declaration from the actual value.

Wildcard matching

The asterisk can be used as a wildcard, making it easy to write a single rule that can be applied to many different applications or elements.

Using the previous example, if you want to apply the same font to all programs (not just xscreensaver) that contain the class name Dialog which contains the resource name headingFont, you would write:

*Dialog.headingFont:     -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1

If you want to apply this same rule to all programs that contain the resource headingFont regardless of its class, you would write:

*headingFont:    -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1


To add a comment to your Xresources file, simply prefix it with an exclamation point (!), for example:

! This is a comment placed above some Xft settings
xft.dpi:       96      ! this is an inline comment
! The following rule will be ignored because it has been commented out
!xft.antialias:        true

Sample usage

The following samples should provide a good understanding of how application settings can be modified using an Xresources file. For full details, refer to the man page of the application in question.

File header

If desired, you can add a header to Template:Filename which not only explains the file's contents, but also instruct vim how to perform syntax highlighting and other formatting. For example:

! ----------------------------------------------------------------------------
! file:     ~/.Xresources
! author:   Thayer Williams - http://cinderwick.ca
! modified: November 2008
! vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=xdefaults:
! ----------------------------------------------------------------------------

This will instruct vim to use UTF-8 encoding, display line numbers, auto-indent, smart-indent, expand tabs to spaces, set tabs to equal 4 spaces, and set the autocommand Filetype to "xdefaults".

It is a good habit to get into, especially if you'd like to make your dotfiles available for public consumption.

Terminal colors

Most terminals, including xterm and urxvt, support at least 16 basic colors. The following is an example of a 16-color scheme. The colors 0-7 are the 'normal' colors, while colors 8-15 are their 'bright' counterparts, used for highlighting and such. A good place to start when making your Xresources, is to define the default terminal colors:

! terminal colors ------------------------------------------------------------

! tangoesque scheme
*background: #111111
*foreground: #babdb6
! Black (not tango) + DarkGrey
*color0:  #000000
*color8:  #555753
! DarkRed + Red
*color1:  #ff6565
*color9:  #ff8d8d
! DarkGreen + Green
*color2:  #93d44f
*color10: #c8e7a8
! DarkYellow + Yellow
*color3:  #eab93d
*color11: #ffc123
! DarkBlue + Blue
*color4:  #204a87
*color12: #3465a4
! DarkMangenta + Mangenta
*color5:  #ce5c00
*color13: #f57900
!DarkCyan + Cyan (both not tango)
*color6:  #89b6e2
*color14: #46a4ff
! LightGrey + White
*color7:  #cccccc
*color15: #ffffff

For more examples of color schemes, see the #More resources section at the bottom of this article.

Xcursor resources

Set the theme and size of your mouse cursor:

! Xcursor --------------------------------------------------------------------

Xcursor.theme: Vanilla-DMZ-AA
Xcursor.size:  22

Available themes reside in Template:Filename and local themes can be installed to Template:Filename.

Xft resources

You can define basic font resources without the need of a Template:Filename file or a desktop environment. Note however, the use of a desktop environment and/or Template:Filename can override these settings. Your best option is to use one or the other, but not both.

! Xft settings ---------------------------------------------------------------

Xft.dpi:        96
Xft.antialias:  true
Xft.rgba:       rgb
Xft.hinting:    true
Xft.hintstyle:  hintslight

Xterm resources

The following resources will open xterm in an 80x25 character window with a scroll-bar and scroll capability for the last 512 lines. The specified Terminus facename is a popular and clean terminal font.

! xterm ----------------------------------------------------------------------

xterm*geometry:           80x25
xterm*faceName:           terminus:bold:pixelsize=14
!xterm*font:              -*-dina-medium-r-*-*-16-*-*-*-*-*-*-*
xterm*dynamicColors:      true
xterm*utf8:               2
xterm*eightBitInput:      true
xterm*saveLines:          512
xterm*scrollTtyKeypress:  true
xterm*scrollTtyOutput:    false
xterm*scrollBar:          true
xterm*rightScrollBar:     true
xterm*jumpScroll:         true
xterm*multiScroll:        true
xterm*toolBar:            false

Urxvt resources

Urxvt features an extensive list of options which can be configured via Template:Filename. Refer to the urxvt man page for details.

Aterm preferences

Sample settings for aterm (very similar to urxvt):

!aterm settings-------------------------------------------------------------     

aterm*background:               black
aterm*foreground:               white
aterm*transparent:              true
aterm*shading:                  30
aterm*cursorColor:              gray
aterm*saveLines:                2000
!aterm*tinting:                 gray
aterm*scrollBar:                false
!aterm*scrollBar_right:          true
aterm*transpscrollbar:          true
aterm*borderwidth:              0
aterm*font:                     -*-terminus-*-*-*-*-*-*-*-*-*-*-*-*
aterm*geometry:                 80x25
!aterm*fading:                  70  

Xpdf resources

Following are some basic resources for xpdf, a lightweight PDF viewer:

! xpdf -----------------------------------------------------------------------

xpdf*enableFreetype:    yes
xpdf*antialias:         yes
xpdf*foreground:        black
xpdf*background:        white
xpdf*urlCommand:        /usr/bin/firefox %s

Anything more detailed than the above you should be putting in Template:Filename instead. See the xpdf man page for more information. Note that Template:Codeline is deprecated.

Lal clock resources

! lal clock ------------------------------------------------------------------

lal*font:       Arial
lal*fontsize:   12
lal*bold:       true
lal*color:      #ffffff
lal*width:      150
lal*format:     %a %b %d %l:%M%P

Xclock preferences

Some basic xclock settings. See the xclock man page for all X resources.

! xclock ---------------------------------------------------------------------

xclock*update:            1
xclock*analog:            false
xclock*Foreground:        white
xclock*background:        black

X11-ssh-askpass resources

! x11-ssh-askpass ------------------------------------------------------------

x11-ssh-askpass*font:                   -*-dina-medium-r-*-*-12-*-*-*-*-*-*-*
x11-ssh-askpass*background:             #000000
x11-ssh-askpass*foreground:             #ffffff
x11-ssh-askpass.Button*background:      #000000
x11-ssh-askpass.Indicator*foreground:   #ff9900
x11-ssh-askpass.Indicator*background:   #090909
x11-ssh-askpass*topShadowColor:         #000000
x11-ssh-askpass*bottomShadowColor:      #000000
x11-ssh-askpass.*borderWidth:           1

Xscreensaver resources

Following is a sample xscreensaver theme. For more information, refer to the xscreensaver man page.

! xscreensaver ---------------------------------------------------------------

!font settings
xscreensaver.Dialog.headingFont:        -*-dina-bold-r-*-*-12-*-*-*-*-*-*-*
xscreensaver.Dialog.bodyFont:           -*-dina-medium-r-*-*-12-*-*-*-*-*-*-*
xscreensaver.Dialog.labelFont:          -*-dina-medium-r-*-*-12-*-*-*-*-*-*-*
xscreensaver.Dialog.unameFont:          -*-dina-medium-r-*-*-12-*-*-*-*-*-*-*
xscreensaver.Dialog.buttonFont:         -*-dina-bold-r-*-*-12-*-*-*-*-*-*-*
xscreensaver.Dialog.dateFont:           -*-dina-medium-r-*-*-12-*-*-*-*-*-*-*
xscreensaver.passwd.passwdFont:         -*-dina-bold-r-*-*-12-*-*-*-*-*-*-*
!general dialog box (affects main hostname, username, password text)
xscreensaver.Dialog.foreground:         #ffffff
xscreensaver.Dialog.background:         #111111
xscreensaver.Dialog.topShadowColor:     #111111
xscreensaver.Dialog.bottomShadowColor:  #111111
xscreensaver.Dialog.Button.foreground:  #666666
xscreensaver.Dialog.Button.background:  #ffffff
!username/password input box and date text colour
xscreensaver.Dialog.text.foreground:    #666666
xscreensaver.Dialog.text.background:    #ffffff
xscreensaver.Dialog.borderWidth:        20
xscreensaver.Dialog.shadowThickness:    2
!timeout bar (background is actually determined by Dialog.text.background)
xscreensaver.passwd.thermometer.foreground:  #ff0000
xscreensaver.passwd.thermometer.background:  #000000
xscreensaver.passwd.thermometer.width:       8
!datestamp format--see the strftime(3) manual page for details
xscreensaver.dateFormat:    %I:%M%P %a %b %d, %Y

Xcalc resources

Following are some xcalc resources to colorize and customize buttons.


xcalc*geometry:                        200x275
xcalc.ti.bevel.background:             #111111
xcalc.ti.bevel.screen.background:      #000000
xcalc.ti.bevel.screen.DEG.background:  #000000
xcalc.ti.bevel.screen.DEG.foreground:  LightSeaGreen
xcalc.ti.bevel.screen.GRAD.background: #000000
xcalc.ti.bevel.screen.GRAD.foreground: LightSeaGreen
xcalc.ti.bevel.screen.RAD.background:  #000000
xcalc.ti.bevel.screen.RAD.foreground:  LightSeaGreen
xcalc.ti.bevel.screen.INV.background:  #000000
xcalc.ti.bevel.screen.INV.foreground:  Red
xcalc.ti.bevel.screen.LCD.background:  #000000
xcalc.ti.bevel.screen.LCD.foreground:  LightSeaGreen
xcalc.ti.bevel.screen.LCD.shadowWidth: 0
xcalc.ti.bevel.screen.M.background:    #000000
xcalc.ti.bevel.screen.M.foreground:    LightSeaGreen
xcalc.ti.bevel.screen.P.background:    #000000
xcalc.ti.bevel.screen.P.foreground:    Yellow
xcalc.ti.Command.foreground:  White
xcalc.ti.Command.background:  #777777
xcalc.ti.button5.background:  Orange3
xcalc.ti.button19.background: #611161
xcalc.ti.button18.background: #611161
xcalc.ti.button20.background: #611111
!uncomment to change label on division button
!xcalc.ti.button20.label:      /
xcalc.ti.button25.background: #722222
xcalc.ti.button30.background: #833333
xcalc.ti.button35.background: #944444
xcalc.ti.button40.background: #a55555
xcalc.ti.button22.background: #222262
xcalc.ti.button23.background: #222262
xcalc.ti.button24.background: #222272
xcalc.ti.button27.background: #333373
xcalc.ti.button28.background: #333373
xcalc.ti.button29.background: #333373
xcalc.ti.button32.background: #444484
xcalc.ti.button33.background: #444484
xcalc.ti.button34.background: #444484
xcalc.ti.button37.background: #555595
xcalc.ti.button38.background: #555595
xcalc.ti.button39.background: #555595
XCalc*Cursor:                 hand2
XCalc*ShapeStyle:             rectangle

Color scheme commands

Here are some fast bash commands you can run right in your shell.

Display all 256 colors

Prints all 256 colors across the screen, very quick.

(x=`tput op` y=`printf %80s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done)

Display tput escape codes

Replace 'tput op' with whatever tput you want to trace. op is the default foreground and background color. Template:Command

Enumerating colors supported by terminals

The following command will let you discover all the terminals you have terminfo support for, and the number of colors each terminal supports. The possible values are: 8, 15, 16, 52, 64, 88 and 256. Template:Command

Enumerating terminal capabilities

This command is useful to see what features that are supported by your terminal. Template:Command

Color scheme scripts

Any of the following scripts will display a chart of your current terminal color scheme. Handy for testing and whatnot.

Script #1

#   This file echoes a bunch of color codes to the 
#   terminal to demonstrate what's available.  Each 
#   line is the color code of one forground color,
#   out of 17 (default + 16 escapes), followed by a 
#   test use of that color on all nine background 
#   colors (default + 8 escapes).

T='gYw'   # The test text

echo -e "\n                 40m     41m     42m     43m\
     44m     45m     46m     47m";

for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' \
           '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' \
           '  36m' '1;36m' '  37m' '1;37m';
  do FG=${FGs// /}
  echo -en " $FGs \033[$FG  $T  "
  for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
    do echo -en "$EINS \033[$FG\033[$BG  $T  \033[0m";

Script #2

# Original: http://frexx.de/xterm-256-notes/
#           http://frexx.de/xterm-256-notes/data/colortable16.sh
# Modified by Aaron Griffin
# and further by Kazuo Teramoto
FGNAMES=(' black ' '  red  ' ' green ' ' yellow' '  blue ' 'magenta' '  cyan ' ' white ')

echo "     ┌──────────────────────────────────────────────────────────────────────────┐"
for b in {0..8}; do
  ((b>0)) && bg=$((b+39))

  echo -en "\033[0m ${BGNAMES[b]} │ "
  for f in {0..7}; do
    echo -en "\033[${bg}m\033[$((f+30))m ${FGNAMES[f]} "
  echo -en "\033[0m │"
  echo -en "\033[0m\n\033[0m     │ "
  for f in {0..7}; do
    echo -en "\033[${bg}m\033[1;$((f+30))m ${FGNAMES[f]} "

  echo -en "\033[0m │"
  echo -e "\033[0m"

  ((b<8)) &&
  echo "     ├──────────────────────────────────────────────────────────────────────────┤"
echo "     └──────────────────────────────────────────────────────────────────────────┘"

Script #3

# Original: http://frexx.de/xterm-256-notes/
#           http://frexx.de/xterm-256-notes/data/colortable16.sh
# Modified by Aaron Griffin
# and further by Kazuo Teramoto

FGNAMES=(' black ' '  red  ' ' green ' ' yellow' '  blue ' 'magenta' '  cyan ' ' white ')
echo "     ----------------------------------------------------------------------------"
for b in $(seq 0 8); do
    if [ "$b" -gt 0 ]; then

    echo -en "\033[0m ${BGNAMES[$b]} : "
    for f in $(seq 0 7); do
      echo -en "\033[${bg}m\033[$(($f+30))m ${FGNAMES[$f]} "
    echo -en "\033[0m :"

    echo -en "\033[0m\n\033[0m     : "
    for f in $(seq 0 7); do
      echo -en "\033[${bg}m\033[1;$(($f+30))m ${FGNAMES[$f]} "
    echo -en "\033[0m :"
        echo -e "\033[0m"
  if [ "$b" -lt 8 ]; then
    echo "     ----------------------------------------------------------------------------"
echo "     ----------------------------------------------------------------------------"

Script #4

#!/usr/bin/env lua

function cl(e)
	return string.format('\27[%sm', e)

function print_fg(bg, pre)
	for fg = 30,37 do
		fg = pre..fg
		io.write(cl(bg), cl(fg), string.format(' %6s ', fg), cl(0))

for bg = 40,47 do
	io.write(cl(0), ' ', bg, ' ')
	print_fg(bg, '')
	io.write('\n    ')
	print_fg(bg, '1;')

-- Andres P

Contributed examples

Check out these links for some real world examples of Xdefaults, contributed by fellow community members. Note that Xdefaults has the same syntax as Xresources.

More resources