Difference between revisions of "Xinit"

From ArchWiki
Jump to: navigation, search
(remove Desktop environments category, while xinit can be used to start DEs it is unaware of them)
 
(26 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
{{Lowercase title}}
 
{{Lowercase title}}
[[Category:X server]]
+
[[Category:Xorg commands]]
 
[[de:Xinitrc]]
 
[[de:Xinitrc]]
 
[[el:Xinitrc]]
 
[[el:Xinitrc]]
[[es:Xinitrc]]
+
[[es:Xinit]]
 
[[fr:Startx]]
 
[[fr:Startx]]
 
[[it:Xinitrc]]
 
[[it:Xinitrc]]
 
[[ja:Xinitrc]]
 
[[ja:Xinitrc]]
 +
[[pt:Xinit]]
 
[[ru:Xinitrc]]
 
[[ru:Xinitrc]]
 
[[zh-hans:Xinit]]
 
[[zh-hans:Xinit]]
Line 18: Line 19:
 
:The '''xinit''' program allows a user to manually start an [[Xorg]] display server. The {{man|1|startx}} script is a front-end for {{man|1|xinit}}.
 
:The '''xinit''' program allows a user to manually start an [[Xorg]] display server. The {{man|1|startx}} script is a front-end for {{man|1|xinit}}.
  
''xinit'' and ''startx'' take an optional client program argument. If you do not provide one they will look for {{ic|~/.xinitrc}} to run as a shell script to start up client programs.
+
''xinit'' is typically used to start [[window manager]]s or [[desktop environment]]s. While you can also use ''xinit'' to run GUI applications without a window manager, many graphical applications expect an [[Wikipedia:Extended Window Manager Hints|EWMH]] compliant window manager. [[Display manager]]s start [[Xorg]] for you and generally source [[xprofile]].  
Executing {{ic|xinit /usr/bin/foo}} is therefore equivalent to running {{ic|xinit}} with {{ic|exec foo}} in your {{ic|~/.xinitrc}}.
 
 
 
''xinit'' is typically used to start [[window manager]]s or [[desktop environment]]s. While you can also use ''xinit'' to run GUI applications without a window manager, many graphical applications expect an [[Wikipedia:Extended Window Manager Hints|EWMH]] compliant window manager. {{ic|~/.xinitrc}} is handy to run programs depending on X and set environment variables on X server startup. [[Display manager]]s start [[Xorg]] for you and generally source [[xprofile]].  
 
  
 
== Installation ==
 
== Installation ==
Line 28: Line 26:
  
 
== Configuration ==
 
== Configuration ==
 +
 +
''xinit'' and ''startx'' take an optional client program argument, see [[#Override xinitrc]].  If you do not provide one they will look for {{ic|~/.xinitrc}} to run as a shell script to start up client programs.
  
 
=== xinitrc ===
 
=== xinitrc ===
  
If {{ic|.xinitrc}} is present in a user's home directory, ''startx'' and ''xinit'' execute it. Otherwise ''startx'' will run the default {{ic|/etc/X11/xinit/xinitrc}}.
+
{{ic|~/.xinitrc}} is handy to run programs depending on X and set environment variables on X server startup. If it is present in a user's home directory, ''startx'' and ''xinit'' execute it. Otherwise ''startx'' will run the default {{ic|/etc/X11/xinit/xinitrc}}.
 +
 
 
{{note|''Xinit'' has its own default behaviour instead of executing the file. See {{man|1|xinit}} for details.}}
 
{{note|''Xinit'' has its own default behaviour instead of executing the file. See {{man|1|xinit}} for details.}}
 +
 
This default xinitrc will start a basic environment with [[Twm]], {{Pkg|xorg-xclock}} and [[Xterm]] (assuming that the necessary packages are installed). Therefore, to start a different window manager or desktop environment, first create a copy of the default {{ic|xinitrc}} in your home directory:
 
This default xinitrc will start a basic environment with [[Twm]], {{Pkg|xorg-xclock}} and [[Xterm]] (assuming that the necessary packages are installed). Therefore, to start a different window manager or desktop environment, first create a copy of the default {{ic|xinitrc}} in your home directory:
  
Line 44: Line 46:
 
exec openbox-session}}
 
exec openbox-session}}
  
