Difference between revisions of "Xinit"

From ArchWiki
Jump to: navigation, search
(Moving some parts from Xorg to xinitrc.)
m (add de:Xinitrc)
(47 intermediate revisions by 14 users not shown)
Line 1: Line 1:
[[Category:Desktop environments (English)]]
+
[[Category:Desktop environments]]
[[Category:X Server (English)]]
+
[[Category:X Server]]
{{i18n|Xinitrc}}
+
[[de:Xinitrc]]
 +
[[el:Xinitrc]]
 +
[[es:Xinitrc]]
 
[[fr:Startx]]
 
[[fr:Startx]]
 +
[[it:Xinitrc]]
 +
[[zh-CN:Xinitrc]]
 
{{Article summary start}}
 
{{Article summary start}}
 
{{Article summary text|An overview of the primary configuration file for the xinit (startx) program.}}
 
{{Article summary text|An overview of the primary configuration file for the xinit (startx) program.}}
 
{{Article summary heading|Related}}
 
{{Article summary heading|Related}}
 
{{Article summary wiki|Display Manager}}
 
{{Article summary wiki|Display Manager}}
{{Article summary wiki|Start X at boot}}
+
{{Article summary wiki|Start X at Login}}
 
{{Article summary wiki|Xorg}}
 
{{Article summary wiki|Xorg}}
 
{{Article summary wiki|xprofile}}
 
{{Article summary wiki|xprofile}}
 
{{Article summary end}} {{Lowercase title}}
 
{{Article summary end}} {{Lowercase title}}
  
