Difference between revisions of "Xinit"

From ArchWiki
Jump to: navigation, search
(Policykit: too many examples to list them all)
m (File examples: more common example entry)
Line 20: Line 20:
cairo-compmgr &                  # starts composite manager
xrdb -merge ~/.Xresources        # update x resources db
xscreensaver -no-splash &        # starts screensaver daemon  
xscreensaver -no-splash &        # starts screensaver daemon  
xsetroot -cursor_name left_ptr &  # sets the cursor icon
xsetroot -cursor_name left_ptr &  # sets the cursor icon

Revision as of 08:14, 21 July 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end

The Template:Filename file is a shell script read by Template:Codeline and Template:Codeline. It is typically used to execute window managers and other programs when starting X - e.g. starting daemons and setting environment variables. The Template:Codeline program is used to start the X Window System and works as a first client program on systems that cannot start X directly from Template:Filename, or in environments that use multiple window systems. The Template:Filename file is therefore a simple way to start X, usually in conjunction with running the startx script directly from inittab.

File examples

Following is a simple Template:Filename file example, including some startup programs: Template:File

Following example can be used as a template for executing various window managers, by uncommenting the one to be used, e.g. Openbox:


Prepending Template:Codeline is recommended as it replaces the current process with the manager, but its not necessary if all additional desktop/window managers are commented out as in the above example. Use the full path when possible, using Template:Codeline.

In addition to the examples provided here, you can find another at Template:Filename provided by Template:Package Official. To use it, simply copy it to your home directory:

$ cp /etc/skel/.xinitrc ~/

File configuration

When a display manager is not used, it is important to keep in mind that the life of the X session starts and ends with Template:Filename. This means that once the script quits, X quits regardless of whether you still have running programs (including your window manager). Therefore it's important that the window manager quitting and X quitting should coincide. This is easily achieved by running the window manager as the last program in the script.

Note that in the first example above, programs such as Template:Codeline, Template:Codeline, Template:Codeline and Template:Codeline are run in the background (Template:Codeline suffix added). Otherwise, the script would halt and wait for each program and daemons to exit before executing Template:Codeline. Also note that Template:Codeline is not backgrounded. This ensures that the script will not quit until openbox does. If you run the Template:Codeline script manually, ending the script will terminate X and leave you with whatever virtual consoles Template:Filename has started.

If running the file from Template:Filename and have set the line to Template:Codeline instead of Template:Codeline, Template:Filename will be re-run. This way X can be restarted without having to restart the computer.

The following sections explains how to configure Template:Filename for different uses.

Multiple WMs and DEs

On the command line

If you have a working Template:Filename, but just want to try other WM/DE you can run it by issuing Template:Codeline followed by the path to the window manager:

xinit /full/path/to/window-manager

Note that the full path is required. Optionally, you can pass options to the X server after appending Template:Codeline - e.g.:

xinit /usr/bin/enlightenment -- -br +bs -dpi 96

The following example Template:Filename shows how to start a particular window manager with an argument:


Using this example you can start fluxbox or scrotwm with the command Template:Codeline or Template:Codeline.

At startup

You can also have a choice of window managers and desktop environments at startup, using just Template:Filename 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 Template:Filename 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;;

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 Template:Filename 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/sda1 ro 4
initrd /boot/kernel26.img

Finally, you will need to ensure that the Template:Filename file is actually run at the chosen runlevel. Using the tip from Start X at boot#/etc/inittab, you can edit the Template:Filename to simply run Template:Codeline on the desired runlevel which will in turn use your Template:Filename 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 Template:Filename as described above. This is preferable to attempt differentiating in the Template:Filename file as we stick pretty close to using the various configuration files as they were intended.

Tips and tricks


Various desktop environment features and applications expect PolicyKit to be active, and will produce errors if absent. A common error to notice is the inability to access shutdown or reboot prompts from desktop environment windows, and failure to mount usb devices, cd-roms etc. without root permissions. Most modern display managers will start policykit automatically. When only using Template:Filename with your display manager e.g Slim, you should execute the window manager as follows:

exec ck-launch-session gnome-session

Starting the WM first

If you need to start your window manager before other additional applications, use the following method:


openbox & wmpid=$!

urxvtd -q -f -o &
xscreensaver -no-splash &
fbpanel &

wait $wmpid

The first line runs openbox as a background process and immediately stores the process id (Template:Codeline) in the variable Template:Codeline. On the last line, the wait builtin is used to wait until the process specified by Template:Codeline terminates.

More resources