Difference between revisions of "X resources"

From ArchWiki
Jump to: navigation, search
m (i18n template update)
(wikilink xscreensaver, move terminal colors under term preferences)
 
(212 intermediate revisions by 59 users not shown)
Line 1: Line 1:
{{i18n|Xdefaults}}
+
[[Category:Configuration files]]
 +
[[Category:X server]]
 
[[de:Xdefaults]]
 
[[de:Xdefaults]]
[[Category:Dotfiles (English)]]
+
[[ja:X resources]]
[[Category:X Server (English)]]
+
[[ru:X resources]]
[[Category:HOWTOs (English)]]
+
{{Related articles start}}
 +
{{Related|X Logical Font Description}}
 +
{{Related|dotfiles}}
 +
{{Related articles end}}
 +
'''Xresources''' is a user-level configuration ''dotfile'', typically located at {{ic|~/.Xresources}}.
 +
It can be used to set [[Wikipedia:X resources|X resources]], which are configuration parameters for X client applications.
  
'''Xdefaults''' is a user-level configuration ''dotfile'', typically located at {{Filename|~/.Xdefaults}}. When present, it is parsed by the {{Codeline|xrdb}} (Xorg resource database) program automatically when [[Xorg]] is started, and can be used to set or override preferences for X and X applications. It can do many operations, including:
+
Among other things they can be used to:
* 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.)
 
  
==Getting started==
+
* configure terminal preferences (e.g. terminal colors)
 +
* set DPI, anti-aliasing, hinting and other X font settings
 +
* change the Xcursor theme
 +
* theme [[XScreenSaver]]
 +
* configure low-level X applications like: {{Pkg|xorg-xclock}}, {{Pkg|xpdf}}, [[rxvt-unicode]]
  
===Creating .Xdefaults===
+
== Installation ==
The file {{Filename|~/.Xdefaults}} does not exist by default. To create it, open a terminal and type the following as a normal user:
 
$ touch ~/.Xdefaults
 
Being a plain-text file, you can edit your {{Filename|~/.Xdefaults}} file with the text editor of your choice.
 
  
===Default settings===
+
[[Install]] the {{pkg|xorg-xrdb}} package.
To see the default settings for your installed X11 apps, look in {{Filename|/usr/share/X11/app-defaults/}}.
 
  
===Xdefaults syntax===
+
== Usage ==
====The basic syntax====
 
The syntax of an Xdefaults file is as follows:
 
'''name.Class.resource: value'''
 
and here is a real world example:
 
