X 资源
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 提供