LinuxSir.cn,穿越时空的Linuxsir!

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

【翻译】如何使用 X RESOURCES

[复制链接]
发表于 2009-1-31 16:34:15 | 显示全部楼层 |阅读模式
希望对大家有帮助。
翻译的出发点,一是正好在找相关资料,一是,学习英文吧。
本人虽然是PG,但没上过大学,英语也是很差,翻译非常费时,边查单词边造句,太累了。不过感觉对学习英语没有太大帮助吧。

疑点;
1. Athena 不知道具体是什么,可能是某种软件/硬件平台吧
2. geometry?几何?不知如何翻译。

来源:http://web.mit.edu/answers/xwindows/xwindows_resources.html

译稿:
如何使用 X RESOURCES



● X-RESOURCES 文件是什么?

用户可以定制程序的外观,使用了 X 资源文件中的条目的 X 接口的程序。在 Athena 上,这个文件叫 .Xresources,为了能够工作,这个文件需要放在用户目录的最上层。定制内容举例来说,包括改变应用程序的 geometry 和尺寸大小,或者程序所用的颜色。



● 使用 X RESOURCES 我需要知道什么?

要使用你的 .Xresource 为某个程序定制资源,你首先要知道你想要定制的资源,以及这个程序的实例或类。

对于使用 X Toolkit intrinsics 编写的程序,其标准资源,请查阅 X 手册;对于程序的特定资源,请查阅该程序的手册。比如:要查找程序 "xterm" 的资源,你可以输入:

  man xterm

通常,一个 X 程序,它默认的实例就是它的名字,它的类,就是它的名字并且首字母大写,除非它的首字母是 "X",这种情况下,其前两个字母大写。比如:程序 "xterm" 的实例是 "xterm",类是 "XTerm",程序 "mwm","mwm" 作为实例,"Mwm" 作为类。

相对于使用传统方式的程序,不幸的事情是,许多 X 程序是非传统的。如果是这种情况,只要启动有疑问的 X 程序,在 unix 提示符下输入 "xprop",再然后点击这个程序。比如,在一个 "xterm" 窗口使用 xprop 会得到:

  WM_CLASS(STRING) = "xterm", "XTerm"



● 我应当如何使用 X RESOURCES?

在 .Xresources 文件中,条目有多种差异,但,是类似的,格式化的。说明所有的条目太费事。如果你需要比这里所说的更详细的信息,请查阅 X 手册。

通常,这些条目的形式如下:
  class*resource: value
  instance*resource: value
  class.resource: value
  instance.resource: value

资源设置的第一个元素可以是 "class(类)" 或者 "instance(实例)"。类包含了通过特定程序启动的所有,实例是一个给定特定名称的进程。

比如,XTerm 是一个类,所有你启动的 xterm,无论如何,他们都由这个类而来(这个类启动的所有资源都将被应用)。然而,你也可以像这样来启动 xterm:

  xterm -name xterm-big

这个处理将会产生一个 XTerm 类,但是实例却是 xterm-big。
因此,你可以像这样来创建资源:
  
  XTerm*reverseVideo:         on
  xterm*VT100.geometry:     80x24
  xterm-big*VT100.geometry: 80x48
  xterm-small*VT100.geometry: 80x10

这样,所有你启动的 xterm 的 reverse video 被设置为 on,但是使用 "-name xterm-big" 选项启动的,拥有一个 geometry,使用 "-name xterm-small" 选项启动的,拥有另一个,而没有指定名称的则默认名称为 xterm,也拥有一个不同的 geometry。(VT100 指明 geometry 用在主文本窗口,而不是菜单或子窗口。)

资源名称(如上面例子中的 'geometry')是 X 程序的特定外观属性。拼写资源名称是要小心。只有特定的拼写才正确。比如:'reverseVideo' 和 'ReverseVideo' 作为 xterm 资源而正确地起作用,而不是其它拼写。

其它例子:

        oneko*tora:true

        matlab*reverseVideo: false   ! matlab windows in "reverse video"

        emacs*Font: 8x13             ! 字体 8x13, 80 列
        emacs*geometry: 80x48+0+0    !  宽的, 48 行高

        XTerm*scrollBar: on             ! 带流动条
        XTerm*saveLines: 250             !   保存 250 行回溯

        XTerm*VT100.geometry:80x48+0+0  ! 仅主窗口 80x48

在这些例子中,"*" (宽松绑定) 和 "." (严格绑定) 之间的区别是,*会让资源应用到顶级窗口之内的所有子窗口(像菜单之类),点则只应用到程序的顶级窗口。



● 其它信息

-感叹号(!)用来在 .Xresources 文件中注释一行
-实例的优先级比类高。如果你为一个程序使用不同的值同时指定了类和实例,实例的资源将被使用,如:
        xterm*Background: blue

将被使用,代替:

        XTerm*Background: green

-要重新读入 .Xresources 文件,并且抛弃老的资源,你可以输入:

        xrdb ~/.Xresources

-要重新读入 .Xresources 文件,并保持原来的资源,输入:

        xrdb -merge ~/.Xresources

        这将合并资源到你当前正在使用的资源中。

-对于 Athena 程序,X 接口程序的默认资源被放在目录 /usr/athena/lib/X11/app-defaults.

-事实上,你并不需要通过程序的类或实例名称来作定制。比如,如果你想为所有 X 驱动的程序指定相同设置,只要加入:

        *resource: value

        到你的 .Xresources 文件中。

