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