{{Note|At the very least, ensure that the last if block in {{ic|/etc/X11/xinit/xinitrc}} is present in your {{ic|.xinitrc}} file to ensure that the scripts in {{ic|/etc/X11/xinit/xinitrc.d}} are sourced.}}   
+
{{Note|At the very least, ensure that the last if block in {{ic|/etc/X11/xinit/xinitrc}} is present in your {{ic|~/.xinitrc}} file to ensure that the scripts in {{ic|/etc/X11/xinit/xinitrc.d}} are sourced.}}   
  
 
Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an {{ic|&}} sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of [[xrdb]]. Prepending {{ic|exec}} will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.
 
Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an {{ic|&}} sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of [[xrdb]]. Prepending {{ic|exec}} will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.
Line 74: Line 76:
 
  $ startx
 
  $ startx
  
or
+
Or if [[#xserverrc]] is configured:
  
 
  $ xinit -- :1
 
  $ xinit -- :1
  
{{Note|''xinit'' does not handle multiple displays when another X server is already started. For that you must specify the display by appending {{ic|-- :''display_number''}}, where {{ic|''display_number''}} is 1 or more.}}
+
{{Note|''xinit'' does not handle multiple displays when another X server is already started. For that you must specify the display by appending {{ic|-- :''display_number''}}, where {{ic|''display_number''}} is {{ic|1}} or more.}}
  
 
Your window manager (or desktop environment) of choice should now start correctly.
 
Your window manager (or desktop environment) of choice should now start correctly.
Line 91: Line 93:
 
}}
 
}}
  
== Autostart X at login ==
+
See also {{man|7|signal}}.
 +
 
 +
== Tips and tricks ==
 +
 
 +