-避免在 .Xresources 文件的头部和尾部出现空格。

-输入 "attach dotfiles",查找 /mit/dotfiles/Xresources 目录,你可以找到 Xresource 文件的示例。

-你可以改变许多使用 -name 选项启动的 X 程序的实例。比如,你如果输入 "xterm -name XT1" 来启动一个 xterm 窗口,那么你可以在你的 .Xresources 文件中使用 "XT1" 来定制资源,就像这样:

        XT1*Background: yellow


原稿:
    How to use X RESOURCES

                       WHAT IS AN X-RESOURCES FILE?

Users can customize the look of programs that use an X interface with entries in an X resources file.  On Athena, this file is named .Xresources, and needs to reside at the top level of a user's home directory in order for it to work.  Examples of customizations include changing the geometry and size of an application, or the colors that the program uses.


                WHAT DO I NEED TO KNOW TO USE X RESOURCES?

To specify resources for a program using your .Xresources file, you first must know the resource you want to specify, and the program's instance or class. You can find the resources for a program by checking the X manual page, for standard resources that are used by programs written with the X Toolkit Intrinsics, and by checking that program's manual page, for resources specific to that program.  For example, to find the resources for the program "xterm," you would type:

        man xterm

By convention, the default instance for an X program is just its name, and the class is just its name with the first letter capitalized, unless the first letter is an "X," in which case the first two letters are capitalized.  For example, the "xterm" program's instance is "xterm" and its class is "XTerm," and the program "mwm" has "mwm" as an instance, and "Mwm" as a class.  

The unfortunate thing about finding out the class and instance of a given program is that by convention, many X programmers are unconventional.  If this is the case, just start up the X program in question, type "xprop" at a unix prompt, and then click in the window of the X program.  This will give you the class and instance of the program.  For example, using xprop on an "xterm" window gives:

        WM_CLASS(STRING) = "xterm", "XTerm"


                      HOW DO I USE X RESOURCES?

Entries in the .Xresources file have a variety of different, but similar, forms.  Explaining them all here would be take too much detail.  If you need more information than what is here, please read the X manual page.

Generally, the forms entries take on are:

        class*resource: value
        instance*resource: value
        class.resource: value
        instance.resource: value

The first element in a resource specification is either a "class" or an "instance".  A class consists of ALL the invocations of a particular program.  An instance is a process which is given a particular name.

For example, XTerm is a class.  All xterms you start up, no matter how they are started up fall under this class (and as such all the resources starting with this class will apply to it).  However, you can also start up an xterm like this:

        xterm -name xterm-big

This process will have a class of XTerm, but an instance of xterm-big.
So, you could create resources like this:

        XTerm*reverseVideo:               on
        xterm*VT100.geometry:       80x24
        xterm-big*VT100.geometry:   80x48
        xterm-small*VT100.geometry: 80x10

where EVERY xterm you start up will have reverse video on, but one started with the '-name xterm-big' option will have one geometry, one started with the '-name xterm-small' option will have another, and one started with no specific name will default to the name 'xterm' and have yet a different geometry. (The VT100 designation is used to indicate that the geometry is for the main text window, and not the menus or subwindows.)

The resource name (e.g. 'geometry' in your above example) is a particular aspect of an X program.  Be careful when spelling resource names.  Only particular spellings of resources are correct.  Example: 'reverseVideo' and 'ReverseVideo' will function correctly as xterm resources, but not other spellings.

Other examples are:

        oneko*tora: true

        matlab*reverseVideo: false   ! matlab windows in "reverse video"

        emacs*Font: 8x13             ! emacs with 8x13 font, 80 columns
        emacs*geometry: 80x48+0+0    !   wide, 48 columns high

        XTerm*scrollBar: on             ! Xterms with a scrollbar that
        XTerm*saveLines: 250             !   keep track of last 250 lines

        XTerm*VT100.geometry:80x48+0+0  ! Make only the main xterm
                                        !   window be 80x48


In these examples, the difference between the "*" (a loose binding) and the "." (a tight binding) is that the * causes the resource to be applied to all the children windows within the top-level window (such as menus), whereas the dot causes the resource to be applied only to the top-level window of the program.


                      MISCELLANEOUS INFORMATION
                                     
-The exclamation mark (!), is used to comment a line in the .Xresources file.

-Instance names are considered more specific than class names.  If you use both the class and instance names of a program to specify a resource with different values, the instance resource value will be used.  For example:

        xterm*Background: blue

will be used, instead of:

        XTerm*Background: green

-To re-read your .Xresources file, and throw away your old resources, you can type:

        xrdb ~/.Xresources

-To re-read your .Xresources file, and keep your old resources, type:

        xrdb -merge ~/.Xresources

-This will merge any new resources you've put in with the current resources you're using.

-For Athena programs, the default resources for programs with an X interface are kept in the directory /usr/athena/lib/X11/app-defaults.

-You don't actually need the class or instance name of a program to make a customization.  For example, if you wanted to make the same customization for all X-driven programs, you put an entry of the form:

        *resource: value

in your .Xresources file.

-Avoid blank spaces at the beginning and end of lines in the .Xresources file.

-You can find sample Xresources files by typing "attach dotfiles" and looking in the directory /mit/dotfiles/Xresources.

-You can change the instance of many X programs by starting them with the -name option.  For example, if you start an xterm window by typing "xterm -name XT1", then you can specify resources for it in your .Xresources file with "XT1,", like this:

        XT1*Background: yellow
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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