xscreensaver.Dialog.headingFont: -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1
 
  
;name
+
=== Load resource file ===
:The name of the application, such xterm, xpdf, etc
 
  
;class
+
Resources are stored in the X server, so have to only be read once. They are also accessible to ''remote'' X11 clients (such as those [[Secure_Shell#X11_forwarding|forwarded over SSH]]).
:The classification used to group resources together. Class names are typically uppercase.
 
  
;resource
+
Load a resource file (such as the conventional {{ic|.Xresources}}), replacing any current settings:
:The name of the resource whose value is to be changed. Resources are typically lowercase with uppercase concatenation.
 
  
;value
+
$ xrdb ''~/.Xresources''
: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))
 
  
;delimiters
+
Load a resource file, and merge with the current settings:
: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====
+
$ xrdb -merge ''~/.Xresources''
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:
+
{{Note|
'''*'''Dialog.headingFont:    -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1
+
* Most [[Display manager]]s load the {{ic|~/.Xresources}} file on login.
 +
* The older {{ic|~/.Xdefaults}} file is read when an X11 program starts, but only if ''xrdb'' has not been used in the current session. [https://groups.google.com/forum/#!msg/comp.windows.x/hQBEdql8l-Q/hF3DETcIHGwJ]
 +
}}
  
If you want to apply this same rule to all programs that contain the resource ''headingFont'' regardless of its class, you would write:
+
=== xinitrc ===
'''*'''headingFont:    -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1
 
  
====Commenting====
+
If you are using a copy of the default [[xinitrc]] as your {{ic|.xinitrc}} it already merges {{ic|~/.Xresources}}.
To add a comment to your Xdefaults 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
+
If you are using a custom {{ic|.xinitrc}} add the following line:
!xft.antialias:       true
 
  
==Sample usage==
+
<nowiki>[[ -f ~/.Xresources ]] && xrdb -merge -I$HOME ~/.Xresources</nowiki>
The following samples should provide a good understanding of how application settings can be modified using an Xdefaults file. For full details, refer to the man page of the application in question.
 
  
===File header===
+
{{Note|Do not background the xrdb command within {{ic|~/.xinitrc}}. Otherwise, programs launched after xrdb may look for resources before it has finished loading them.}}
If desired, you can add a header to {{Filename|~/.Xdefaults}} which not only explains the file's contents, but also instruct vim how to perform syntax highlighting and other formatting. For example:
 
<pre>
 
! ----------------------------------------------------------------------------
 
! file:    ~/.Xdefaults
 
! author:  Thayer Williams - http://cinderwick.ca
 
! modified: November 2008
 
! vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=xdefaults:
 
! ----------------------------------------------------------------------------
 
</pre>
 
  
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".
+
=== Default settings ===
  
It is a good habit to get into, especially if you'd like to make your dotfiles available for public consumption.
+
To see the default settings for your installed X11 apps, look in {{ic|/usr/share/X11/app-defaults/}}.
  
===Terminal colors===
+
Detailed information on program-specific resources is usually provided in the man page for the program. xterm's man page is a good example, as it contains a list of X resources and their default values.
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, etc.)
+
To see the currently loaded resources:
<pre>
 
! terminal colors ------------------------------------------------------------
 
  
! tangoesque scheme
+
  $ xrdb -query -all
*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
 
</pre>
 
  
For more examples of color schemes, see the [[#More resources]] section at the bottom of this article.
+
===Xresources syntax===
  
===Desktop preferences===
+
====Basic syntax====
  
====Xcursor settings====
+
The syntax of an Xresources file is as follows:
Set the theme and size of your mouse cursor:
+
'''name.Class.resource: value'''
<pre>
+
and here is a real world example:
! Xcursor --------------------------------------------------------------------
+
xscreensaver.Dialog.headingFont: -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1
  
Xcursor*theme: Vanilla-DMZ-AA
+
;name
Xcursor.size: 22
+
:The name of the application, such as xterm, xpdf, etc
</pre>
 
Available themes reside in {{Filename|/usr/share/icons}} and local themes can be installed to {{Filename|~/.icons}}.
 
  
====Xft Font Settings====
+
;class
You can define basic font settings without the need of a {{Filename|fonts.conf}} file or Desktop Environment. Note however, the use of a desktop environment and/or {{Filename|fonts.conf}} can override these settings. Your best option is to use one or the other, but not both.
+
:The classification used to group resources together. Class names are typically uppercase.
<pre>
 
! Xft settings ---------------------------------------------------------------
 
  
Xft.dpi:        96
+
;resource
Xft.antialias: true
+
:The name of the resource whose value is to be changed. Resources are typically lowercase with uppercase concatenation.
Xft.rgba:      rgb
 
Xft.hinting:    true
 
Xft.hintstyle:  hintslight
 
</pre>
 
  
===xterm preferences===
+
;value
This will open Xterm in an 80x25 character window with a scroll-bar and scroll capability for the last 512 lines.
+
: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 ({{ic|white}}), a color ({{ic|#ffffff}}), or a path ({{ic|/usr/bin/firefox}}))
  
The specified [[Fonts#Terminal|Terminus]] facename is a popular and clean terminal font.
+
;delimiters
<pre>
+
:A dot ({{ic|'''.'''}}) 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 ({{ic|''':'''}}) is used to separate the resource declaration from the actual value.
! xterm ----------------------------------------------------------------------
 
  
xterm*geometry:          80x25
+
{{Note|For more information about Xresources file syntax see {{man|3|XrmGetDatabase|FILE_SYNTAX}}.}}
xterm*faceName:          terminusbold: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
 
</pre>
 
  
===urxvt preferences===
+
====Wildcard matching====
Rxvt-unicode features an extensive list of options which can be configured via Xdefaults. Refer to the [[urxvt]] man page for details.
 
<pre>
 
! rxvt-unicode ---------------------------------------------------------------
 
  
! font preference
+
Question mark ({{ic|?}}) and asterisk ({{ic|*}}) can be used as wildcards, making it easy to write a single rule that can be applied to many different applications or elements. {{ic|?}} is used to match any single component name, while {{ic|*}} is used to represent any number of intervening components including none.
urxvt*font:      -*-terminus-*-*-*-*-*-*-*-*-*-*-*-*
 
urxvt*boldFont:  -*-terminus-*-*-*-*-*-*-*-*-*-*-*-*
 
!initial size
 
urxvt*geometry:          120x35
 
!internal whitespace
 
urxvt*internalBorder:    5
 
!fade text n% upon unfocus
 
urxvt*fading:            20
 
!darken=(0 to 100) lighten=(-1 to -100)
 
urxvt*shading:            30
 
!tint background with this color
 
urxvt*tintColor:          black
 
!set to 32-bit for real transparency (compositing required)
 
!urxvt*depth:            24
 
!save n lines of scrollback buffer
 
urxvt*saveLines:          32767
 
!flash screen for attention
 
urxvt*visualBell:        true
 
!jump to bottom (prompt) on keypress
 
urxvt*scrollTtyKeypress:  true
 
!jump to bottom (prompt) when tty gets new lines
 
urxvt*scrollWithBuffer:  false
 
!jump to bottom (prompt) on tty output
 
urxvt*scrollTtyOutput:    false
 
!toggle scrollbar
 
urxvt*scrollBar:          false
 
!scrollbar styles: rxvt, plain, next or xterm
 
urxvt*scrollstyle:        plain
 
!scrollbar alignment
 
urxvt*scrollBar_right:    true
 
urxvt*scrollColor:        #777777
 
urxvt*cursorColor:        #ffcc00
 
!enable pseudo-transparency (requires depth: 24 (see above))
 
urxvt*inheritPixmap:      true
 
!delimiters for double-click mouse selection
 
urxvt*cutchars:          "()*,<>[]{}|'
 
!screen dump settings
 
urxvt*print-pipe:        cat > $(echo urxvt.dump.$(date +'%Y%M%d%H%m%S'))
 
!secondary screen scroll (default enabled)
 
urxvt*secondaryScroll:    true
 
!de-iconify (map) on receipt of a bell character
 
urxvt*mapAlert:          true
 
!inhibit writing record into the system log file utmp
 
urxvt*utmpInhibit:        true
 
!! BEGIN urlLauncher settings !!
 
urxvt*perl-lib:          /usr/lib/urxvt/perl/
 
urxvt*perl-ext-common:    default,matcher
 
urxvt*urlLauncher:        /usr/bin/firefox
 
urxvt*matcher.button:    1
 
!! END urlLauncher settings !!
 
  
!transparent=0000 opaque=ffff
+
Using the previous example, if you want to apply the same font to all programs (not just XScreenSaver) that contain the class name {{ic|Dialog}} which contains the resource name {{ic|headingFont}}, you could write:
urxvt*background: rgba:1111/1111/1111/dddd
 
</pre>
 
  
===aterm preferences===
+
'''?'''.Dialog.headingFont:    -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1
Sample settings for aterm (very similar to urxvt)
 
<pre>
 
!aterm settings-------------------------------------------------------------   
 
  
aterm*background:               black
+
If you want to apply this same rule to all programs that contain the resource {{ic|headingFont}}, regardless of its class, you could write:
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 
 
</pre>
 
  
===xpdf preferences===
+
'''*'''headingFont:   -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1
Some basic settings for '''xpdf''', a lightweight PDF viewer:
 
<pre>
 
! xpdf -----------------------------------------------------------------------
 
  
xpdf*enableFreetype:    yes
+
For more information about wildcard matching rules see {{man|3|XrmGetResource|MATCHING_RULES}}.
xpdf*antialias:        yes
 
xpdf*foreground:        black
 
xpdf*background:        white
 
xpdf*urlCommand:        /usr/bin/firefox %s
 
</pre>
 
Anything more detailed than the above you should be putting in {{Filename|~/.xpdfrc}} instead. See {{Codeline|xpdf}} man page for more information. ''Note:'' viKeys is deprecated.
 
  
===lal clock===
+
==== Commenting ====
<pre>
 
! lal clock ------------------------------------------------------------------
 
  
lal*font:      Arial
+
To add a comment to your Xresources file, simply prefix it with an exclamation mark ({{ic|!}}), for example:
lal*fontsize:  12
 
lal*bold:      true
 
lal*color:      #ffffff
 
lal*width:      150
 
lal*format:    %a %b %d %l:%M%P
 
</pre>
 
  
===xclock preferences===
+
  ! The following rule will be ignored because it has been commented out
Some basic '''xclock''' settings. See xclock man page for all X resources.
+
  !Xft.antialias:       true
<pre>
 
  ! xclock ---------------------------------------------------------------------
 
 
 
xclock*update:            1
 
xclock*analog:            false
 
xclock*Foreground:        white
 
xclock*background:        black
 
</pre>
 
 
 
===x11-ssh-askpass===
 
<pre>
 
! 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
 
</pre>
 
 
 
===xscreensaver theming===
 
A sample '''xscreensaver''' theme.  For more information, refer to the xscreensaver man page. [http://www.flickr.com/photos/cinderwick/2685038363/ View] the resulting theme.
 
<pre>
 
! 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.internalBorderWidth:24
 
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
 
</pre>
 
 
 
===xcalc preferences===
 
Some '''xcalc''' settings to colorize and customize buttons.
 
<pre>
 
!xcalc-----------------------------------------------------------------------
 
 
 
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
 
</pre>
 
 
 
==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===
 
<pre>
 
#!/bin/bash
 
#
 
#  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";
 
  done
 
  echo;
 
done
 
echo
 
</pre>
 
 
 
===Script #2===
 
<pre>
 
#!/bin/bash
 
# 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 ')
 
BGNAMES=('DFT' 'BLK' 'RED' 'GRN' 'YEL' 'BLU' 'MAG' 'CYN' 'WHT')
 
 
 
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]} "
 
  done
 
 
 
  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]} "
 
  done
 
  
  echo -en "\033[0m │"
+
==== Include files ====
  echo -e "\033[0m"
+
{{Note|You need to have a C preprocessor, such as {{ic|GNU CPP}}, installed to use this functionality.}}
  
  ((b<8)) &&
+
To use different files for each application, use {{ic|#include}} in the main file. For example:
  echo "    ├──────────────────────────────────────────────────────────────────────────┤"
 
done
 
echo "    └──────────────────────────────────────────────────────────────────────────┘"
 
</pre>
 
  
===Script #3===
+
{{hc|~/.Xresources|
<pre>
+
#include ".Xresources.d/xterm"
#!/bin/bash
+
#include ".Xresources.d/rxvt-unicode"
# Original: http://frexx.de/xterm-256-notes/
+
#include ".Xresources.d/fonts"
#           http://frexx.de/xterm-256-notes/data/colortable16.sh
+
#include ".Xresources.d/xscreensaver"
# Modified by Aaron Griffin
+
}}
# and further by Kazuo Teramoto
 
  
 +
If files fail to load, specify the directory to ''xrdb'' with the {{ic|-I}} parameter. For example:
  
FGNAMES=(' black ' '  red  ' ' green ' ' yellow' '  blue ' 'magenta' '  cyan ' ' white ')
+
{{hc|~/.xinitrc|
BGNAMES=('DFT' 'BLK' 'RED' 'GRN' 'YEL' 'BLU' 'MAG' 'CYN' 'WHT')
+
xrdb -I''$HOME'' ~/.Xresources
echo "    ----------------------------------------------------------------------------"
+
}}
for b in $(seq 0 8); do
 
    if [ "$b" -gt 0 ]; then
 
      bg=$(($b+39))
 
    fi
 
  
    echo -en "\033[0m ${BGNAMES[$b]} : "
+
=== Getting resource values ===
    for f in $(seq 0 7); do
 
      echo -en "\033[${bg}m\033[$(($f+30))m ${FGNAMES[$f]} "
 
    done
 
    echo -en "\033[0m :"
 
  
    echo -en "\033[0m\n\033[0m    : "
+
If you want to get the value of a resource (for example if you want to use it in a bash script) you can use {{AUR|xgetres}}:
    for f in $(seq 0 7); do
 
      echo -en "\033[${bg}m\033[1;$(($f+30))m ${FGNAMES[$f]} "
 
    done
 
    echo -en "\033[0m :"
 
        echo -e "\033[0m"
 
       
 
  if [ "$b" -lt 8 ]; then
 
    echo "    ----------------------------------------------------------------------------"
 
  fi
 
done
 
echo "    ----------------------------------------------------------------------------"
 
</pre>
 
  
===Script #4===
+
$ xgetres xscreensaver.Dialog.headingFont
<pre>
+
-*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1
#!/usr/bin/env lua
 
  
local function cl(e)
+
== Sample usage ==
    return ('\27[%sm'):format(e)
+
The following samples should provide a good understanding of how application settings can be modified using an Xresources file. See [https://gist.github.com/anonymous/fa98de9fd70b51611303] for more examples. Refer to the man page of the application in question otherwise.
end
 
  
local function print_fg(bg, pre)
+
* [[Color output in console#Terminal emulators]]
    for fg = 30,37 do
+
* [[Cursor themes#X resources]]
        fg = pre..fg
+
* [[Font configuration#Applications without fontconfig support]]
        io.write(cl(bg), cl(fg), (' %6s '):format(fg), cl(0))
+
* [[Xterm#Configuration]]
    end
+
* [[rxvt-unicode#Configuration]]
end
+
* {{man|1|xpdf|OPTIONS}}
  
for bg = 40,47 do
+
== Troubleshooting ==
    io.write(cl(0), ' ', bg, ' ')
 
    print_fg(bg, '')
 
    io.write('\n    ')
 
    print_fg(bg, '1;')
 
    print('\n')
 
end
 
  
-- Andres P
+
=== Parsing errors ===
</pre>
 
  
==Contributed .Xdefaults==
+
[[Display manager]]s such as [[GDM]] may use the {{ic|--nocpp}} argument for ''xrdb''.
Check out these links for some real world examples of Xdefaults, contributed by fellow community members:
 
  
http://dotfiles.org/~buttons/.Xdefaults<br/>
+
==See also==
http://code.suckless.org/hg/dextra/file/513faba2591f/dolby/Xdefaults<br/>
 
http://github.com/stxza/arch-linux-configs/tree/master/.Xdefaults<br/>
 
http://dotfiles.org/~wraith/.Xdefaults<br/>
 
http://dotfiles.org/~tdy/.Xdefaults<br/>
 
http://github.com/jelly/dotfiles/tree/master/.Xdefaults<br/>
 
  
==More resources==
 
* [http://phraktured.net/terminal-colors/ Terminal Color Schemes]- a gallery of terminal color schemes by our very own Aaron Griffin
 
* [http://gentoo-wiki.com/TIP_Linux_Colors_in_Aterm/rxvt TIP Linux Colors in Aterm/rxvt] - Gentoo wiki article with loads of information
 
 
* [https://engineering.purdue.edu/ECN/Support/KB/Docs/UsingTheXdefaultsFil Using the Xdefaults File] - An in-depth article on how X interprets the Xdefaults file
 
* [https://engineering.purdue.edu/ECN/Support/KB/Docs/UsingTheXdefaultsFil Using the Xdefaults File] - An in-depth article on how X interprets the Xdefaults file
* [http://wiki.afterstep.org/index.php?title=Rxvt-Unicode_Configuration_Tutorial Rxvt-unicode Configuration Tutorial] - lots of information for urxvt users
 
* [http://mkaz.com/ref/xterm_colors.html Available Colors and their names] - listing of available colors and their color names for xterm and other X-applications.
 

Latest revision as of 14:50, 28 April 2018

Xresources is a user-level configuration dotfile, typically located at ~/.Xresources. It can be used to set X resources, which are configuration parameters for X client applications.

Among other things they can be used to:

  • configure terminal preferences (e.g. terminal colors)
  • set DPI, anti-aliasing, hinting and other X font settings
  • change the Xcursor theme
  • theme XScreenSaver
  • configure low-level X applications like: xorg-xclock, xpdf, rxvt-unicode

Installation

Install the xorg-xrdb package.

Usage

Load resource file

Resources are stored in the X server, so have to only be read once. They are also accessible to remote X11 clients (such as those forwarded over SSH).

Load a resource file (such as the conventional .Xresources), replacing any current settings:

$ xrdb ~/.Xresources

Load a resource file, and merge with the current settings:

$ xrdb -merge ~/.Xresources
Note:
  • Most Display managers load the ~/.Xresources file on login.
  • The older ~/.Xdefaults file is read when an X11 program starts, but only if xrdb has not been used in the current session. [1]

xinitrc

If you are using a copy of the default xinitrc as your .xinitrc it already merges ~/.Xresources.

If you are using a custom .xinitrc add the following line:

[[ -f ~/.Xresources ]] && xrdb -merge -I$HOME ~/.Xresources
Note: Do not background the xrdb command within ~/.xinitrc. Otherwise, programs launched after xrdb may look for resources before it has finished loading them.

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 the program. xterm's man page is a good example, as it contains a list of X resources and their default values.

To see the currently loaded resources:

$ xrdb -query -all

Xresources syntax

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
name
The name of the application, such as xterm, xpdf, etc
class
The classification used to group resources together. Class names are typically uppercase.
resource
The name of the resource whose value is to be changed. Resources are typically lowercase with uppercase concatenation.
value
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))
delimiters
A dot (.) 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.
Note: For more information about Xresources file syntax see XrmGetDatabase(3).

Wildcard matching

Question mark (?) and asterisk (*) can be used as wildcards, making it easy to write a single rule that can be applied to many different applications or elements. ? is used to match any single component name, while * is used to represent any number of intervening components including none.

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 could 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 could write:

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

For more information about wildcard matching rules see XrmGetResource(3).

Commenting

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

! The following rule will be ignored because it has been commented out
!Xft.antialias:        true

Include files

Note: You need to have a C preprocessor, such as GNU CPP, installed to use this functionality.

To use different files for each application, use #include in the main file. For example:

~/.Xresources
#include ".Xresources.d/xterm"
#include ".Xresources.d/rxvt-unicode"
#include ".Xresources.d/fonts"
#include ".Xresources.d/xscreensaver"

If files fail to load, specify the directory to xrdb with the -I parameter. For example:

~/.xinitrc
xrdb -I$HOME ~/.Xresources

Getting resource values

If you want to get the value of a resource (for example if you want to use it in a bash script) you can use xgetresAUR:

$ xgetres xscreensaver.Dialog.headingFont
-*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1

Sample usage

The following samples should provide a good understanding of how application settings can be modified using an Xresources file. See [2] for more examples. Refer to the man page of the application in question otherwise.

Troubleshooting

Parsing errors

Display managers such as GDM may use the --nocpp argument for xrdb.

See also