=== Autostart X at login ===
  
 
Make sure that ''startx'' is properly [[#Configuration|configured]].
 
Make sure that ''startx'' is properly [[#Configuration|configured]].
Line 113: Line 119:
 
{{Tip|This method can be combined with [[automatic login to virtual console]].}}
 
{{Tip|This method can be combined with [[automatic login to virtual console]].}}
  
== Tips and tricks ==
+
=== Override xinitrc ===
  
=== Override xinitrc from command line ===
+
If you have a working {{ic|~/.xinitrc}} but just want to try other window manager or desktop environment, you can run it by issuing ''startx'' followed by the path to the window manager, for example:
  
If you have a working {{ic|~/.xinitrc}}, but just want to try other window manager or desktop environment, you can run it by issuing ''startx'' followed by the path to the window manager:
+
$ startx /usr/bin/i3
  
$ startx /full/path/to/window-manager
+
If the binary takes arguments, they need to be quoted to be recognized as part of the first parameter of ''startx'':
  
If the window manager takes arguments, they need to be quoted to be recognized as part of the first parameter of ''startx'':
+
$ startx "/usr/bin/''application'' --''key value''"
  
$ startx "/full/path/to/window-manager --key value"
+
Note that the full path is '''required'''. You can also specify custom options for the [[#xserverrc]] script by appending them after the double dash {{ic|--}} sign:
 
 
Note that the full path is '''required'''. Optionally, you can also specify custom options for [[#xserverrc]] script by appending them after {{ic|--}}, e.g.:
 
  
 
  $ startx /usr/bin/enlightenment -- -br +bs -dpi 96
 
  $ startx /usr/bin/enlightenment -- -br +bs -dpi 96
Line 131: Line 135:
 
See also {{man|1|startx}}.
 
See also {{man|1|startx}}.
  
{{Tip|This can be used even to start a regular GUI programs but without any of the window manager features. See also [[#Starting applications without a window manager]] and [[Running program in separate X display]].}}
+
{{Tip|This can be used to start regular GUI programs but without any of the basic window manager features. See also [[#Start applications only]] and [[Running program in separate X display]].}}
  
 
=== Switching between desktop environments/window managers ===
 
=== Switching between desktop environments/window managers ===
  
If you are frequently switching between different desktop environments or window managers, it is convenient to either use a [[display manager]] or expand {{ic|.xinitrc}} to make the switching possible.
+
If you are frequently switching between different desktop environments or window managers, it is convenient to either use a [[display manager]] or expand {{ic|~/.xinitrc}} to make the switching possible.
  
The following example {{ic|~/.xinitrc}} shows how to start a particular desktop environment or window manager with an argument:
+
The following example shows how to start a particular desktop environment or window manager with an argument:
  
 
{{hc|~/.xinitrc|<nowiki>
 
{{hc|~/.xinitrc|<nowiki>
Line 162: Line 166:
 
  $ startx ~/.xinitrc ''session''
 
  $ startx ~/.xinitrc ''session''
  
=== Starting applications without a window manager ===
+
=== Start applications only ===
  
 
It is possible to start only specific applications without a window manager, although most likely this is only useful with a single application shown in full-screen mode. For example:
 
It is possible to start only specific applications without a window manager, although most likely this is only useful with a single application shown in full-screen mode. For example:
Line 172: Line 176:
 
}}
 
}}
  
With this method you need to set each application window's geometry through its own configuration files, if possible at all.
+
Alternatively the binary can be called directly from the command prompt as described in [[#Override xinitrc]].
 +
 
 +
With this method you need to set each application's window geometry through its own configuration files (if possible at all).
  
{{Tip|This method can be useful to launch graphical games, especially on systems where excluding the memory or CPU usage of a window manager or desktop environment, and possible accessory applications, can help improve the game's execution performance.}}
+
{{Tip|This can be useful to launch graphical games, where excluding the overhead of a compositor can help improve the game's performance.}}
  
 
See also [[Display manager#Starting applications without a window manager]].
 
See also [[Display manager#Starting applications without a window manager]].

Latest revision as of 11:37, 13 November 2018

From Wikipedia:

The xinit program allows a user to manually start an Xorg display server. The startx(1) script is a front-end for xinit(1).

xinit is typically used to start window managers or desktop environments. While you can also use xinit to run GUI applications without a window manager, many graphical applications expect an EWMH compliant window manager. Display managers start Xorg for you and generally source xprofile.

Installation

Install the xorg-xinit package.

Configuration

xinit and startx take an optional client program argument, see #Override xinitrc. If you do not provide one they will look for ~/.xinitrc to run as a shell script to start up client programs.

xinitrc

~/.xinitrc is handy to run programs depending on X and set environment variables on X server startup. If it is present in a user's home directory, startx and xinit execute it. Otherwise startx will run the default /etc/X11/xinit/xinitrc.

Note: Xinit has its own default behaviour instead of executing the file. See xinit(1) for details.

This default xinitrc will start a basic environment with Twm, xorg-xclock and Xterm (assuming that the necessary packages are installed). Therefore, to start a different window manager or desktop environment, first create a copy of the default xinitrc in your home directory:

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

Then edit the file and replace the default programs with desired commands. Remember that lines following a command using exec would be ignored. For example, to start xscreensaver in the background and then start openbox, use the following:

~/.xinitrc
...
xscreensaver &
exec openbox-session
Note: At the very least, ensure that the last if block in /etc/X11/xinit/xinitrc is present in your ~/.xinitrc file to ensure that the scripts in /etc/X11/xinit/xinitrc.d are sourced.

Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an & sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of xrdb. Prepending exec will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.

xserverrc

The xserverrc file is a shell script responsible for starting up the X server. Both startx and xinit execute ~/.xserverrc if it exists, startx will use /etc/X11/xinit/xserverrc otherwise.

In order to maintain an authenticated session with logind and to prevent bypassing the screen locker by switching terminals, Xorg has to be started on the same virtual terminal where the login occurred [1]. Therefore it is recommended to specify vt$XDG_VTNR in the ~/.xserverrc file:

~/.xserverrc
#!/bin/sh

exec /usr/bin/Xorg -nolisten tcp "$@" vt$XDG_VTNR

See Xserver(1) for a list of all command line options.

Tip: -nolisten local can be added after -nolisten tcp to disable abstract sockets of X11 to help with isolation. There is a quick background on how this potentially affects X11 security.

Alternatively, if you wish to have the X display on a separate console from the one where the server is invoked, you can do so by using the X server wrapper provided by /usr/lib/systemd/systemd-multi-seat-x. For convenience, xinit and startx can be set up to use this wrapper by modifying your ~/.xserverrc.

Note: To re-enable redirection of the output from X session into the Xorg log file, add the -keeptty option. See Xorg#Broken redirection for details.

Usage

To run Xorg as a regular user, issue:

$ startx

Or if #xserverrc is configured:

$ xinit -- :1
Note: xinit does not handle multiple displays when another X server is already started. For that you must specify the display by appending -- :display_number, where display_number is 1 or more.

Your window manager (or desktop environment) of choice should now start correctly.

To quit X, run your window manager's exit function (assuming it has one). If it lacks such functionality, run:

$ pkill -15 Xorg
Note: pkill will kill all running X instances. To specifically kill the window manager on the current virtual terminal, run:
$ pkill -15 -t tty"$XDG_VTNR" Xorg

See also signal(7).

Tips and tricks

Autostart X at login

Make sure that startx is properly configured.

For Bash, add the following to the bottom of ~/.bash_profile. If the file does not exist, copy a skeleton version from /etc/skel/.bash_profile. For Zsh, add it to ~/.zprofile.

if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
  exec startx
fi

You can replace the -eq comparison with one like -le 3 (for vt1 to vt3) if you want to use graphical logins on more than one virtual terminal.

Alternative conditions to detect the virtual terminal include "$(tty)" = "/dev/tty1", which does not allow comparison with -le, and "$(fgconsole 2>/dev/null || echo -1)" -eq 1, which does not work in serial consoles.

If you would like to remain logged in when the X session ends, remove exec.

See also Fish#Start X at login and Systemd/User#Automatic login into Xorg without display manager.

Tip: This method can be combined with automatic login to virtual console.

Override xinitrc

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

$ startx /usr/bin/i3

If the binary takes arguments, they need to be quoted to be recognized as part of the first parameter of startx:

$ startx "/usr/bin/application --key value"

Note that the full path is required. You can also specify custom options for the #xserverrc script by appending them after the double dash -- sign:

$ startx /usr/bin/enlightenment -- -br +bs -dpi 96

See also startx(1).

Tip: This can be used to start regular GUI programs but without any of the basic window manager features. See also #Start applications only and Running program in separate X display.

Switching between desktop environments/window managers

If you are frequently switching between different desktop environments or window managers, it is convenient to either use a display manager or expand ~/.xinitrc to make the switching possible.

The following example shows how to start a particular desktop environment or window manager with an argument:

~/.xinitrc
...

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

case $session in
    i3|i3wm           ) exec i3;;
    kde               ) exec startkde;;
    xfce|xfce4        ) exec startxfce4;;
    # No known session, try to run it as command
    *                 ) exec $1;;
esac

To pass the argument session:

$ xinit session

or

$ startx ~/.xinitrc session

Start applications only

It is possible to start only specific applications without a window manager, although most likely this is only useful with a single application shown in full-screen mode. For example:

~/.xinitrc
...

exec chromium

Alternatively the binary can be called directly from the command prompt as described in #Override xinitrc.

With this method you need to set each application's window geometry through its own configuration files (if possible at all).

Tip: This can be useful to launch graphical games, where excluding the overhead of a compositor can help improve the game's performance.

See also Display manager#Starting applications without a window manager.

Output redirection using startx

See Xorg#Broken redirection for details.