LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 572|回复: 0

##知识帖## how X11 programs obtain their resources, ,X11 程序如何寻找资源

[复制链接]
发表于 2010-9-4 10:25:12 | 显示全部楼层 |阅读模式
Let me just explain how X11 programs (provided that they have been
correctly written by the programmer) obtain their resources, taken
from the approximate and incomplete sequence described in
the O'Reilly book "X User Tools" by Mui and Vercia

When the X11 program starts up it looks for entries in a file whose name is
the "class" of the application -- for rxvt, the class is Rxvt --
可以运行xprop 查看一个Gui 程序的WM_CLASS值,其中第二个值就是它的Class (第一个是instance )
WM_CLASS(STRING) = "urxvt", "URxvt"
比如urxvt 相应的class=URxvt ,instance=urxvt
下面以urxvt 为例


NB in each case below, replace class with the actual class name eg URxvt

1) in the file /usr/lib/$LANG/app-defaults/class if it exists
首先寻找是否存在 /usr/lib/$LANG/app-defaults/class,
比如针对urxvt 寻找路径是/usr/lib/zh_CN.UTF-8/app-defaults/URxvt ,

2) in the file /usr/lib/X11/app-defaults/class if it exists
or on many systems in the file /etc/X11/app-defaults/class if it exists
接下来寻找 /usr/lib/X11/app-defaults/URxvt
许多系统上可能寻找:/etc/X11/app-defaults/class


3) if the environmental variable XUSERFILESEARCHPATH is set,
then it looks for the file $XUSERFILESEARCHPATH/class
然后查看$XUSERFILESEARCHPATH是否设置了,若设置了则查看
$XUSERFILESEARCHPATH/URxvt 文件

4) if the environmental variable XAPPLRESDIR is set,
then it looks for the file $XAPPLRESDIR/$LANG/class
otherwise for the file $XAPPLRESDIR/class
otherwise for the file $HOME/$LANG/class
otherwise for the file $HOME/class
然后如果有$XAPPLRESDIR
接着寻找$XAPPLRESDIR/zh_CN.UTF-8/URxvt
                 $XAPPLRESDIR/URxvt
                 $HOME/zh_CN.UTF-8/URxvt
                 $HOME/URxvt
5) then it checks in the X server display RESOURCE_MANAGER property
resources are added to this using the command
xrdb - merge apps_default_file
To see what is present in RESOURCE_MANAGER user
xrdb -q

找到以上资源 会用这条命令将这些文件中的配置合并到 RESOURCE_MANAGER
xrdb - merge apps_default_file
可以用xrdb -q 查询刚刚合并进去的信息


6) then it checks in the file $HOME/.Xdefaults if it exists
然后检查$HOME/.Xdefaults   文件是否存在
在这个文件中以URxvt开头的信息都是关于urxvt 的配置

7) then it checks to see if the variable $XENVIRONMENT points to a file
and looks in that file
然后寻找 $XENVIRONMENT 指向的文件

8) if XENVIRONMENT has not been set, then it checks for
$HOME/.Xdefaults-hostname
若$XENVIRONMENT 不存在,继续寻找$HOME/.Xdefaults-localhost

9) then it processes any command line options which always override
any of the settings above eg - fg color or -xrm 'Rxvt*foreground: color'
然后用这个文件里的配置覆盖前那些文件的配置
比如Rxvt*foreground: #000000


So my advise to you is rather than mess up what you have in the installed
system applications defaults directory /etc/X11/app-defaults (but you
can do so if you wish, its your system) created a directory

mkdir -p /usr/local/X11R6/app-defaults

and put your customized app-defaults in there, like the Rxvt file I sent you, and set the environmental variable XAPPLRESDIR to point to that directory

So if you are using sh, bash, or ksh as your login shell
put the following lines in your $HOME/.profile

if [ -n "${DISPLAY}" ]
then
XAPPLRESDIR="/usr/local/X11R6/app-defaults"
export XAPPLRESDIR
fi

or if your login shell is csh or tcsh,
put the following lines in your $HOME/.cshrc or $HOME/.tcshrc
(as appropriate)

if (${?DISPLAY} == 1) setenv XAPPLRESDIR "/usr/local/X11R6/app-defaults"

Once that is done, and you have sourced your .profile or .cshrc or
.tcshrc, then you will be able to fire up rxvt and it will read the defaults.

Again, I draw your attention to what I already described above as
to how to get color scheme specific versions of rxvt with applications
running in them

eg rxvt -name vi -e vi

and how to set up aliases for them in your .profile for the Bourne, Korn,
or Bash login shell.

So do you understand what is happening now when you fire up an
X11 application and how to set its application defaults resources?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表