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