Xinitrc (简体中文)
From ArchWiki
i18n |
---|
English |
Ελληνικά |
简体中文 |
Español |
xinit程序用来启动某些系统的 X Window 系统服务器端和第一个客户端,因为这些系统通常不能直接从/etc/init启动 X 或者是处于使用多头显示系统的环境。因此.xinitrc文件是一种通常与直接从inittab运行startx脚本结合使用的启动X的简单方法。
Contents |
工作原理
The .xinitrc file is really just one more shell script to run. It can be used to start various applications you want to associate with starting X, e.g. the X screensaver, and to set global environment variables, like MOZ_PLUGIN_PATH. It's foremost use however, is as a replacement for a display manager when on a single user machine. When you do not start a display manager it is important to keep in mind that the life of your X session starts and ends with the .xinitrc script. What this means is that once the script finishes, X quits, regardless of whether you still have running programs, including your window manager. It is therefore important that the window manager quitting and X quitting should coincide. This is usually achieved by running the window manager as the last thing in the .xinitrc script, e.g.
.xinitrc 示例
#!/bin/sh /usr/bin/autocutsel -fork & /usr/bin/autocutsel -selection PRIMARY -fork & /usr/local/bin/urxvtd -q -f -o & /usr/bin/xscreensaver -no-splash & /usr/lib/notification-daemon/notification-daemon & export MOZ_PLUGIN_PATH="/usr/lib/mozilla/plugins:/opt/mozilla/lib/plugins" exec openbox-session
Notice that applications such as autocutsel, xscreensaver and the urxvtd and notification-daemon daemons are run in the background (& appendage). Otherwise the script would halt and wait for the programs and daemons to quit before continuing to export the variable line and openbox-session. The openbox-session line starting an Openbox session however, is not backgrounded. This ensures that the script will not quit until Openbox does. If you run the startx script manually, ending the script will terminate X and leave you with whatever virtual consoles your inittab has started. If you're running it from inittab and has set the line to 'respawn' (rather than 'once'), xinitrc will be run again. This way you can restart X without having to restart the computer with.
一个标准的 .xinitrc
使用这个模板时你可简单地将你喜欢的窗口管理器取消注释,例如 Gnome
#!/bin/sh # # ~~/.xinitrc # # 被startx执行 (从这里运行你的窗口管理器) # # exec ion # exec wmaker # exec startkde # exec icewm # exec blackbox exec gnome-session # exec startfluxbox # exec startxfce4 # exec openbox # exec startlxde
Note: Prepending exec
is not necessary as long as additional desktop/window managers are commented out as they are in the above example.
多桌面环境选择
命令行方式下
如果你有一个可用的.xinitrc文件,但只想尝试下其他的窗口管理器/桌面环境,你可从命令行这样运行xinit
xinit /full/path/to/window-manager
需要使用完整路径。此外你可以选择在'--'后面向X服务器传递参数,例如
xinit /usr/bin/enlightenment -- -br +bs -dpi 96
随系统启动方式
You can also have a choice of window managers and desktop environments at startup, using just .xinitrc and GRUB and no display manager. The idea is to take advantage of the fact that Arch doesn't make any particular use of the runlevel system. The following .xinitrc tests for the current runlevel and will start Openbox and GNOME on runlevels 5 and 4 respectively:
rl=$(runlevel | grep -o [0-6]) case $rl in 4) exec gnome-session;; 5) exec openbox-session;; esac
Choosing between different runlevels is simply a matter of cloning a GRUB entry and adding the desired runlevel to the kernel arguments. Inserting the runlevel at the end of the 'kernel' line indicates that the inittab's default of runlevel 5 should be overridden and replaced with the desired runlevel, 4 in this instance:
title Arch Linux GNOME root (hd0,2) kernel /boot/vmlinuz26 root=/dev/disk/by-uuid/a29113d7-2204-49e9-be69-d94699eba466 ro 4 initrd /boot/kernel26.img
Finally, you will need to ensure that the .xinitrc file is actually run at the chosen runlevel. Using the tip from the startx article, you can edit the inittab to simply run startx on the desired runlevel which will in turn use your .xinitrc script:
x:45:once:/bin/su PREFERED_USER -l -c "/bin/bash --login -c startx >/dev/null 2>&1"
Notice that "45" means that this will happen on both runlevels 4 and 5. The final differentiation between 4 and 5 will then come in .xinitrc as described above. This is preferable to attempt differentiating in the inittab file as we stick pretty close to using the various configuration files as they were intended.