]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - herbstluftwm/autostart
6ba04041fb40172d03f6d61e30e8a3f42ffb9f86
[config/dotfiles.git] / herbstluftwm / autostart
1 #!/bin/sh
2
3 # Herbstluftm configuration file.
4
5 # Copyright (C) 2014  Simon Ruderich
6 #
7 # This file 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.
11 #
12 # This file 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.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this file.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 set -e
22
23
24 hc() {
25     herbstclient "$@"
26 }
27 installed() {
28     type "$1" >/dev/null 2>&1
29 }
30 # $1: timeout
31 notify() {
32     if installed dzen2; then
33         read x
34         printf '%s\n' "$x" | sed 's/\^/^^/g' \
35             | dzen2 -fg blue -bg yellow -y 15 -h 30 -p "$1" &
36     elif installed xmessage; then
37         # Fallback solution, display first line of stdin.
38         read x
39         xmessage -timeout "$1" "$x" &
40     else
41         # Last way to send a "message", create a stupid window layout so I
42         # notice something is up and look at the logs.
43         hc fullscreen off
44         hc floating off
45         hc pseudotile off
46         hc split vertical 0.1
47         hc unlock # or we might not see the changes
48     fi
49 }
50
51 # Tell all clients the configuration file was reloaded. Should be the first
52 # command in the autostart file.
53 hc emit_hook reload
54
55
56 # KEY BINDINGS
57
58 # Use Super (= "Windows") key as modifier which is used for all herbstluftwm
59 # key bindings.
60 mod=Mod4
61
62 # Remove all existing key bindings.
63 hc keyunbind --all
64
65 # Basic key bindings.
66 hc keybind $mod-Shift-Return spawn urxvt
67 hc keybind $mod-Shift-c close
68 hc keybind $mod-q reload
69 hc keybind $mod-Shift-q quit
70 # Find an existing screen locker.
71 for locker in xscreensaver xtrlock ''; do
72     if installed "$locker"; then
73         break
74     fi
75 done
76 if test -z "$locker"; then
77     echo 'No screen locker found!' | notify 60
78 fi
79 # Additional options.
80 locker_pre=
81 if test x"$locker" = xxscreensaver; then
82     # Start xscreensaver if it's not already running. xscreensaver-command
83     # ensures xscreensaver is availble for the current X session.
84     locker_pre='xscreensaver-command -time >/dev/null 2>&1 || xscreensaver &'
85     locker='xscreensaver-command -lock'
86 elif test x"$locker" = xxtrlock; then
87     # Sleep is necessary to allow xtrlock to grab the keyboard input.
88     locker_pre='sleep 1;'
89 fi
90 # Lock the screen.
91 hc keybind $mod-z spawn sh -c "$locker_pre exec $locker"
92
93 # Tag key bindings. Create tags 1 to 9 with bindings to switch and move
94 # windows to them.
95 hc rename default 1 2>/dev/null || true
96 for i in `seq 1 9`; do
97     hc add "$i"
98     hc keybind "$mod-$i" use "$i"
99     hc keybind "$mod-Shift-$i" move "$i"
100 done
101 # Switch to last active tag.
102 hc keybind $mod-b use_previous
103
104 # Layouting key bindings.
105 hc keybind $mod-space cycle_layout 1 horizontal max # toggle these layouts
106 hc keybind $mod-u split vertical   0.5
107 hc keybind $mod-o split horizontal 0.5
108 hc keybind $mod-r remove                            # remove a split
109 # Change window state.
110 hc keybind $mod-f fullscreen toggle
111 # Reset fullscreen and layout. Just in case I get confused.
112 hc keybind $mod-Shift-space chain , fullscreen off , set_layout horizontal
113
114 # Focus key bindings.
115 hc keybind $mod-h focus left
116 hc keybind $mod-j focus down
117 hc keybind $mod-k focus up
118 hc keybind $mod-l focus right
119 # Move windows.
120 hc keybind $mod-Shift-h shift left
121 hc keybind $mod-Shift-j shift down
122 hc keybind $mod-Shift-k shift up
123 hc keybind $mod-Shift-l shift right
124 # Swap top and bottom frame (only works with two frames).
125 hc keybind $mod-s chain , lock , rotate , rotate , unlock
126
127
128 # MOUSE BINDINGS
129
130 # Remove all existing key bindings.
131 hc mouseunbind --all
132
133
134 # GENERAL SETTINGS
135
136 # Necessary for Java so it recognizes herbstluftwm as tiling window manager.
137 hc set wmname LG3D
138 # Auto-detect new monitors.
139 hc set auto_detect_monitors 1
140
141
142 # WINDOW and FRAME SETTINGS
143
144 # No border for frames, only for windows.
145 hc set frame_border_width  0
146 hc set window_border_width 1
147 # No gaps between frames or windows.
148 hc set frame_gap  0
149 hc set window_gap 0
150 # Inactive window borders are black, almost invisible on my black screen.
151 # Active window borders are dark red.
152 hc set window_border_normal_color '#000000'
153 hc set window_border_active_color '#990000'
154 # Transparent background for empty frames.
155 hc set frame_bg_transparent 1
156
157 # Use vertical layout for windows in frames per default.
158 hc set default_frame_layout 1 # vertical
159
160
161 # LAYOUT
162
163 # Run only on startup, not when reloading the config. Thanks to The-Compiler
164 # in #herbstluftwm on Freenode (2014-01-10 16:26 CET) for the idea to use
165 # environment variables.
166 if ! hc getenv HLWMRC_LOADED >/dev/null; then
167     hc setenv HLWMRC_LOADED 1
168
169     # Setup my layout: Vertical split with my main terminal window in the top
170     # frame, secondary windows in the bottom frame.
171     hc split vertical 0.5
172 fi
173
174
175 # RULES
176
177 # Remove all existing rules.
178 hc unrule --all
179
180 # * Do not focus new clients (default).
181 # * Don't allow clients to toggle fullscreen via EWMH.
182 # * Move new windows to the frame at the bottom of the screen.
183 hc rule focus=off \
184         ewmhrequests=off \
185         index=1
186
187 # Focus important windows when they are opened.
188 hc rule instance=xmessage focus=on
189
190 # Move Iceweasel to tag 2.
191 hc rule instance=Navigator class=Iceweasel tag=2
192
193
194 # After everything is done, allow redrawing of the windows.
195 hc unlock
196
197
198 # To notify me if set -e has terminated the script (then this part won't get
199 # executed).
200 echo 'hlwm restarted' | notify 1