https://wiki.archlinux.org/api.php?action=feedcontributions&user=Zowki&feedformat=atomArchWiki - User contributions [en]2024-03-29T14:33:06ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Xinit&diff=93479Xinit2010-01-24T15:13:47Z<p>Zowki: start window manager using command line argument</p>
<hr />
<div>[[Category:Desktop environments (English)]]<br />
[[Category:Boot process (English)]]<br />
[[Category:X Server (English)]]<br />
[[Category:HOWTOs (English)]]<br />
{{Article summary start}}<br />
{{Article summary text|An overview of the primary configuration file for the xinit (startx) program.}}<br />
{{Article summary heading|Available in languages}}<br />
{{i18n entry|English|Xinitrc}}<br />
{{i18n entry|Ελληνικά|Starting different desktop environments HOWTO (Ελληνικά)}}<br />
{{i18n entry|简体中文|Xinitrc (简体中文)}}<br />
{{i18n entry|Español|cómo iniciar los distintos entornos de escritorio}}<br />
{{Article summary heading|Related articles}}<br />
{{Article summary wiki|Xorg}}<br />
{{Article summary wiki|Start X at boot}}<br />
{{Article summary wiki|Automatic login manager startup}}<br />
{{Article summary end}} {{DISPLAYTITLE:xinitrc}}<br />
<br />
The xinit program is used to start the X Window System server and a first client program on systems that cannot start X directly from {{Filename|/etc/init}} or in environments that use multiple window systems. The {{Filename|.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 {{Filename|inittab}}]].<br />
<br />
== How it works ==<br />
<br />
The {{Filename|.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. <br />
<br />
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 {{Filename|.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 {{Filename|.xinitrc}} script, e.g.:<br />
<br />
{{File<br />
|name=~/.xinitrc<br />
|content=<nowiki><br />
#!/bin/sh<br />
<br />
/usr/bin/autocutsel -fork &<br />
/usr/bin/autocutsel -selection PRIMARY -fork &<br />
/usr/local/bin/urxvtd -q -f -o &<br />
/usr/bin/xscreensaver -no-splash &<br />
/usr/lib/notification-daemon/notification-daemon &<br />
<br />
export MOZ_PLUGIN_PATH="/usr/lib/mozilla/plugins:/opt/mozilla/lib/plugins"<br />
<br />
exec openbox-session<br />
</nowiki>}}<br />
<br />
Notice that applications such as {{Codeline|autocutsel}}, {{Codeline|xscreensaver}}, {{Codeline|urxvtd}}, and {{Codeline|notification-daemon}} are run in the background ({{Codeline|&}} appendage). Otherwise the script would halt and wait for the programs and daemons to quit before continuing to export the variable line and executing {{Codeline|openbox-session}}. <br />
<br />
The {{Codeline|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 {{Codeline|startx}} script manually, ending the script will terminate X and leave you with whatever virtual consoles your {{Filename|inittab}} has started. <br />
<br />
If you're running it from {{Filename|inittab}} and have set the line to 'respawn' (rather than 'once'), {{Filename|.xinitrc}} will be run again. This way you can restart X without having to restart the computer.<br />
<br />
== A standard .xinitrc ==<br />
<br />
Using this template you can simply uncomment your choice, e.g. [[GNOME]]:<br />
<br />
{{File<br />
|name=~/.xinitrc<br />
|content=<nowiki><br />
#!/bin/sh<br />
#<br />
# ~/.xinitrc<br />
#<br />
# Executed by startx (run your window manager from here)<br />
#<br />
# exec ion<br />
# exec jwm<br />
# exec wmaker<br />
# exec startkde<br />
# exec icewm<br />
# exec blackbox<br />
exec gnome-session<br />
# exec startfluxbox<br />
# exec startxfce4<br />
# exec xfce4-session<br />
# exec openbox<br />
# exec startlxde<br />
</nowiki>}}<br />
<br />
{{Note|Prepending {{Codeline|exec}} is not necessary as long as additional desktop/window managers are commented out as they are in the above example.}}<br />
<br />
== Multiple DE options ==<br />
<br />
=== On the command line ===<br />
<br />
If you have a working {{Filename|.xinitrc}}, but just want to try other WM/DE you can run {{Codeline|xinit}} from command line like this<br />
<br />
xinit /full/path/to/window-manager<br />
<br />
The full path is '''required'''. Optionally you can pass options to X server after '--', e.g.<br />
<br />
xinit /usr/bin/enlightenment -- -br +bs -dpi 96<br />
<br />
You can put this in to your .xinitrc to start a particular window manager with an argument:<br />
{{File<br />
|name=~/.xinitrc<br />
|content=<nowiki><br />
#!/bin/sh<br />
#<br />
# ~/.xinitrc<br />
#<br />
# Executed by startx (run your window manager from here)<br />
<br />
if [[ $1 == "fluxbox" ]]<br />
then<br />
exec startfluxbox<br />
elif [[ $1 == "scrotwm" ]]<br />
then<br />
exec startscrotwm<br />
else<br />
echo "Choose a window manager"<br />
fi<br />
</nowiki>}}<br />
Using this xinitrc you can start Fluxbox with the command "xinit fluxbox" or start ScrotWm with the command "xinit scrotwm".<br />
<br />
=== At startup ===<br />
<br />
You can also have a choice of window managers and desktop environments at startup, using just {{Filename|.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 {{Filename|.xinitrc}} tests for the current runlevel and will start [[Openbox]] and [[GNOME]] on runlevels 5 and 4 respectively:<br />
<br />
rl=$(runlevel | grep -o [0-6])<br />
<br />
case $rl in<br />
4) exec gnome-session;;<br />
5) exec openbox-session;;<br />
esac<br />
<br />
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 {{Filename|inittab}} default of runlevel 5 should be overridden and replaced with the desired runlevel, 4 in this instance:<br />
<br />
title Arch Linux GNOME<br />
root (hd0,2)<br />
kernel /boot/vmlinuz26 root=/dev/sda1 ro 4<br />
initrd /boot/kernel26.img<br />
<br />
Finally, you will need to ensure that the {{Filename|.xinitrc}} file is actually run at the chosen runlevel. Using the tip from [[Start X at boot#/etc/inittab]], you can edit the {{Filename|inittab}} to simply run {{Codeline|startx}} on the desired runlevel which will in turn use your {{Filename|.xinitrc}} script:<br />
<br />
x:45:once:/bin/su PREFERED_USER -l -c "/bin/bash --login -c startx >/dev/null 2>&1"<br />
<br />
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 {{Filename|.xinitrc}} as described above. This is preferable to attempt differentiating in the {{Filename|inittab}} file as we stick pretty close to using the various configuration files as they were intended.<br />
<br />
== External links ==<br />
<br />
* [http://fluxbox-wiki.org/index.php?title=.xinitrc .xinitrc @ Fluxbox-wiki]</div>Zowki