X 資源 文件 是一個用戶級配置點文件,通常位於 ~/.Xresources
。
它可用於設置X 資源,即 X 客戶端程序的配置參數。
除其他用途外,它們可用於:
- 配置終端首選項(如終端顏色)
- 設置 DPI、抗鋸齒、hinting 和其他 X 字體設置
- 更改 Xcursor 主題
- 主題 XScreenSaver
- 配置低級 X 應用程式,如 xorg-xclock包、xpdf包、rxvt-unicode)
安裝
安裝 xorg-xrdb包 軟體包來獲得 X 伺服器資源資料庫工具,安裝 xorg-docs包 來獲得 X.org 文檔。
Configuration
X(7) § RESOURCES and XrmGetDatabase(3) § FILE SYNTAX provide detailed information on X resources mechanism and file syntax.
~/.Xresources
is a conventional file name, xrdb
does not claim it. You can use any other file names, like ~/.config/X11/Xresources
and ~/.config/X11/Xresources.d/application-name
(also see #Samples and #Include files).
Basic syntax
The syntax of an X resources file is a sequence of resource lines as follows:
application_name.Class.resourceName: value application_name.resourceName: value Class.resourceName: value application_name*resourceName: value *resourceName: value
application_name
and Class
substrings will never contain a dot (.
), the resourceName
substring may contain a dot. For example, Dialog.bodyFont
is a XScreenSaver internal resource that is specified to set the body font and fallback font:
xscreensaver-auth.default.Dialog.bodyFont: times new roman 12, dejavu serif 12
- application_name
- The name of the application, such as
urxvt
,xpdf
,xterm
, etc. Also may be called the instance name.
- Class
- The classification used to group resources together. Class names are typically uppercase.
- resourceName
- The name of the resource whose value is to be set. Resources are typically lowercase with uppercase concatenation.
- value
- The actual value of the resource. This can be one of three 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 a tight binding and is used to separate immediately adjacent components (in other words, to signify each step down into the hierarchy) — in the above example we start at application name, then descend into Class, and finally into the resource itself. - An asterisk (
*
) is a loose binding and is used to represent any number of components, including none. - A colon (
:
) is used to separate the resource name from the value.
- From resource file syntax point of view, everything before a colon (
:
) is a resource name. From the user perspective, we often call resource only the rightmost component. In other words, resource name is a string consisted of application name, Class and resource name substrings. That might be the source of confusion. - Resource naming schema is totally application-dependent. While one application might use
application_name.Class.resourceName
, another might understandapplication_name.resourceName
andClass.resourceName
only.
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
- Question mark (
?
) is like component name, so binding character — dot (.
) or asterisk (*
) — next to it is required. - Asterisk (
*
) is a binding character itself, there is no need in placing dot next to it, and a sequence of dot(s) and asterisk(s) is replaced with a single asterisk during file processing.
See XrmGetResource(3) § MATCHING RULES for more information.
Comments
Lines starting with an exclamation mark (!
) are ignored, for example:
! The following rule will be ignored because it has been commented out !Xft.antialias: true
- The exclamation mark must be the first character on the line.
- If you have a C preprocessor, such as GNU CPP (gcc包), installed you can use C-style (
//
and/* … */
) comments (also see #Samples).
Include files
To spread resource configuration across multiple files (e.g. to use its own file for each application), use C preprocessor #include
directive:
~/.config/X11/Xresources
#include "Xresources.d/fonts" #include "Xresources.d/rxvt-unicode" #include "Xresources.d/xscreensaver" #include "Xresources.d/xterm"
If files that are referenced with #include are not reachable from the applied configuration file directory, you need to pass a directory to search for:
$ xrdb -load -I${HOME}/.config/X11 ~/.Xresources
Default settings
To see the default settings for your installed X11 applications, look in /usr/share/X11/app-defaults/
.
Detailed information on program-specific resources is usually provided in the man page for the program. xterm(1) § RESOURCES 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
Samples
- Color output in console#Terminal emulators
- Cursor themes#X resources
- Font configuration#Applications without fontconfig support
- rxvt-unicode#Configuration
- xpdf(1) § OPTIONS
- Xterm#Configuration
- klassiker (mrdotx) — Rxvt-unicode patch developer dotfiles
用法
加載資源文件
資源存儲在 X 伺服器中,因此只需讀取一次。遠程X11 客戶端(如通過 SSH 轉發)也可以訪問這些資源。
加載資源文件(如傳統的 .Xresources
),替換任何當前設置:
$ xrdb ~/.Xresources
加載資源文件,並與當前設置合併:
$ xrdb -merge ~/.Xresources
xinitrc
如果使用默認的 xinitrc 副本作為 .xinitrc
,它已經合併了 ~/.Xresources
。
如果您使用的是自定義的,請添加:
.xinitrc
[[ -f ~/.Xresources ]] && xrdb -merge -I$HOME ~/.Xresources
~/.xinitrc
中設置 xrdb 命令的後台。否則,在 xrdb 之後啟動的程序可能會在加載完成前查找資源。獲取資源值
如果要獲取某個資源的值(例如在 bash 腳本中使用),可以使用 xgetresAUR:
$ xgetres xscreensaver.Dialog.headingFont -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1
Troubleshooting
Parsing errors
Display managers such as GDM may use the --nocpp
argument for xrdb.
No output from xrdb -query
It is not rare for xrdb -query
to output nothing. Try following #Load resource file and #xinitrc from above. And note some of the files mentioned there could be empty.
參見
- Using the .Xdefaults File 由 Purdue Engineering Computer Network 提供
- Overlooked Points of X Resources 由 Thomas Dickey 提供