3 # startx configuration file.
5 # Copyright (C) 2011-2014 Simon Ruderich
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # Some systems don't set the LANG environment variable when starting xinitrc,
22 # this causes problems for rxvt-unicode-256color which fails to display UTF-8
23 # characters correctly when LANG is missing and for notify.py which also needs
24 # LANG set (for Python's decode() function). Therefore load my general shell
25 # environment which also includes $LANG.
26 if test -f "$HOME/.shell/env"; then
27 # Debug function used in ~/.shell/env.
38 type "$1" >/dev/null 2>&1
41 if installed xmessage; then
44 # Log message to a file which is displayed by my Zsh setup on startup.
45 printf '%s\n' "$*" >>"$HOME/.xinitrc.errors"
48 # Save PID of the most recently started background process. Used to terminate
49 # them when logging out to prevent unused background processes. On some
50 # systems this is only necessary for some programs (like ssh-agent), haven't
51 # yet figured out why.
52 save_background_pid() {
53 background_pids="$background_pids $!"
58 # Options, can be modified in ~/.xinitrc.local. To disable a boolean option
59 # set it to an empty value.
61 # Default to use a background image.
63 # Default to display a warning if `xautolock` is not available.
65 # Lock screen after x minutes of inactivity, requires `xautolock` to be
68 # Locker program to lock the screen, used below with `xautolock`.
71 # Load settings for the local system.
72 if test -f "$HOME/.xinitrc.local"; then
73 . "$HOME/.xinitrc.local"
77 # Start ssh-agent if no agent is running and we have private keys, thanks to
78 # http://code.haskell.org/XMonadContrib/scripts/xinitrc (read on 2011-06-19).
79 if test -z "$SSH_AGENT_PID" \
80 && test -x /usr/bin/ssh-agent \
81 && test -f "$HOME/.ssh/id_rsa"; then
82 # -s to force bourne shell output. This file is a bourne shell script even
83 # if the environment might suggest otherwise.
84 eval `/usr/bin/ssh-agent -s` >/dev/null
87 # Use a black background for the root window.
90 # Force English keyboard layout.
91 if installed setxkbmap; then
95 # Use the Caps lock as Ctrl because it's easier to reach and very useful for
96 # all programs. Caps lock is removed completely. Thanks to
97 # http://snarfed.org/space/switch%20control%20and%20caps%20lock
98 if xmodmap | grep -E '^lock.*Caps_Lock' >/dev/null; then
99 xmodmap -e 'remove Lock = Caps_Lock'
100 xmodmap -e 'remove Control = Control_L'
101 xmodmap -e 'keysym Caps_Lock = Control_L'
102 xmodmap -e 'add Control = Control_L'
104 # Move grave and tilde next to left shift key. This setting may only be
105 # necessary because of my German keyboard which I use with English settings.
106 xmodmap -e 'keycode 94 = grave asciitilde'
108 # Disable annoying audio bell. Thanks to Sebastian Rachuj.
111 # Load settings for programs. Xdefaults is deprecated.
114 # Change the background if available.
115 if test -f "$HOME/.background" && test -n "$set_background"; then
116 if installed hsetroot; then
117 hsetroot -full "$HOME/.background"
118 elif installed feh; then
119 feh --bg-scale "$HOME/.background"
120 # Remove the unnecessary ~/.fehbg file created by `feh`. I don't want
121 # to restore the background, I just run `feh` on each startx run.
122 # --no-fehbg is only available in recent feh releases.
127 # Display timed reminders and recheck the file for changes every minute (-z1).
128 if installed remind && test -f "$HOME/.reminders"; then
129 remind -z1 -k'.shell/bin/notify.py %s &' "$HOME/.reminders" &
133 # Set color temperature of display according to time of day.
134 if installed redshift; then
135 redshift -l 49.9:10.9 -t 5500:4500 >/dev/null &
138 # Automatically lock the screen after x minutes of inactivity if `xautolock`
139 # is available. Warn if locker wasn't found.
140 if installed xautolock; then
141 if installed "$screen_locker"; then
142 xautolock -secure -time "$screen_lock_time" -locker "$screen_locker" &
144 error "Locker '$screen_locker' not installed. Auto lock won't work!"
146 elif test -n "$screen_lock_force"; then
147 error "'xautolock' not found. Auto lock won't work!"
150 # Use compton to get transparent windows. See ~/.Xresources for configuration
152 if installed compton; then
154 # xcompmgr as fallback.
155 elif installed xcompmgr; then
160 # My window managers doesn't start a terminal emulator on its own, start one
162 (urxvt || rxvt || xterm) &
164 # Start window manager.
166 if installed herbstluftwm; then
167 herbstluftwm --locked >~/.config/herbstluftwm/log 2>&1 || failed=1
168 elif installed xmonad; then
170 elif installed stumpwm; then
173 failed='no window manager found'
175 # Fallback in case my window manager failed to start. Otherwise X terminates
176 # the session immediately (because xinitrc finishes).
177 if test -n "$failed"; then
178 if test x"$failed" = x1; then
179 failed='failed to start window manager'
181 error "$failed (spawning fallback terminal)"
182 urxvt || rxvt || xterm
188 # Kill ssh-agent to prevent unused background processes.
189 if test -x /usr/bin/ssh-agent; then
190 /usr/bin/ssh-agent -k >/dev/null
191 # No `eval` necessary, we terminate anyway.
193 # Kill remaining background processes.
194 kill $background_pids