Difference between revisions of "Xinit"

From ArchWiki
Jump to: navigation, search
(Getting started: add some note about xinit)
(Reorganise article, remove redundant examples)
Line 17: Line 17:
 
{{Article summary end}} {{Lowercase title}}
 
{{Article summary end}} {{Lowercase title}}
  
The {{ic|~/.xinitrc}} file is a shell script read by {{ic|xinit}} and by its front end {{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}} program starts the [[Xorg|X Window System]] server and works as first client program on systems that are not using a [[display manager]].
+
The {{ic|~/.xinitrc}} file is a shell script read by {{ic|xinit}} and by its front-end {{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}} program starts the [[Xorg|X Window System]] server and works as first client program on systems that are not using a [[display manager]].
  
 
One of the main functions of {{ic|~/.xinitrc}} is to dictate which client for the X Window System is invoked with {{ic|startx}} or {{ic|xinit}} programs 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.
 
One of the main functions of {{ic|~/.xinitrc}} is to dictate which client for the X Window System is invoked with {{ic|startx}} or {{ic|xinit}} programs 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.
Line 25: Line 25:
 
{{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.
 
{{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".}}
+
{{Tip|{{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:
Line 73: Line 73:
 
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.
 
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.
  
=== Making a DE/WM choice ===
+
== Configuration ==
  
If you aren't using any graphical login manager or don't want to, you might have to edit the {{ic|~/.xinitrc}} very frequently.
+
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.
This can be easly solved by simple few line case addition which will take the argument and load the desire DE/WM.
 
  
{{bc|
+
Following is a simple {{ic|~/.xinitrc}} file example, including some startup programs:
#!/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
 
 
 
# Here xfce is kept as default
 
case $1 in
 
        gnome) exec gnome-session;;
 
        kde) exec startkde;;
 
        xfce);;
 
        *) exec startxfce4;;
 
esac
 
}}
 
  
After editing {{ic|~/.xinitrc}}, you can easily start desire DE/WM by passing argument.
 
$ xinit
 
$ xinit gnome
 
$ xinit kde
 
$ xinit xfce -- :1
 
 
=== Preserving the session ===
 
 
See [[General Troubleshooting#Session permissions]] for details.
 
 
== File examples==
 
 
Following is a simple {{ic|~/.xinitrc}} file example, including some startup programs:
 
 
{{hc|~/.xinitrc|<nowiki>
 
{{hc|~/.xinitrc|<nowiki>
 
#!/bin/sh
 
#!/bin/sh
Line 133: Line 98:
 
</nowiki>}}
 
</nowiki>}}
  
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.
+
Note that in the example above, programs such as {{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.
 +
 
 +
Prepending the window manager {{ic|openbox-session}} with {{ic|exec}} is recommended as it replaces the current process with that process, so the script will stop running and X won't exit even if the process forks into the background.
 +
 
 +
== Tips and tricks ==
  
== File configuration ==
+
=== Override xinitrc from command line ===
  
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.
+
If you have a working {{ic|~/.xinitrc}}, but just want to try other WM/DE, you can run it by issuing {{ic|startx}} followed by the path to the window manager:
  
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.
+
$ startx /full/path/to/window-manager
  
The following sections explains how to configure {{ic|~/.xinitrc}} for multiple WMs and DEs.
+
Note that the full path is '''required'''. Optionally, you can also override {{ic|/etc/X11/xinit/xserverrc}} file (which stores the default X server options) with custom options by appending them after {{ic|--}}, e.g.:
  
=== On the command line ===
+
$ startx /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR
  
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:
+
or
  
  $ xinit /full/path/to/window-manager
+
  $ xinit /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR
  
Note that the full path is '''required'''. Optionally, you can pass options to the X server after appending {{ic|--}} - e.g.:
+
=== Making a DE/WM choice ===
  
$ xinit /usr/bin/enlightenment -- -br +bs -dpi 96
+
If you aren't using any graphical login manager or don't want to, you might have to edit the {{ic|~/.xinitrc}} very frequently. This can be easily solved by simple few line case addition, which will take the argument and load the desired desktop environment or window manager.
  
The following example {{ic|~/.xinitrc}} shows how to start a particular window manager with an argument:
+
The following example {{ic|~/.xinitrc}} shows how to start a particular DE/WM with an argument:
  
 
{{hc|~/.xinitrc|<nowiki>
 
{{hc|~/.xinitrc|<nowiki>
Line 169: Line 138:
 
fi
 
fi
  
if [[ $1 == "fluxbox" ]]; then
+
# Here Xfce is kept as default
         exec startfluxbox
+
session=${1:-xfce}
elif [[ $1 == "spectrwm" ]]; then
+
 
         exec spectrwm
+
case $session in
else
+
        enlightenment) exec enlightenment_start;;
         echo "Choose a window manager"
+
        fluxbox) exec startfluxbox;;
fi
+
         gnome) exec gnome-session;;
 +
        lxde) exec startlxde;;
 +
        kde) exec startkde;;
 +
        openbox) exec openbox-session;;
 +
         xfce) exec startxfce4;;
 +
        # No known session, try to run it as command
 +
         *) exec $1;;               
 +
esac
 
</nowiki>}}
 
</nowiki>}}
  
