https://wiki.archlinux.org/api.php?action=feedcontributions&user=N0name&feedformat=atomArchWiki - User contributions [en]2024-03-28T12:38:13ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Xinit&diff=269077Xinit2013-07-31T08:55:19Z<p>N0name: </p>
<hr />
<div>[[Category:Desktop environments]]<br />
[[Category:X Server]]<br />
[[de:Xinitrc]]<br />
[[el:Xinitrc]]<br />
[[es:Xinitrc]]<br />
[[fr:Startx]]<br />
[[it:Xinitrc]]<br />
[[ja:Xinitrc]]<br />
[[zh-CN:Xinitrc]]<br />
{{Article summary start}}<br />
{{Article summary text|An overview of the primary configuration file for the xinit (startx) program.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Display Manager}}<br />
{{Article summary wiki|Start X at Login}}<br />
{{Article summary wiki|Xorg}}<br />
{{Article summary wiki|xprofile}}<br />
{{Article summary end}} {{Lowercase title}}<br />
<br />
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.<br />
<br />
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.<br />
<br />
== Getting started ==<br />
<br />
{{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.<br />
<br />
{{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".}}<br />
<br />
Copy the sample {{ic|/etc/skel/.xinitrc}} file to your home directory:<br />
$ cp /etc/skel/.xinitrc ~<br />
<br />
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]]:<br />
<br />
{{bc|<br />
#!/bin/sh<br />
#<br />
# ~/.xinitrc<br />
#<br />
# Executed by startx (run your window manager from here)<br />
<br />
if [ -d /etc/X11/xinit/xinitrc.d ]; then<br />
for f in /etc/X11/xinit/xinitrc.d/*; do<br />
[ -x "$f" ] && . "$f"<br />
done<br />
unset f<br />
fi<br />
<br />
# exec gnome-session<br />
# exec startkde<br />
# exec startxfce4<br />
# exec wmaker<br />
# exec icewm<br />
# exec blackbox<br />
# exec fluxbox<br />
# exec openbox-session<br />
# ...or the Window Manager of your choice<br />
exec xterm<br />
}}<br />
<br />
{{Note|Make sure to uncomment only one {{ic|exec}} line, since that will be the last command run from the script; all the following lines will just be ignored. Do NOT attempt to background your WM by appending a `&` to the line.}}<br />
<br />
After editing {{ic|~/.xinitrc}} properly, it's time to run X. To run X as a non-root user, issue:<br />
$ startx<br />
$ xinit<br />
$ xinit -- :1<br />
<br />
{{Note|{{ic|xinit}} doesn't handle multiple session if you are already logged-in into some other vt. for that you have to specify session by appending {{ic|-- :''session_no''}}. If you are already running X then you should start with :1 or more.}}<br />
<br />
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.<br />
<br />
=== Making a DE/WM choice ===<br />
<br />
If you aren't using any graphical login manager or don't want to, you might have to edit the {{ic|~/.xinitrc}} very frequently.<br />
This can be easly solved by simple few line case addition which will take the argument and load the desire DE/WM.<br />
<br />
{{bc|<br />
#!/bin/sh<br />
#<br />
# ~/.xinitrc<br />
#<br />
# Executed by startx (run your window manager from here)<br />
<br />
if [ -d /etc/X11/xinit/xinitrc.d ]; then<br />
for f in /etc/X11/xinit/xinitrc.d/*; do<br />
[ -x "$f" ] && . "$f"<br />
done<br />
unset f<br />
fi<br />
<br />
# Here xfce is kept as default<br />
case $1 in<br />
gnome) exec gnome-session;;<br />
kde) exec startkde;;<br />
xfce);;<br />
*) exec startxfce4;;<br />
esac<br />
}}<br />
<br />
After editing {{ic|~/.xinitrc}}, you can easily start desire DE/WM by passing argument.<br />
$ xinit<br />
$ xinit gnome<br />
$ xinit kde<br />
$ xinit xfce -- :1<br />
<br />
=== Preserving the session ===<br />
<br />
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.<br />
<br />
{{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.}}<br />
<br />
== File examples==<br />
<br />
Following is a simple {{ic|~/.xinitrc}} file example, including some startup programs:<br />
{{hc|~/.xinitrc|<nowiki><br />
#!/bin/sh<br />
<br />
if [ -d /etc/X11/xinit/xinitrc.d ]; then<br />
for f in /etc/X11/xinit/xinitrc.d/*; do<br />
[ -x "$f" ] && . "$f"<br />
done<br />
unset f<br />
fi<br />
<br />
xrdb -merge ~/.Xresources # update x resources db<br />
<br />
xscreensaver -no-splash & # starts screensaver daemon <br />
xsetroot -cursor_name left_ptr & # sets the cursor icon<br />
sh ~/.fehbg & # sets the background image<br />
<br />
exec openbox-session # starts the window manager<br />
</nowiki>}}<br />
<br />
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.<br />
<br />
== File configuration ==<br />
<br />
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.<br />
<br />
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.<br />
<br />
The following sections explains how to configure {{ic|~/.xinitrc}} for multiple WMs and DEs.<br />
<br />
=== On the command line ===<br />
<br />
If you have a working {{ic|~/.xinitrc}}, but just want to try other WM/DE you can run it by issuing {{ic|xinit}} followed by the path to the window manager:<br />
<br />
$ xinit /full/path/to/window-manager<br />
<br />
Note that the full path is '''required'''. Optionally, you can pass options to the X server after appending {{ic|--}} - e.g.:<br />
<br />
$ xinit /usr/bin/enlightenment -- -br +bs -dpi 96<br />
<br />
The following example {{ic|~/.xinitrc}} shows how to start a particular window manager with an argument:<br />
<br />
{{hc|~/.xinitrc|<nowiki><br />
#!/bin/sh<br />
#<br />
# ~/.xinitrc<br />
#<br />
# Executed by startx (run your window manager from here)<br />
<br />
if [ -d /etc/X11/xinit/xinitrc.d ]; then<br />
for f in /etc/X11/xinit/xinitrc.d/*; do<br />
[ -x "$f" ] && . "$f"<br />
done<br />
unset f<br />
fi<br />
<br />
if [[ $1 == "fluxbox" ]]; then<br />
exec startfluxbox<br />
elif [[ $1 == "spectrwm" ]]; then<br />
exec spectrwm<br />
else<br />
echo "Choose a window manager"<br />
fi<br />
</nowiki>}}<br />
<br />
Using this example you can start fluxbox or spectrwm with the command {{ic|xinit fluxbox}} or {{ic|xinit spectrwm}}.<br />
<br />
=== At startup ===<br />
<br />
See [[Start X at Login]].</div>N0name