X环境中的窗口管理器与Shell环境配置
1. 窗口管理器概述
窗口管理器在X环境中至关重要,它直接影响用户对X环境的整体观感和使用体验。窗口管理器由Xsession脚本直接或间接启动(如CDE环境由dtsession脚本启动),其配置由启动的rc文件决定。下面将介绍两种常用的窗口管理器:Motif Window Manager(mwm)和CDE Window Manager(dtwm)。
1.1 Motif Window Manager(mwm)
mwm是较旧的窗口管理器。系统有一个全局的mwm配置文件system.mwmrc,更准确地说,它是默认的窗口管理器配置文件。X的工作方式是按顺序在多个可能的位置搜索配置文件,从用户主目录开始,直到找到系统全局的默认配置文件,第一个找到的文件将用于配置窗口管理器。
建议管理员将默认配置文件system.mwmrc复制到用户主目录下的.mwmrc,让用户有机会进行个性化修改。否则,X将使用默认配置文件(通常在/usr/lib/X11目录下的system.mwmrc),而不会有任何个性化定制。实际上,大多数用户不会修改个人配置,因此通常使用系统全局的默认设置。
以下是一个系统全局mwm配置文件的示例:
$ cat /usr/lib/X11/system.mwmrc
#
# DEFAULT mwm RESOURCE DESCRIPTION FILE (system.mwmrc and .mwmrc)
#
# menu pane descriptions
# Root Menu Description => The "Root Menu" is invoked by clicking in the root window
(see the Button Bindings description). The "Root Menu" is
pop−down menu with the here specified fields. By clicking
the field, the corresponding function is started.
Menu RootMenu
{
"Root Menu" f.title
"New Window" f.exec "xterm &"
"Shuffle Up" f.circle_up
"Shuffle Down" f.circle_down
"Refresh" f.refresh
no−label f.separator
"Restart…" f.restart
}
# Default Window Menu Description => This is the default window menu; it can be started
(function f.post_wmenu) using an appropriate key
or button (defined by Key or Button Bindings)
Menu Default Window Menu
{
Restore _R Alt<Key>F5 f.normalize
Move _M Alt<Key>F7 f.move
Size _S Alt<Key>F8 f.resize
Minimize _n Alt<Key>F9 f.minimize
Maximize _x Alt<Key>F10 f.maximize
Lower _L Alt<Key>F3 f.lower
no−label f.separator
Close _C Alt<Key>F4 f.kill
}
#
# key binding descriptions => This resource is a set of key bindings that are used
to configure window manager behavior; a function defined
as "f.function_name" is started when a key is pressed
the indicated context.
Keys DefaultKeyBindings
{
Shift<Key>Escape window/icon f.post_wmenu
Meta<Key>space window/icon f.post_wmenu
Meta<Key>Tab root/icon/window f.next_key
Meta Shift<Key>Tab root/icon/window f.prev_key
Meta<Key>Escape root/icon/window f.next_key
Meta Shift<Key>Escape root/icon/window f.prev_key
Meta Shift Ctrl<Key>exclam root/con/window f.set_behavior
Meta<Key>F6 window f. next_key transient
Meta Shift<Key>F6 window f.prev_key transient
<Key>F4 icon f.post_wmenu
}
#
# button binding descriptions => This resource is a set of button bindings that are used to
configure window manager behavior; a function defined
as "f.function_name" is started when a button press occurs
with the pointer over a framed client window, an icon, or
the root window.
Buttons DefaultButtonBindings
{
<Btn1Down> icon/frame f.raise
<Btn3Down> icon f.post_wmenu
<Btn1Down> root f.menu RootMenu
}
Buttons ExplicitButtonBindings
{
.....
.....
}
Buttons PointerButtonBindings
{
.....
.....
}
#
# END OF mwm RESOURCE DESCRIPTION FILE
关于f.function_name函数的详细解释可以在mwm窗口管理器的手册页中找到。
1.2 CDE Window Manager(dtwm)
CDE环境采用了与mwm类似的配置方法,只是文件的位置和名称不同。默认的CDE窗口管理器配置文件sys.dtwmrc位于/usr/dt/config目录下。管理器按以下顺序搜索配置文件(使用Bourne/Korn shell表示用户主目录):
1. $HOME/.dt/en_US/dtwmrc(“en_US”链接到“C”子目录)
2. $HOME/.dt/dtwmrc
3. /etc/dt/config/en_US/sys.dtwmrc
4. /etc/dt/config/sys.dtwmrc
5. /usr/dt/config/en_US/sys.dtwmrc
6. /usr/dt/config/sys.dtwmrc(默认文件)
同样,第一个找到的文件将被使用,最终必须找到默认设置。
以下是默认CDE窗口管理器配置文件的示例:
$ cat /usr/dt/config/sys.dtwmrc
########################################################################
#
# Original copy: /usr/dt/config/C/sys.dtwmrc
#
# The Resource Description File for the CDE Window Manager dtwm
#
# (c) Copyright 1993, 1994 Hewlett−Packard Company.
# (c) Copyright 1993, 1994 International Business Machines Corp.
# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary
# of Novell, Inc.
#
# $XConsortium: sys.dtwmrc.src /main/cde1_maint/3 1995/10/30 17:23:26 drk $
#
########################################################################
###
#
# Please make a COPY of this file before editing it.
#
# Personalized copies typically exist as:
#
# $HOME/.dt/dtwmrc
#
###
###
#
# Root Menu Description
#
###
Menu DtRootMenu => The "Root Menu" is invoked by clicking in the root window; it is
the pop−down menu with the here specified fields. By clicking on
the field, the corresponding function is started.
{
"Workspace Menu" f.title
"Programs" f.menu ProgramsMenu
no−label f.separator
"Shuffle Up" f.circle_up
"Shuffle Down" f.circle_down
"Refresh" f.refresh
"Minimize/Restore Front Panel" f.toggle_frontpanel
no−label f.separator
"Restart Workspace Manager…" f.restart
no−label f.separator
"Log out…" f.action ExitSession
}
Menu ProgramsMenu => This is the submenu in the "Root Menu".
{
"Programs" f.title
"File Manager…" f.action DtfileHome
"Text Editor…" f.action TextEditor
"Mailer…" f.action Dtmail
"Calendar…" f.action Dtcm
no−label f.separator
"Terminal…" f.action Terminal
"Console…" f.action DttermConsole
no−label f.separator
"Clock…" f.action OWclock
"Calculator…" f.action Dtcalc
"Performance Meter…" f.action OWperfmeter
"Printer Manager…" f.action DtPrintManager
"Audio Tool…" f.action OWaudiotool
no−label f.separator
"Image Viewer…" f.action SDTimage
"Snapshot…" f.action SDTsnapshot
"Icon Editor…" f.action Dticon
no−label f.separator
"Style Manager…" f.action Dtstyle
"App Manager…" f.action Dtappmgr
"Help…" f.action Dthelpview
"AnswerBook…" f.action OWanswerbook
}
.....
.....
###
#
# Key Bindings Description
#
###
.....
.....
###
#
# Mouse Button Bindings Description
#
###
.....
.....
###
#
# Defaults: Window menus, key bindings, and mouse button bindings
#
###
.....
.....
###
#
# User Customization: $HOME/.dt/user.dtwmrc (if it exists) => This is an alternate way to append
#
user−specific settings to the system−
wide ones
###
INCLUDE
{
$HOME/.dt/user.dtwmrc
}
################# End of the dtwmrc file #####################
2. Shell环境与X环境的关系
虽然Shell在X环境之外,但在UNIX系统上运行的X客户端必然依赖于正确设置的Shell环境,具体来说,依赖于正确定义的环境变量和命令搜索路径。
2.1 DISPLAY环境变量
对于X客户端来说,最重要的Shell环境变量是DISPLAY。所有X客户端都使用DISPLAY环境变量来确定要显示的X服务器。由于任何X客户端都可以连接到允许它连接的任何X服务器,因此所有X客户端在启动时都需要知道要连接的显示设备。如果DISPLAY未正确设置,客户端将无法执行。
可以使用以下命令简单检查DISPLAY变量的值:
#echo $DISPLAY
:0.0
早期的X11版本也可以显示unix:0.0。
在用户登录系统时定义DISPLAY变量是一个不错的选择,就像为基于字符的会话指定终端一样。根据用户使用的Shell,可以在用户的.login或.profile文件中定义DISPLAY变量为全局变量:
# 对于C shell
setenv DISPLAY hostname:0.0
# 对于Bourne或Korn shell
DISPLAY=hostname:0.0; export DISPLAY
其中hostname是X终端的名称,可以通过DNS、NIS或本地主机数据库查询到,也可以是IP地址。不过,也有人认为DISPLAY变量不应该包含在登录脚本中,因为这会限制用户只能使用特定的X终端。
可以从命令行覆盖DISPLAY变量的值:
#xterm −display hostname:0.0 &
这个命令会在后台启动xterm程序,xterm是X窗口系统的终端模拟器,为无法直接使用窗口系统的程序提供DEC VT102和Tektronix 4014兼容的终端。−display选项指定要连接的X服务器,这里是主机hostname。主机名后面跟着冒号和字符串0.0,分别指定显示编号和屏幕编号。
对于本地控制台显示,”:0.0”和”hostname:0.0”都可以使用,但它们意味着不同的连接X服务器的方式。前者表示客户端应使用UNIX域套接字(IPC)连接,后者表示客户端应使用Internet域套接字(TCP/IP)连接。
2.2 搜索路径
另一个重要的Shell环境问题是搜索路径。搜索路径需要包含X可执行文件所在的目录。假设X可执行文件位于/usr/bin/X11和/usr/local/bin/X11目录下,相应的用户启动Shell脚本.profile和.cshrc应分别通过扩展PATH条目进行修改:
# 对于Bourne或Korn shell
PATH=/usr/ucb:/ bin:/ usr/bin:/ usr/bin/X11:/ usr/local/bin/X11:.
export PATH
# 对于C shell
set path = (/usr/ucb /bin /usr/bin /usr/bin/X11 /usr/local/bin/X11)
需要注意的是,这只是一个示例,其他目录也可以包含或省略,也可以通过不同的方式实现。
早期的X版本中的.xsession启动脚本会重新定义搜索路径,除非另有指定。它假设X客户端程序位于标准位置。如果客户端位于不同的目录,则需要进行相应的修改。
2.3 CDE环境中的.dtprofile脚本
CDE环境中的.dtprofile脚本与.profile文件共存(假设用户使用Bourne或Korn shell环境,对于.login和C shell也是如此)。通常的基于字符的登录脚本.profile可以由.dtprofile脚本引用,也可以被忽略或替换。
以下是一个.dtprofile文件的示例:
$ cat /home/bjl/.dtprofile
########################################################################
###
### .dtprofile
###
### user personal environment variables
###
### Common Desktop Environment (CDE)
###
###
### $Revision: 1.7 $
###
########################################################################
###
### Your $HOME/.dtprofile is read each time you login to the Common Desktop
### Enviroment (CDE) and is the place to set or override desktop
### environment variables for your session. Environment variables set in
### $HOME/.dtprofile are made available to all applications on the desktop.
### The desktop will accept either sh or ksh syntax for the commands in
### $HOME/.dtprofile.
###
### By default, the desktop does not read your standard $HOME/.profile
### or $HOME/.login files. This can be changed by uncommenting the
### DTSOURCEPROFILE variable assignment at the end of this file. The
### desktop reads .profile if your $SHELL is "sh" or "ksh", or .login
### if your $SHELL is "csh".
###
### The desktop reads the .dtprofile and .profile/.login without an
### associated terminal emulator such as xterm or dtterm. This means
### there is no available command line for interaction with the user.
### This being the case, these scripts must avoid using commands that
### depend on having an associated terminal emulator or that interact
### with the user. Any messages printed in these scripts will not be
### seen when you log in and any prompts such as by the 'read' command
### will return an empty string to the script. Commands that set a
### terminal state, such as "tset" or "stty" should be avoided.
###
### With minor editing, it is possible to adapt your .profile or .login
### for use both with and without the desktop. Group the statements not
### appropriate for your desktop session into one section and enclose them
### with an "if" statement that checks for the setting of the "DT"
### environment variable. When the desktop reads your .profile or .login
### file, it will set "DT" to a non−empty value for which your .profile or
### .login can test.
###
### example for sh/ksh
###
### if [ ! "$DT" ]; then
### #
### #commands and environment variables not appropriate for desktop
### #
### stty …
### tset …
### DISPLAY=mydisplay:0
### …
### fi
###
### # environment variables common to both desktop and non−desktop
### #
### PATH=$H OME/bin:$PATH
### MYVAR=value
### export MYVAR
### ...
###
### example for csh
###
### if (! ${?DT}) then
### #
### # commands and environment variables not appropriate for desktop
### #
### stty…
### tset…
### setenv DISPLAY mydisplay:0
### ...
### endif
###
### #environment variables common to both desktop and non−desktop
### #
### setenv PATH $HOME/bin:$PATH
### setenv MYVAR value
### ...
###
### Errors in .dtprofile or .profile (.login) may prevent a successful
### login. If after you login, your session startup terminates and you
### are presented with the login screen, this might be the cause. If this
### happens, select the Options−>Sessions−>Failsafe Session item on the
### login screen, login and correct the error. The $HOME/.dt/startlog and
### $HOME/.dt/errorlog files may be helpful in identifying errors.
###
# If $HOME/.profile (.login) has been edited as described above, uncomment
# the following line.
#
DTSOURCEPROFILE=true
#
这个示例展示了最常见的dtprofile配置,它会根据用户使用的Shell完全包含.profile或.login文件,因此之前的Shell环境设置仍然有效。不过,这需要对.profile文件进行一些小的修改,具体可以参考文件中的注释。
2.4 HP VUE环境中的.vueprofile脚本
Visual User Environment(VUE)是HP特定的X版本,在所有HP - UX平台上都有实现,从HP - UX 9.0x到HP - UX 11.x。新的HP - UX版本同时支持VUE和CDE。.vuelogin是.dtlogin文件的VUE对应文件,实际上,.vuelogin文件更早存在。
以下是一个.vueprofile文件的示例:
$ cat /users/bjl/.vueprofile
#!/ bin/sh
########################################################################
###
### .vueprofile
### user personal environment variables
### Hewlett−Packard Visual User Environment, Version 3.0
###
########################################################################
###
### VUE pre−sets the following environment variables for each user.
###
### DISPLAY set to the value of the first field in the Xservers file
### EDITOR set to the HP VUE default editor
### ENV set to "$HOME/.kshrc"
### HOME set to the user's home directory (from /etc/passwd)
### KBD_LANG set to the value of $LANG for some languages (see Xsession)
### LANG set to the display's current NLS language (if any)
### LC_ALL, LC_MESSAGES set to the value of $LANG
### LOGNAME set to the user name
### MAIL set to "/usr/mail/$USER"
### PATH set to the value of the Vuelogin "userPath" resource
### USER set to the user name
### SHELL set to the user's default shell (from /etc/passwd)
### TERM set to xterm
### TZ set to the value of the Vuelogin "timeZone" resource
###
### Three methods are available to modify or add to this list depending
### on the desired scope of the resulting environment variable.
###
### 1. X server and/or all users on a display (Xconfig file)
### 2. all users on a display (Xsession file)
### 3. individual users (.vueprofile file)
###
###
### Personal environment variables can be set in the script file
### "$HOME/.vueprofile". The files /etc/profile and $HOME/.profile are
### not read by VUE as they may contain terminal I/O based commands
### inappropriate for a graphical interface. Users should set up
### ".vueprofile" with personal environment variables for their VUE
### session.
###
### VUE will accept either sh, ksh, or csh syntax for the commands in this
### file. The commands should only be those that set environment
### variables, not any that perform terminal I/O, ex. "tset" or "stty".
### If the first line of ".vueprofile" is #!/bin/sh, #!/bin/ksh, or
### #!/bin/csh, VUE will use the appropriate shell to parse the commands.
### Otherwise the user's default shell ($SHELL) will be used.
###
### With minor editing, it is possible to adapt $HOME/.profile (.login)
### for use both with and without HP VUE. Group the statements not
### allowed for VUE into one section and enclose them with an "if"
### statement that checks for the setting of the "VUE" environment
### variable. Then set the "VUE" environment variable at the bottom of
### this script (.vueprofile) and log in again. From then on changes
### need only be made to $HOME/.profile (.login).
###
### example for sh/ksh
### #
#### commands and environment variables used when logging in without VUE
### #
### if [ ! "$VUE" ]; then
### stty…
### tset…
### DISPLAY=mydisplay:0
### MAIL=/usr/mail/$USER
### EDITOR=/bin/vi
### …
### fi
###
### #
### # environment variables common to both VUE and non−VUE
### #
### PATH=$HOME/bin:$PATH
### …
###
### Errors in .vueprofile or .profile (.login) may prevent a successful
### login. If so, log in via the Fail−safe session and correct the error.
###
########################################################################
#
# if $HOME/.profile (.login) has been edited as described above, uncomment
# one of the two following lines, depending on your default shell.
#
VUE=true; export VUE; . $HOME/.profile; unset VUE # sh, ksh
# setenv VUE true; source $HOME/.login; unsetenv VUE # csh
#
# @(#) $Revision: 66.1 $
.vueprofile和.dtprofile文件有明显的相似之处,但.dtprofile文件是改进版本。.vueprofile也需要对用户的.profile文件(或.login)进行相应的修改。
以下是一个修改后的.profile文件示例:
$ cat /users/bjl/.profile
# User .profile file (/bin/sh initialization).
#
# Testing VUE environment
if [ ! "$VUE" ]; then
# Set up the terminal: <−−−− this part is active only if VUE is not implemented!
TERM=vt100
export TERM
tset −Q
stty erase "^?" kill "^U" intr "^C" eof "^D"
stty hupcl ixon ixoff
tabs
echo "Your terminal is $TERM"
echo ""
# Set up the shell environment:
set −u
trap "echo 'logout'" 0
# Set up the shell variables:
EDITOR=vi
export EDITOR
fi <−−−− the end of the part
# Set up the search paths:
PATH=$PATH:/usr/local/TeX/bin:.
export PATH
#
3. 总结
通过合理配置窗口管理器和Shell环境,可以为用户提供更好的X环境使用体验。在配置过程中,需要注意不同窗口管理器和环境的特点,根据实际需求进行个性化设置。同时,要避免在配置文件中使用依赖于终端模拟器或与用户交互的命令,以免影响登录和使用。
3.1 窗口管理器配置总结
| 窗口管理器 | 配置文件搜索顺序 | 默认配置文件位置 |
|---|---|---|
| mwm | 从用户主目录到系统全局默认配置文件 | /usr/lib/X11/system.mwmrc |
| dtwm | $HOME/.dt/en_US/dtwmrc -> $HOME/.dt/dtwmrc -> /etc/dt/config/en_US/sys.dtwmrc -> /etc/dt/config/sys.dtwmrc -> /usr/dt/config/en_US/sys.dtwmrc -> /usr/dt/config/sys.dtwmrc | /usr/dt/config/sys.dtwmrc |
3.2 Shell环境配置总结
| 环境变量 | 作用 | 配置方式 |
|---|---|---|
| DISPLAY | 确定X客户端要显示的X服务器 | 在.login或.profile文件中定义,可从命令行覆盖 |
| PATH | 命令搜索路径 | 在.profile或.cshrc文件中扩展 |
3.3 配置流程图
graph TD;
A[用户登录] --> B{是否为X环境};
B -- 是 --> C{使用哪种窗口管理器};
C -- mwm --> D[搜索mwm配置文件];
D -- 找到 --> E[使用该配置文件配置mwm];
D -- 未找到 --> F[使用默认配置文件system.mwmrc];
C -- dtwm --> G[搜索dtwm配置文件];
G -- 找到 --> H[使用该配置文件配置dtwm];
G -- 未找到 --> I[使用默认配置文件sys.dtwmrc];
B -- 否 --> J[使用传统Shell环境配置];
K[设置DISPLAY变量] --> L[启动X客户端];
M[设置PATH变量] --> L;
通过以上的配置和优化,可以让X环境更加稳定、高效,满足不同用户的需求。
4. 窗口管理器配置的深入分析
4.1 mwm配置文件详解
mwm的配置文件system.mwmrc和.mwmrc包含了多种资源描述,如菜单和键绑定。以下是对这些部分的详细分析:
-
菜单配置
:
-
Root Menu
:通过在根窗口点击调用,包含一系列功能选项,如打开新窗口、窗口排序等。示例代码如下:
Menu RootMenu
{
"Root Menu" f.title
"New Window" f.exec "xterm &"
"Shuffle Up" f.circle_up
"Shuffle Down" f.circle_down
"Refresh" f.refresh
no−label f.separator
"Restart…" f.restart
}
- **Default Window Menu**:默认窗口菜单,可通过特定按键或按钮启动。
Menu Default Window Menu
{
Restore _R Alt<Key>F5 f.normalize
Move _M Alt<Key>F7 f.move
Size _S Alt<Key>F8 f.resize
Minimize _n Alt<Key>F9 f.minimize
Maximize _x Alt<Key>F10 f.maximize
Lower _L Alt<Key>F3 f.lower
no−label f.separator
Close _C Alt<Key>F4 f.kill
}
-
键绑定配置
:
- Keys DefaultKeyBindings :定义了一系列键绑定,用于配置窗口管理器的行为。例如,按下Shift + Escape组合键可弹出窗口菜单。
Keys DefaultKeyBindings
{
Shift<Key>Escape window/icon f.post_wmenu
Meta<Key>space window/icon f.post_wmenu
Meta<Key>Tab root/icon/window f.next_key
Meta Shift<Key>Tab root/icon/window f.prev_key
Meta<Key>Escape root/icon/window f.next_key
Meta Shift<Key>Escape root/icon/window f.prev_key
Meta Shift Ctrl<Key>exclam root/con/window f.set_behavior
Meta<Key>F6 window f. next_key transient
Meta Shift<Key>F6 window f.prev_key transient
<Key>F4 icon f.post_wmenu
}
-
按钮绑定配置
:
- Buttons DefaultButtonBindings :定义了鼠标按钮的绑定,例如按下鼠标左键在图标或框架上可提升窗口。
Buttons DefaultButtonBindings
{
<Btn1Down> icon/frame f.raise
<Btn3Down> icon f.post_wmenu
<Btn1Down> root f.menu RootMenu
}
4.2 dtwm配置文件详解
dtwm的配置文件sys.dtwmrc包含了根菜单、子菜单和用户自定义部分。以下是详细分析:
-
根菜单配置
:
-
Menu DtRootMenu
:通过在根窗口点击调用,包含工作区菜单、程序菜单等选项。
Menu DtRootMenu
{
"Workspace Menu" f.title
"Programs" f.menu ProgramsMenu
no−label f.separator
"Shuffle Up" f.circle_up
"Shuffle Down" f.circle_down
"Refresh" f.refresh
"Minimize/Restore Front Panel" f.toggle_frontpanel
no−label f.separator
"Restart Workspace Manager…" f.restart
no−label f.separator
"Log out…" f.action ExitSession
}
-
子菜单配置
:
- Menu ProgramsMenu :是根菜单中的子菜单,包含文件管理器、文本编辑器等程序选项。
Menu ProgramsMenu
{
"Programs" f.title
"File Manager…" f.action DtfileHome
"Text Editor…" f.action TextEditor
"Mailer…" f.action Dtmail
"Calendar…" f.action Dtcm
no−label f.separator
"Terminal…" f.action Terminal
"Console…" f.action DttermConsole
no−label f.separator
"Clock…" f.action OWclock
"Calculator…" f.action Dtcalc
"Performance Meter…" f.action OWperfmeter
"Printer Manager…" f.action DtPrintManager
"Audio Tool…" f.action OWaudiotool
no−label f.separator
"Image Viewer…" f.action SDTimage
"Snapshot…" f.action SDTsnapshot
"Icon Editor…" f.action Dticon
no−label f.separator
"Style Manager…" f.action Dtstyle
"App Manager…" f.action Dtappmgr
"Help…" f.action Dthelpview
"AnswerBook…" f.action OWanswerbook
}
-
用户自定义部分
:
- INCLUDE :可通过包含$HOME/.dt/user.dtwmrc文件进行用户特定设置的追加。
INCLUDE
{
$HOME/.dt/user.dtwmrc
}
5. Shell环境配置的最佳实践
5.1 DISPLAY变量设置建议
- 全局设置 :在用户登录时设置DISPLAY变量是一个好的选择,但要注意不要限制用户只能使用特定的X终端。可以在.login或.profile文件中设置,示例如下:
# 对于C shell
setenv DISPLAY hostname:0.0
# 对于Bourne或Korn shell
DISPLAY=hostname:0.0; export DISPLAY
- 命令行覆盖 :如果需要临时更改DISPLAY变量的值,可以从命令行使用 -display 选项,例如:
xterm −display hostname:0.0 &
5.2 搜索路径配置建议
- 包含X可执行文件目录 :确保搜索路径包含X可执行文件所在的目录,如/usr/bin/X11和/usr/local/bin/X11。示例如下:
# 对于Bourne或Korn shell
PATH=/usr/ucb:/ bin:/ usr/bin:/ usr/bin/X11:/ usr/local/bin/X11:.
export PATH
# 对于C shell
set path = (/usr/ucb /bin /usr/bin /usr/bin/X11 /usr/local/bin/X11)
- 避免重复设置 :在不同的配置文件中避免重复设置搜索路径,以免造成混淆。
5.3 .dtprofile和.vueprofile文件使用建议
- .dtprofile文件 :可以根据用户的Shell类型包含或排除.profile或.login文件。在修改.profile文件时,使用条件语句区分桌面环境和非桌面环境的设置。示例如下:
# sh/ksh示例
if [ ! "$DT" ]; then
# 非桌面环境的设置
stty …
tset …
DISPLAY=mydisplay:0
…
fi
# 桌面和非桌面环境通用的设置
PATH=$HOME/bin:$PATH
MYVAR=value
export MYVAR
- .vueprofile文件 :同样需要对.profile或.login文件进行修改,使用条件语句区分VUE环境和非VUE环境的设置。示例如下:
# sh/ksh示例
if [ ! "$VUE" ]; then
# 非VUE环境的设置
stty…
tset…
DISPLAY=mydisplay:0
MAIL=/usr/mail/$USER
EDITOR=/bin/vi
…
fi
# VUE和非VUE环境通用的设置
PATH=$HOME/bin:$PATH
6. 常见问题及解决方法
6.1 窗口管理器配置问题
- 问题描述 :修改窗口管理器配置文件后,配置未生效。
-
解决方法
:
- 检查配置文件的语法是否正确,可以使用文本编辑器的语法检查功能。
- 确保配置文件的路径和名称正确,按照搜索顺序检查。
- 重启窗口管理器或重新登录系统,使配置生效。
6.2 Shell环境配置问题
- 问题描述 :X客户端无法启动,提示DISPLAY变量未设置或设置错误。
-
解决方法
:
-
使用
echo $DISPLAY命令检查DISPLAY变量的值是否正确。 - 在.login或.profile文件中检查DISPLAY变量的设置,确保主机名和显示编号正确。
- 如果需要,从命令行使用 -display 选项临时设置DISPLAY变量。
-
使用
6.3 登录问题
- 问题描述 :登录后会话启动终止,返回登录屏幕。
-
解决方法
:
- 检查.dtprofile或.profile(.login)文件中是否存在错误,特别是使用了依赖于终端模拟器或与用户交互的命令。
- 选择登录屏幕上的Options -> Sessions -> Failsafe Session选项,登录并修改错误。
- 查看$HOME/.dt/startlog和$HOME/.dt/errorlog文件,帮助识别错误。
7. 总结与展望
7.1 总结
本文详细介绍了X环境中的窗口管理器(mwm和dtwm)和Shell环境的配置方法。通过合理配置窗口管理器和Shell环境,可以为用户提供更好的X环境使用体验。在配置过程中,需要注意不同窗口管理器和环境的特点,根据实际需求进行个性化设置。同时,要避免在配置文件中使用依赖于终端模拟器或与用户交互的命令,以免影响登录和使用。
7.2 展望
随着技术的不断发展,X环境和窗口管理器也在不断更新和改进。未来,可能会有更多的配置选项和功能,以满足用户日益增长的需求。同时,配置过程也可能会更加简化和自动化,提高用户的使用效率。
7.3 常见配置总结表格
| 配置项 | 详细信息 |
|---|---|
| mwm配置文件 | 搜索顺序从用户主目录到系统全局默认配置文件,默认配置文件为/usr/lib/X11/system.mwmrc |
| dtwm配置文件 | 搜索顺序为$HOME/.dt/en_US/dtwmrc -> $HOME/.dt/dtwmrc -> /etc/dt/config/en_US/sys.dtwmrc -> /etc/dt/config/sys.dtwmrc -> /usr/dt/config/en_US/sys.dtwmrc -> /usr/dt/config/sys.dtwmrc,默认配置文件为/usr/dt/config/sys.dtwmrc |
| DISPLAY变量 | 用于确定X客户端要显示的X服务器,可在.login或.profile文件中定义,也可从命令行覆盖 |
| PATH变量 | 命令搜索路径,需在.profile或.cshrc文件中扩展,包含X可执行文件目录 |
7.4 配置流程优化图
graph TD;
A[用户登录] --> B{是否为X环境};
B -- 是 --> C{使用哪种窗口管理器};
C -- mwm --> D[检查mwm配置文件语法];
D -- 正确 --> E[搜索mwm配置文件];
E -- 找到 --> F[使用该配置文件配置mwm];
E -- 未找到 --> G[使用默认配置文件system.mwmrc];
D -- 错误 --> H[修正配置文件语法];
H --> E;
C -- dtwm --> I[检查dtwm配置文件语法];
I -- 正确 --> J[搜索dtwm配置文件];
J -- 找到 --> K[使用该配置文件配置dtwm];
J -- 未找到 --> L[使用默认配置文件sys.dtwmrc];
I -- 错误 --> M[修正配置文件语法];
M --> J;
B -- 否 --> N[使用传统Shell环境配置];
O[设置DISPLAY变量] --> P[检查DISPLAY变量有效性];
P -- 有效 --> Q[启动X客户端];
P -- 无效 --> R[修正DISPLAY变量设置];
R --> P;
S[设置PATH变量] --> Q;
通过以上的详细介绍和优化建议,希望能帮助用户更好地配置和使用X环境,提高工作效率和使用体验。
超级会员免费看
29万+

被折叠的 条评论
为什么被折叠?