Using this example you can start fluxbox or spectrwm with the command {{ic|xinit fluxbox}} or {{ic|xinit spectrwm}}.
+
Then copy the {{ic|/etc/X11/xinit/xserverrc}} file into your home directory:
 +
 
 +
$ cp /etc/X11/xinit/xserverrc ~/.xserverrc
  
=== At startup ===
+
After that, you can easily start a particular DE/WM by passing an argument, e.g.:
  
See [[Start X at Login]].
+
$ xinit
 +
$ xinit gnome
 +
$ xinit kde
 +
$ xinit wmaker
 +
 
 +
or
 +
 
 +
$ startx
 +
$ startx ~/xinitrc gnome
 +
$ startx ~/xinitrc kde
 +
$ startx ~/xinitrc wmaker

Revision as of 13:12, 22 November 2013

zh-CN:Xinitrc 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 by its front-end 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 program starts the X Window System server and works as first client program on systems that are not using a display manager.

One of the main functions of ~/.xinitrc is to dictate which client for the X Window System is invoked with startx or xinit programs 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.

Tip: ~/.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: Make sure to uncomment only one 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.

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

$ startx

or

$ xinit -- :1 -nolisten tcp vt$XDG_VTNR
Note:
  • xinit doesn't read the system-wide /etc/X11/xinit/xserverrc file, so you either have to copy it into your home directory as name .xserverrc, or specify vt$XDG_VTNR as command line option in order to preserve session permissions.
  • xinit doesn't handle multiple sessions if you are already logged-in into some other virtual terminal. For that you have to specify session by appending -- :session_no. If you are already running X then you should start with :1 or more.

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.

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.

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

Note that in the example above, programs such as 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.

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

Tips and tricks

Override xinitrc from command line

If you have a working ~/.xinitrc, but just want to try other WM/DE, you can run it by issuing startx followed by the path to the window manager:

$ startx /full/path/to/window-manager

Note that the full path is required. Optionally, you can also override /etc/X11/xinit/xserverrc file (which stores the default X server options) with custom options by appending them after --, e.g.:

$ startx /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR

or

$ xinit /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR

Making a DE/WM choice

If you aren't using any graphical login manager or don't want to, you might have to edit the ~/.xinitrc very frequently. This can be easily solved by simple few line case addition, which will take the argument and load the desired desktop environment or window manager.

The following example ~/.xinitrc shows how to start a particular DE/WM 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

# Here Xfce is kept as default
session=${1:-xfce}

case $session in
        enlightenment) exec enlightenment_start;;
        fluxbox) exec startfluxbox;;
        gnome) exec gnome-session;;
        lxde) exec startlxde;;
        kde) exec startkde;;
        openbox) exec openbox-session;;
        xfce) exec startxfce4;;
        # No known session, try to run it as command
        *) exec $1;;                
esac

Then copy the /etc/X11/xinit/xserverrc file into your home directory:

$ cp /etc/X11/xinit/xserverrc ~/.xserverrc

After that, you can easily start a particular DE/WM by passing an argument, e.g.:

$ xinit
$ xinit gnome
$ xinit kde
$ xinit wmaker

or

$ startx
$ startx ~/xinitrc gnome
$ startx ~/xinitrc kde
$ startx ~/xinitrc wmaker