tyou-are-the-wm.txt - monochromatic - monochromatic blog: http://blog.z3bra.org
HTML git clone git://z3bra.org/monochromatic
DIR Log
DIR Files
DIR Refs
---
tyou-are-the-wm.txt (9411B)
---
1 # You are the WM
2
3 08 January, 2015
4
5 A window manager is a program that runs in the background, and give you keybinds
6 and/or mouse moves to move/resize and arrange your windows on your screen.
7
8 Abbreviated "WM", the window manager is an important part of your system,
9 because without it, you'd probably end up with all your windows pop in the
10 bottom left hand-corner of your screen, unable to switch between them.
11
12 But guess what...
13
14 ## You don't need it !
15
16 It's a fact. A
17 [study](http://www.nytimes.com/2005/01/11/health/11anim.html) determined that
18 some rat could be able to determine which language you are speaking. But that's
19 totally unrelated here, I agree.
20
21 What is a window manager ?
22
23 <q>It's a program !</q> woah. Thank you Timmy.
24
25 A window manager is a program (thank you Timmy) that runs in the background, and
26 wait for X events (I wont talk about wayland here). Those X events can be of
27 any form: key press, window creation/deletion, mouse move, and so on.
28
29 The most used events being the keypress events, because the window manager will
30 perform different actions to arrange your windows.
31
32 With [dcat](http://vps.iotek.org/~dcat), we realized that some programs (sxhkd,
33 xbindkeys and others) already handle those events, and could start programs when
34 receiving them. Following the Ô so true Unix way, we decided to create a set of
35 small tools to perform all the task a window manager is supposed to do.
36
37 We ended up with [wmutils](http://github.com/wmutils/core).
38
39 ## Coreutils, for Xorg
40
41 `wmutils` stands for "window **manipulation** utilities".
42
43 This project aims to provide all the tools needed to manage a list of X windows,
44 while keeping each tool as simple as possible, so that they can easily be glued
45 together to create complex behaviors.
46 Using wmutils, you can list windows, move/resize/teleport them, change their
47 borders, change their visibility, stacking order, ignore them, focus them, and
48 more... Its power reside in its simplicity. As you can chain commands together,
49 you could easily perform some action that other WM can't even do.
50
51 For example, here is how you kill all the windows that are not shown on screen
52 (eg, attached to other workspaces):
53
54 lsw -u | xargs killw
55
56 Put a window in the top-left corner ? pff. easy:
57
58 wtp 0 0 $(wattr whi `$pfw`)
59
60 bottom-left corner ?
61
62 wid=$(pfw)
63 w=$(wattr w $wid)
64 h=$(wattr h $wid)
65 fh=$(wattr h `lsw -r`)
66
67 wtp 0 $((fh - h)) $(wattr whi $wid))
68
69 You get the idea. As a matter of fact, the following as been done using ONLY\*
70 wmutils tools:
71
72 [](http://pub.z3bra.org/monochromatic/img/floater.gif)
74 [](http://pub.z3bra.org/monochromatic/img/tiler.gif)
76
77 *\*only exception is the use of x-move-resize from
78 [no-wm](https://github.com/patrickhaller/no-wm), which is planned to be added to
79 wmutils anyway)*
80
81 Check out the "[contrib](http://github.com/wmutils/contrib)" repo. There are
82 some nice scripts in there !
83
84 Now throw your window manager away, you don't need it anymore. **YOU ARE THE WM
85 !**
86
87 **EDIT**
88 --------
89
90 I was asked on reddit to explain my wmutils setup. I gave a fairly
91 detailed answer which might also be useful for others, so I figured out I could
92 add it here (original comment [here](https://www.reddit.com/r/unixporn/comments/3b42zj/people_using_wmutils_how_do_you_use_it/csj8iq4))
93
94 I Have both `wmutils/core` and `wmutils/opt` installed. I need the latter for
95 `wew`, an X event watcher.
96
97 MANAGING WINDOWS
98 ----------------
99
100 The central piece of my workflow is `sxhkd`. This is a software one can use to
101 bind key combos to commands, or **scripts**. I use it both to start my
102 applications, but also to manage my windows via `wmutils` tools, and scripts.
103 For instance, here is the entry that let me move windows around the screen using
104 the keyboard (`pfw` returns the ID of the currently focused window. It's a
105 rather important piece of software!):
106
107 # move windows around
108 super + {left,down,up,right}
109 wmv {-20 0, 0 20, 0 -20, 20 0} $(pfw)
110
111 # resize windows
112 super + alt + {left,down,up,right}
113 wrs {-20 0, 0 20, 0 -20, 20, 0} $(pfw)
114
115 That's for tools that can be bound "directly" via sxhkd. For more complex tasks,
116 I use a few scripts of my own:
117
118 + `vroum` - manage window focus
119 + `groaw` - manage window groups
120 + `focus` - finer way to focus windows
121 + `corner` - move windows to screen's corner
122 + `fullscreen` - put a window in fullscreen mode
123
124 ## vroum
125
126 It can take 3 arguments: "next, prev, $wid". "next" will focus the next
127 window on the stack, previous will focus the previously focused window, and
128 every argument starting by `0x` will be considered a window ID to be focused
129 directly. It will also change the border of all the inactive windows, and the
130 active window. I use this script to cycle between them:
131
132 # cycle through windows
133 alt {, + shift} + tab
134 vroum {next, prev}
135
136 ## groaw
137
138 This is my "group" manager (think of it as workspaces on steroid). By
139 default, new windows are not assigned any groups. Without much explaning how
140 each flag works, I just need it to perform 3 tasks:
141
142 1. add the current window to a specific group
143 2. toggle visibility state of a specific group
144 3. remove current window from all groups
145
146 This result in the following entries:
147
148 # add window to a group
149 super + shift + {1,2,3,4,5}
150 groaw -d all; \
151 groaw -a {1,2,3,4,5}
152
153 # toggle groups' visibility
154 super + {1,2,3,4,5}
155 groaw -t {1,2,3,4,5}
156
157 # remove window from all groups
158 super + Backspace
159 groaw -d all
160
161 ## focus
162
163 A script I'm really proud of! It focus windows besed on their cardinal
164 positions. It takes exactly 4 different arguments:
165
166 north
167 ^
168 |
169 west <---+---> east
170 |
171 v
172 south
173
174 It will then focus the nearest window in the given direction (using top/left
175 edge of the window) It's bound like so
176
177 # select windows using directions
178 alt + {left,down,up,right}
179 focus {west, south, north, east} $(pfw)
180
181 ## corner
182
183 There's nothing special about it. It put the window in the corner passed as
184 argument (Top-Left, Top-Right, Bottom-Left, Bottom-Right, MiDdle)
185
186 # move windows to corners
187 super + {y,u,b,n,g}
188 corner {tl, tr, bl, br, md} $(pfw)
189
190 ## fullscreen
191
192 Set a window in fullscreen mode (change its size to the size of the monitor, and
193 remove borders. The previous position/size of the window is saved to a file, so
194 when you disable fullscreen mode, or move another window in fullscreen, the
195 window takes its old position back
196
197 # set window fullscreen
198 super + x
199 fullscreen $(pfw)
200
201 DEALING WITH EVENTS
202 -------------------
203
204 The above only applies to existing windows. But when a new window gets created,
205 I need to run a few commands against it, to integrate it to my workflow. This is
206 what `wew` is for. It prints X events to stdout, and the window ID the event
207 applies to. For example:
208
209 16:0x000c00ea
210 19:0x000c00ea
211
212 Event number 16 is "window creation", 19 is "mapping request". I have a parser
213 script that will perform different actions depending on the fired event (it's
214 called `yawee`, I like weird names):
215
216
217 #!/bin/sh
218
219 while IFS=: read ev wid; do
220 case $ev in
221 # window creation: center window on the screen (except docks, menus or similar)
222 16) wattr o $wid || corner md $wid ;;
223
224 # mapping requests: just set a special border for docks, menus and
225 # similar. Focus other windows
226 19) wattr o $wid \
227 && chwb -s 2 -c 0x323232 $wid \
228 || vroum $wid ;;
229
230 # when a window gets deleted, focus another one
231 18) wattr $(pfw) || vroum prev 2>/dev/null;;
232
233 # Focus windows when the mouse cursor enter them
234 7) wattr o $wid || vroum $wid ;;
235 esac
236 done
237
238 In my `$HOME/.xinitrc`, it's started as:
239
240 wew | yawee &
241
242 Pretty straighforward :)
243
244 USING THE MOUSE
245 ---------------
246
247 Nobody's perfect. I use the mouse from time to time to manage my windows. It is
248 sometimes more efficient to get a window out of your way quickly, or resize one
249 approximatively.
250
251 For this purpose, I STILL use sxhkd! Baskerville did an amazing job with this
252 software, as it support integer replacement of the mouse coordinate
253
254 # move windows with the mouse:
255 super + !button{1,3}
256 {wmv, wrs} -a %i %i $(pfw)
257
258 As simple as that!
259
260 MISCELLANOUS
261 ------------
262
263 For eye candy purpose, I wrote a `pulsar` script, to make my currently active
264 window standout. It make the window's border "pulse" like in the following
265 video: [wall-border.webm](http://pub.z3bra.org/monochromatic/vid/wall-border.webm). It uses a `$HOME/.colors`
266 file containing the colors to be used for the gradient. It will then run `chwb`
267 at a regular interval to change the current window's borders.
268
269
270 That's pretty much it! If you have any question, do not hesitate to ask.
271 Also, sorry for the huge wall of text, I was trying to be as precise as
272 possible.
273
274 As a bonus, to congratulate you from reading it all, here is a video from my
275 actual workflow with this setup (writing my latest blogpost:
276 [(grab some popcorns, it's 57 minutes long)](http://pub.z3bra.org/monochromatic/vid/monochromatic-0x0017-writeup.webm)