The {{ic|~/.xinitrc}} file is a shell script read by {{ic|xinit}} and {{ic|startx}}. It is typically used to execute [[window manager]]s and other programs when starting X (e.g., starting daemons and setting environment variables). The {{ic|xinit}} program is used to start the [[Xorg|X Window System]] and works as a first client program on systems that cannot start X directly from {{ic|/etc/init}}, or in environments that use multiple window systems. The {{ic|~/.xinitrc}} file is therefore a simple way to start X, usually in conjunction with [[Start X at boot#/etc/inittab|running the startx script directly from inittab]].
+
The {{ic|~/.xinitrc}} file is a shell script read by {{ic|xinit}} and {{ic|startx}}. It is mainly used to execute [[desktop environment]]s, [[window manager]]s and other programs when starting the X server (e.g., starting daemons and setting environment variables). The {{ic|xinit}} and {{ic|startx}} programs starts the [[Xorg|X Window System]] and works as first client programs on systems that cannot start X directly from {{ic|/etc/init}}, or in environments that use multiple window systems.
  
One of the main functions of {{ic|~/.xinitrc}} is to dictate which client for the X Window System is invoked with the {{ic|/usr/bin/startx}} and/or {{ic|/usr/bin/xinit}} program ''on a per-user basis''. There are vast amounts of additional configurable specifications and commands that may also be added to {{ic|~/.xinitrc}} as you further customize your system.
+
One of the main functions of {{ic|~/.xinitrc}} is to dictate which client for the X Window System is invoked with the {{ic|/usr/bin/startx}} and/or {{ic|/usr/bin/xinit}} program on a per-user basis. There exists numerous additional specifications and commands that may also be added to {{ic|~/.xinitrc}} as you further customize your system.
  
 
==Getting started==
 
==Getting started==
  
{{ic|/etc/skel/}} contains files and directories to provide sane defaults for newly created user accounts. (The name ''skel'' is derived from the word ''skeleton'', because the files it contains form the basic structure for users' home directories.)
+
{{ic|/etc/skel/}} contains files and directories to provide sane defaults for newly created user accounts. (The name ''skel'' is derived from the word ''skeleton'', because the files it contains form the basic structure for users' home directories.) The {{Pkg|xorg-xinit}} package will populate {{ic|/etc/skel}} with a framework {{ic|.xinitrc}} file.
  
{{Note|{{ic|~/.xinitrc}} is a so-called 'dot' (.) file. Files in a *nix file system which are preceded with a dot (.) are 'hidden' and will not show up with a regular {{ic|ls}} command, usually for the sake of keeping directories tidy. Dot files may be seen by running {{ic|ls -a}}. The 'rc' denotes ''Run Commands'' and simply indicates that it is a configuration file. Since it controls how a program runs, it is (although historically incorrect) also said to stand for "Run Control".}}
+
{{Note|{{ic|~/.xinitrc}} is a so-called 'dot' (.) file. Files in a *nix file system which are preceded with a dot (.) are 'hidden' and will not show up with a regular {{ic|ls}} command, usually for the sake of keeping directories tidy. Dot files may be seen by running {{ic|ls -A}}. The 'rc' denotes ''Run Commands'' and simply indicates that it is a configuration file. Since it controls how a program runs, it is (although historically incorrect) also said to stand for "Run Control".}}
  
 
Copy the sample {{ic|/etc/skel/.xinitrc}} file to your home directory:
 
Copy the sample {{ic|/etc/skel/.xinitrc}} file to your home directory:
  $ cp /etc/skel/.xinitrc ~/
+
  $ cp /etc/skel/.xinitrc ~
  
Now, edit {{ic|~/.xinitrc}} and uncomment the line that corresponds to your [[Desktop_Environment|desktop environment]]. For example, if you use [[Xterm]], it will look something like this:
+
Now, edit {{ic|~/.xinitrc}} and uncomment the line that corresponds to your DE/WM. For example, if you want to test your basic X configuration (mouse, keyboard, graphics resolution), you can simply use [[xterm]]:
  
 
{{bc|
 
{{bc|
Line 33: Line 37:
 
#
 
#
 
# Executed by startx (run your window manager from here)
 
# Executed by startx (run your window manager from here)
 +
 +
if [ -d /etc/X11/xinit/xinitrc.d ]; then
 +
  for f in /etc/X11/xinit/xinitrc.d/*; do
 +
    [ -x "$f" ] && . "$f"
 +
  done
 +
  unset f
 +
fi
  
 
# exec gnome-session
 
# exec gnome-session
Line 46: Line 57:
 
}}
 
}}
  
{{Note|Be sure to have only ''one'' uncommented {{ic|exec}} line in {{ic|~/.xinitrc}}.}}
+
{{Note|It is important that only one {{ic|exec}} line is uncommented, or else only the first uncommented line will be run.}}
  
Now we are ready to launch X. Start X as a ''normal, non-root'' user, with:
+
After editing {{ic|~/.xinitrc}} properly, it's time to run X. To run X as a non-root user, issue:
 
  $ startx
 
  $ startx
  
or
+
Your DE/WM of choice should now start up. You are now free to test your keyboard with its layout, moving your mouse around and of course enjoy the view.
$ xinit
+
  
Your desktop should open up now. You can test your keyboard and its layout in it. Try moving your mouse around and enjoy the view.
+
===Preserving the session===
  
If you experience trouble with automounting, try using the following command in {{ic|~/.xinitrc}} instead. Replace {{ic|startxfce4}} with the command that is appropriate for your [[Window_Manager|window manager]] or [[Desktop_Environment|desktop environment]].
+
X must always be run on the same tty where the login occurred, to preserve the logind session. This is handled by the default {{ic|/etc/X11/xinit/xserverrc}}. Also see [[General Troubleshooting#Session permissions]] for related issues.
exec ck-launch-session startxfce4
+
  
This will ensure the various environment variables are set correctly by starting a clean [[ConsoleKit]] session. ConsoleKit is a framework for keeping track of the various users, sessions, and seats present on a system. It provides a mechanism for software to react to changes of any of these items or of any of the metadata associated with them. It works in conjunction with [[D-Bus]] and other tools.
+
{{Note|In the past {{ic|ck-launch-session}} was used to start a '''new''' session instead of simply not breaking the old one. There is no equivalent to this hack with {{ic|logind}}, and a multi-seat aware display manager is required to run X on an arbitrary tty.}}
 
+
{{Note|Be sure of having the {{Pkg|consolekit}} package installed.}}
+
  
 
== File examples==
 
== File examples==
Line 69: Line 76:
 
|<nowiki>
 
|<nowiki>
 
#!/bin/sh
 
#!/bin/sh
 +
 +
if [ -d /etc/X11/xinit/xinitrc.d ]; then
 +
  for f in /etc/X11/xinit/xinitrc.d/*; do
 +
    [ -x "$f" ] && . "$f"
 +
  done
 +
  unset f
 +
fi
  
 
xrdb -merge ~/.Xresources        # update x resources db
 
xrdb -merge ~/.Xresources        # update x resources db
Line 77: Line 91:
  
 
exec openbox-session              # starts the window manager
 
exec openbox-session              # starts the window manager
 
 
</nowiki>}}
 
</nowiki>}}
  
Following example can be used as a template for executing various window managers, by uncommenting the one to be used, e.g. [[Openbox]]:
+
Prepending {{ic|exec}} is recommended as it replaces the current process with the process, so the script will stop running and X won't exit even if the process forks into the background.
 
+
{{hc
+
|~/.xinitrc
+
|<nowiki>
+
#!/bin/sh
+
#
+
# ~/.xinitrc
+
#
+
# Executed by startx (run your window manager from here)
+
#
+
# exec ion
+
# exec jwm
+
# exec wmaker
+
# exec startkde
+
# exec icewm
+
# exec pekwm
+
# exec blackbox
+
# exec /usr/bin/ratpoison
+
# exec gnome-session
+
# exec startfluxbox
+
# exec startxfce4
+
# exec xfce4-session
+
exec openbox-session
+
# exec startlxde
+
</nowiki>}}
+
 
+
Prepending {{ic|exec}} 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 to the window manager or desktop environment launcher when possible. You can get the path to it by using {{ic|type}} - i.e. {{ic|type startkde}}.
+
 
+
In addition to the examples provided here, you can find another at {{ic|/etc/skel/.xinitrc}} provided by {{Pkg|xorg-xinit}}. To use it, simply copy it to your home directory:
+
$ cp /etc/skel/.xinitrc ~/
+
  
 
== File configuration ==
 
== File configuration ==
Line 116: Line 99:
 
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 {{ic|~/.xinitrc}}. 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.
 
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 {{ic|~/.xinitrc}}. 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 {{ic|cairo-compmgr}}, {{ic|xscreensaver}}, {{ic|xsetroot}} and {{ic|sh}} are run in the background ({{ic|&}} suffix added). Otherwise, the script would halt and wait for each program and daemons to exit before executing {{ic|openbox-session}}. Also note that {{ic|openbox-session}} is not backgrounded. This ensures that the script will not quit until openbox does. If you run the {{ic|startx}} script manually, ending the script will terminate X and leave you with whatever virtual consoles {{ic|/etc/inittab}} has started.
+
Note that in the first example above, programs such as {{ic|cairo-compmgr}}, {{ic|xscreensaver}}, {{ic|xsetroot}} and {{ic|sh}} are run in the background ({{ic|&}} suffix added). Otherwise, the script would halt and wait for each program and daemons to exit before executing {{ic|openbox-session}}. Also note that {{ic|openbox-session}} is not backgrounded. This ensures that the script will not quit until openbox does.
 
+
If running the file from {{ic|/etc/inittab}} and have set the line to {{ic|respawn}} instead of {{ic|once}}, {{ic|~/.xinitrc}} will be re-run. This way X can be restarted without having to restart the computer.
+
  
 
The following sections explains how to configure {{ic|~/.xinitrc}} for Multiple WMs and DEs.
 
The following sections explains how to configure {{ic|~/.xinitrc}} for Multiple WMs and DEs.
Line 142: Line 123:
 
#
 
#
 
# Executed by startx (run your window manager from here)
 
# Executed by startx (run your window manager from here)
 +
 +
if [ -d /etc/X11/xinit/xinitrc.d ]; then
 +
  for f in /etc/X11/xinit/xinitrc.d/*; do
 +
    [ -x "$f" ] && . "$f"
 +
  done
 +
  unset f
 +
fi
  
 
if [[ $1 == "fluxbox" ]]
 
if [[ $1 == "fluxbox" ]]
 
then
 
then
 
   exec startfluxbox
 
   exec startfluxbox
elif [[ $1 == "scrotwm" ]]
+
elif [[ $1 == "spectrwm" ]]
 
then
 
then
   exec startscrotwm
+
   exec spectrwm
 
else
 
else
 
   echo "Choose a window manager"
 
   echo "Choose a window manager"
Line 154: Line 142:
 
</nowiki>}}
 
</nowiki>}}
  
Using this example you can start fluxbox or scrotwm with the command {{ic|xinit fluxbox}} or {{ic|xinit scrotwm}}.
+
Using this example you can start fluxbox or spectrwm with the command {{ic|xinit fluxbox}} or {{ic|xinit spectrwm}}.
  
 
=== At startup ===
 
=== At startup ===
  
You can also have a choice of window managers and desktop environments at startup, using just {{ic|~/.xinitrc}} and [[GRUB]] and no display manager. The idea is to take advantage of the fact that Arch does not make any particular use of the runlevel system. The following {{ic|~/.xinitrc}} tests for the current runlevel and will start [[Openbox]] and [[GNOME]] on runlevels 5 and 4 respectively:
+
See [[Start X at Login]].
 
+
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 {{ic|inittab}} 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/vmlinuz-linux root=/dev/sda1 ro 4
+
initrd /boot/initramfs-linux.img
+
 
+
Finally, you will need to ensure that the {{ic|~/.xinitrc}} file is actually run at the chosen runlevel. Using the tip from [[Start X at boot#/etc/inittab]], you can edit the {{ic|inittab}} to simply run {{ic|startx}} on the desired runlevel which will in turn use your {{ic|~/.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 {{ic|~/.xinitrc}} as described above. This is preferable to attempt differentiating in the {{ic|inittab}} file as we stick pretty close to using the various configuration files as they were intended.
+
 
+
==Tips and tricks==
+
 
+
=== PolicyKit and ConsoleKit ===
+
Various desktop environment features and applications expect [[PolicyKit]] and [[ConsoleKit]] 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 and ConsoleKit automatically. When only using {{ic|~/.xinitrc}} with your display manager e.g [[Slim]], you should execute the window manager as follows:
+
 
+
exec ck-launch-session gnome-session
+
 
+
{{Note|Beware that {{Package Official|polkit}} and {{Package Official|consolekit}} packages must be present in your installation.}}
+
 
+
{{Note|
+
As of 2011-10-09, there is combination of factor that cause a bug: if you have ''Not authorized'' error with any application in your desktop, this is it.
+
 
+
It is because you use the snippet (also found in {{ic|/etc/skel/.xinitrc}}) that source all the files in {{ic|/etc/X11/xinit/xinitrc.d}}
+
The problem is {{ic|/etc/X11/xinit/xinitrc.d/30-bus}} that launches dbus before {{ic|ck-launch-session}} is run, causing the bug FS#25031
+
 
+
To fix it either remove that snippet or use that line in your {{ic|~/.xinitrc}}
+
exec ck-launch-session dbus-launch gnome-session
+
 
+
until [https://bugs.archlinux.org/task/25031 FS#25031] is fixed. See also the notes of [[Xfce#Manually]] for more details }}
+
 
+
=== Starting the WM first ===
+
 
+
If you need to start your window manager before other additional applications, use the following method:
+
 
+
#!/bin/bash
+
+
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 ({{ic|$!}}) in the variable {{ic|wmpid}}. On the last line, the wait builtin is used to wait until the process specified by {{ic|wmpid}} terminates.
+
 
+
== More resources ==
+
* [http://www.slackbook.org/html/x-window-system-xinitrc.html slackbook.org]
+
* [http://fluxbox-wiki.org/index.php?title=.xinitrc .xinitrc @ Fluxbox-wiki]
+

Revision as of 15:34, 4 November 2012

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 ~/.xinitrc file is a shell script read by xinit and startx. It is mainly used to execute desktop environments, window managers and other programs when starting the X server (e.g., starting daemons and setting environment variables). The xinit and startx programs starts the X Window System and works as first client programs on systems that cannot start X directly from /etc/init, or in environments that use multiple window systems.

One of the main functions of ~/.xinitrc is to dictate which client for the X Window System is invoked with the /usr/bin/startx and/or /usr/bin/xinit program on a per-user basis. There exists numerous additional specifications and commands that may also be added to ~/.xinitrc as you further customize your system.

Getting started

/etc/skel/ contains files and directories to provide sane defaults for newly created user accounts. (The name skel is derived from the word skeleton, because the files it contains form the basic structure for users' home directories.) The xorg-xinit package will populate /etc/skel with a framework .xinitrc file.

Note: ~/.xinitrc is a so-called 'dot' (.) file. Files in a *nix file system which are preceded with a dot (.) are 'hidden' and will not show up with a regular ls command, usually for the sake of keeping directories tidy. Dot files may be seen by running ls -A. The 'rc' denotes Run Commands and simply indicates that it is a configuration file. Since it controls how a program runs, it is (although historically incorrect) also said to stand for "Run Control".

Copy the sample /etc/skel/.xinitrc file to your home directory:

$ cp /etc/skel/.xinitrc ~

Now, edit ~/.xinitrc and uncomment the line that corresponds to your DE/WM. For example, if you want to test your basic X configuration (mouse, keyboard, graphics resolution), you can simply use xterm:

#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)

if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

# exec gnome-session
# exec startkde
# exec startxfce4
# exec wmaker
# exec icewm
# exec blackbox
# exec fluxbox
# exec openbox-session
# ...or the Window Manager of your choice
exec xterm
Note: It is important that only one exec line is uncommented, or else only the first uncommented line will be run.

After editing ~/.xinitrc properly, it's time to run X. To run X as a non-root user, issue:

$ startx

Your DE/WM of choice should now start up. You are now free to test your keyboard with its layout, moving your mouse around and of course enjoy the view.

Preserving the session

X must always be run on the same tty where the login occurred, to preserve the logind session. This is handled by the default /etc/X11/xinit/xserverrc. Also see General Troubleshooting#Session permissions for related issues.

Note: In the past ck-launch-session was used to start a new session instead of simply not breaking the old one. There is no equivalent to this hack with logind, and a multi-seat aware display manager is required to run X on an arbitrary tty.

File examples

Following is a simple ~/.xinitrc file example, including some startup programs:

~/.xinitrc
#!/bin/sh

if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

xrdb -merge ~/.Xresources         # update x resources db

xscreensaver -no-splash &         # starts screensaver daemon 
xsetroot -cursor_name left_ptr &  # sets the cursor icon
sh ~/.fehbg &                     # sets the background image

exec openbox-session              # starts the window manager

Prepending exec is recommended as it replaces the current process with the process, so the script will stop running and X won't exit even if the process forks into the background.

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 ~/.xinitrc. 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 cairo-compmgr, xscreensaver, xsetroot and sh are run in the background (& suffix added). Otherwise, the script would halt and wait for each program and daemons to exit before executing openbox-session. Also note that openbox-session is not backgrounded. This ensures that the script will not quit until openbox does.

The following sections explains how to configure ~/.xinitrc for Multiple WMs and DEs.

On the command line

If you have a working ~/.xinitrc, but just want to try other WM/DE you can run it by issuing xinit 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 -- - e.g.:

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

The following example ~/.xinitrc shows how to start a particular window manager with an argument:

~/.xinitrc
#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)

if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

if [[ $1 == "fluxbox" ]]
then
  exec startfluxbox
elif [[ $1 == "spectrwm" ]]
then
  exec spectrwm
else
  echo "Choose a window manager"
fi

Using this example you can start fluxbox or spectrwm with the command xinit fluxbox or xinit spectrwm.

At startup

See Start X at Login.