]> git.sur5r.net Git - i3/i3.github.io/blob - docs/hacking-howto.html
add impressum to docs
[i3/i3.github.io] / docs / hacking-howto.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\r
2     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\r
4 <head>\r
5 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />\r
6 <meta name="generator" content="AsciiDoc 8.6.4" />\r
7 <title>i3: Hacking i3: How To</title>\r
8 <link rel="stylesheet" href="/css/style.css" type="text/css" />\r
9 <link rel="stylesheet" href="/css/xhtml11.css" type="text/css" />\r
10 <script type="text/javascript">\r
11 /*<![CDATA[*/\r
12 window.onload = function(){asciidoc.footnotes(); asciidoc.toc(2);}\r
13 /*]]>*/\r
14 </script>\r
15 <script type="text/javascript" src="/js/asciidoc-xhtml11.js"></script>\r
16 </head>\r
17 <body class="article">\r
18 \r
19         <div id="main">\r
20             <a href="/"><h1 id="title">i3 - improved tiling WM</h1></a>\r
21                         <ul id="nav">\r
22                                 <li><a style="border-bottom: 2px solid #fff" href="/docs">Docs</a></li>\r
23                                 <li><a href="/screenshots">Screens</a></li>\r
24                                 <li><a href="/contact">Contact</a></li>\r
25                                 <li><a href="http://bugs.i3wm.org/">Bugs</a></li>\r
26                         </ul>\r
27         <br style="clear: both">\r
28 <div id="content">\r
29 <div id="header">\r
30 <h1>Hacking i3: How To</h1>\r
31 <span id="author">Michael Stapelberg</span><br />\r
32 <span id="email"><tt>&lt;<a href="mailto:michael+i3@stapelberg.de">michael+i3@stapelberg.de</a>&gt;</tt></span><br />\r
33 <span id="revdate">December 2009</span>\r
34 <div id="toc">
35   <div id="toctitle">Table of Contents</div>
36   <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
37 </div>\r
38 </div>\r
39 <div id="preamble">\r
40 <div class="sectionbody">\r
41 <div class="paragraph"><p>This document is intended to be the first thing you read before looking and/or\r
42 touching i3’s source code. It should contain all important information to help\r
43 you understand why things are like they are. If it does not mention something\r
44 you find necessary, please do not hesitate to contact me.</p></div>\r
45 </div>\r
46 </div>\r
47 <div class="sect1">\r
48 <h2 id="_window_managers">1. Window Managers</h2>\r
49 <div class="sectionbody">\r
50 <div class="paragraph"><p>A window manager is not necessarily needed to run X, but it is usually used in\r
51 combination with X to facilitate some things. The window manager&#8217;s job is to\r
52 take care of the placement of windows, to provide the user with some mechanisms\r
53 to change the position/size of windows and to communicate with clients to a\r
54 certain extent (for example handle fullscreen requests of clients such as\r
55 MPlayer).</p></div>\r
56 <div class="paragraph"><p>There are no different contexts in which X11 clients run, so a window manager\r
57 is just another client, like all other X11 applications. However, it handles\r
58 some events which normal clients usually don’t handle.</p></div>\r
59 <div class="paragraph"><p>In the case of i3, the tasks (and order of them) are the following:</p></div>\r
60 <div class="olist arabic"><ol class="arabic">\r
61 <li>\r
62 <p>\r
63 Grab the key bindings (events will be sent upon keypress/keyrelease)\r
64 </p>\r
65 </li>\r
66 <li>\r
67 <p>\r
68 Iterate through all existing windows (if the window manager is not started as\r
69   the first client of X) and manage them (reparent them, create window\r
70   decorations, etc.)\r
71 </p>\r
72 </li>\r
73 <li>\r
74 <p>\r
75 When new windows are created, manage them\r
76 </p>\r
77 </li>\r
78 <li>\r
79 <p>\r
80 Handle the client’s <tt>_WM_STATE</tt> property, but only the <tt>_WM_STATE_FULLSCREEN</tt>\r
81 </p>\r
82 </li>\r
83 <li>\r
84 <p>\r
85 Handle the client’s <tt>WM_NAME</tt> property\r
86 </p>\r
87 </li>\r
88 <li>\r
89 <p>\r
90 Handle the client’s size hints to display them proportionally\r
91 </p>\r
92 </li>\r
93 <li>\r
94 <p>\r
95 Handle the client’s urgency hint\r
96 </p>\r
97 </li>\r
98 <li>\r
99 <p>\r
100 Handle enter notifications (focus follows mouse)\r
101 </p>\r
102 </li>\r
103 <li>\r
104 <p>\r
105 Handle button (as in mouse buttons) presses for focus/raise on click\r
106 </p>\r
107 </li>\r
108 <li>\r
109 <p>\r
110 Handle expose events to re-draw own windows such as decorations\r
111 </p>\r
112 </li>\r
113 <li>\r
114 <p>\r
115 React to the user’s commands: Change focus, Move windows, Switch workspaces,\r
116   Change the layout mode of a container (default/stacking/tabbed), start a new\r
117   application, restart the window manager\r
118 </p>\r
119 </li>\r
120 </ol></div>\r
121 <div class="paragraph"><p>In the following chapters, each of these tasks and their implementation details\r
122 will be discussed.</p></div>\r
123 <div class="sect2">\r
124 <h3 id="_tiling_window_managers">1.1. Tiling window managers</h3>\r
125 <div class="paragraph"><p>Traditionally, there are two approaches to managing windows: The most common\r
126 one nowadays is floating, which means the user can freely move/resize the\r
127 windows. The other approach is called tiling, which means that your window\r
128 manager distributes windows to use as much space as possible while not\r
129 overlapping each other.</p></div>\r
130 <div class="paragraph"><p>The idea behind tiling is that you should not need to waste your time\r
131 moving/resizing windows while you usually want to get some work done. After\r
132 all, most users sooner or later tend to lay out their windows in a way which\r
133 corresponds to tiling or stacking mode in i3. Therefore, why not let i3 do this\r
134 for you? Certainly, it’s faster than you could ever do it.</p></div>\r
135 <div class="paragraph"><p>The problem with most tiling window managers is that they are too unflexible.\r
136 In my opinion, a window manager is just another tool, and similar to vim which\r
137 can edit all kinds of text files (like source code, HTML, …) and is not limited\r
138 to a specific file type, a window manager should not limit itself to a certain\r
139 layout (like dwm, awesome, …) but provide mechanisms for you to easily create\r
140 the layout you need at the moment.</p></div>\r
141 </div>\r
142 <div class="sect2">\r
143 <h3 id="_the_layout_table">1.2. The layout table</h3>\r
144 <div class="paragraph"><p>To accomplish flexible layouts, we decided to simply use a table. The table\r
145 grows and shrinks as you need it. Each cell holds a container which then holds\r
146 windows (see picture below). You can use different layouts for each container\r
147 (default layout and stacking layout).</p></div>\r
148 <div class="paragraph"><p>So, when you open a terminal and immediately open another one, they reside in\r
149 the same container, in default layout. The layout table has exactly one column,\r
150 one row and therefore one cell. When you move one of the terminals to the\r
151 right, the table needs to grow. It will be expanded to two columns and one row.\r
152 This enables you to have different layouts for each container. The table then\r
153 looks like this:</p></div>\r
154 <div class="tableblock">\r
155 <table rules="all"\r
156 width="15%"\r
157 frame="border"\r
158 cellspacing="0" cellpadding="4">\r
159 <col width="50%" />\r
160 <col width="50%" />\r
161 <tbody>\r
162 <tr>\r
163 <td align="center" valign="top"><p class="table">T1</p></td>\r
164 <td align="center" valign="top"><p class="table">T2</p></td>\r
165 </tr>\r
166 </tbody>\r
167 </table>\r
168 </div>\r
169 <div class="paragraph"><p>When moving terminal 2 to the bottom, the table will be expanded again.</p></div>\r
170 <div class="tableblock">\r
171 <table rules="all"\r
172 width="15%"\r
173 frame="border"\r
174 cellspacing="0" cellpadding="4">\r
175 <col width="50%" />\r
176 <col width="50%" />\r
177 <tbody>\r
178 <tr>\r
179 <td align="center" valign="top"><p class="table">T1</p></td>\r
180 <td align="center" valign="top"><p class="table"></p></td>\r
181 </tr>\r
182 <tr>\r
183 <td align="center" valign="top"><p class="table"></p></td>\r
184 <td align="center" valign="top"><p class="table">T2</p></td>\r
185 </tr>\r
186 </tbody>\r
187 </table>\r
188 </div>\r
189 <div class="paragraph"><p>You can really think of the layout table like a traditional HTML table, if\r
190 you’ve ever designed one. Especially col- and rowspan work similarly. Below,\r
191 you see an example of colspan=2 for the first container (which has T1 as\r
192 window).</p></div>\r
193 <div class="tableblock">\r
194 <table rules="all"\r
195 width="15%"\r
196 frame="border"\r
197 cellspacing="0" cellpadding="4">\r
198 <col width="100%" />\r
199 <tbody>\r
200 <tr>\r
201 <td align="center" valign="top"><div><div class="literalblock">\r
202 <div class="content">\r
203 <pre><tt>T1</tt></pre>\r
204 </div></div></div></td>\r
205 </tr>\r
206 <tr>\r
207 <td align="center" valign="top"><div><div class="tableblock">\r
208 <table rules="all"\r
209 width="100%"\r
210 frame="void"\r
211 cellspacing="0" cellpadding="4">\r
212 <col width="50%" />\r
213 <col width="50%" />\r
214 <tbody>\r
215 <tr>\r
216 <td align="center" valign="top"><p class="table">T2</p></td>\r
217 <td align="center" valign="top"><p class="table">T3</p></td>\r
218 </tr>\r
219 </tbody>\r
220 </table>\r
221 </div></div></td>\r
222 </tr>\r
223 </tbody>\r
224 </table>\r
225 </div>\r
226 <div class="paragraph"><p>Furthermore, you can freely resize table cells.</p></div>\r
227 </div>\r
228 </div>\r
229 </div>\r
230 <div class="sect1">\r
231 <h2 id="_files">2. Files</h2>\r
232 <div class="sectionbody">\r
233 <div class="dlist"><dl>\r
234 <dt class="hdlist1">\r
235 include/data.h\r
236 </dt>\r
237 <dd>\r
238 <p>\r
239 Contains data definitions used by nearly all files. You really need to read\r
240 this first.\r
241 </p>\r
242 </dd>\r
243 <dt class="hdlist1">\r
244 include/*.h\r
245 </dt>\r
246 <dd>\r
247 <p>\r
248 Contains forward definitions for all public functions, as well as\r
249 doxygen-compatible comments (so if you want to get a bit more of the big\r
250 picture, either browse all header files or use doxygen if you prefer that).\r
251 </p>\r
252 </dd>\r
253 <dt class="hdlist1">\r
254 src/cfgparse.l\r
255 </dt>\r
256 <dd>\r
257 <p>\r
258 Contains the lexer for i3’s configuration file, written for <tt>flex(1)</tt>.\r
259 </p>\r
260 </dd>\r
261 <dt class="hdlist1">\r
262 src/cfgparse.y\r
263 </dt>\r
264 <dd>\r
265 <p>\r
266 Contains the parser for i3’s configuration file, written for <tt>bison(1)</tt>.\r
267 </p>\r
268 </dd>\r
269 <dt class="hdlist1">\r
270 src/click.c\r
271 </dt>\r
272 <dd>\r
273 <p>\r
274 Contains all functions which handle mouse button clicks (right mouse button\r
275 clicks initiate resizing and thus are relatively complex).\r
276 </p>\r
277 </dd>\r
278 <dt class="hdlist1">\r
279 src/client.c\r
280 </dt>\r
281 <dd>\r
282 <p>\r
283 Contains all functions which are specific to a certain client (make it\r
284 fullscreen, see if its class/name matches a pattern, kill it, …).\r
285 </p>\r
286 </dd>\r
287 <dt class="hdlist1">\r
288 src/commands.c\r
289 </dt>\r
290 <dd>\r
291 <p>\r
292 Parsing commands and actually executing them (focusing, moving, …).\r
293 </p>\r
294 </dd>\r
295 <dt class="hdlist1">\r
296 src/config.c\r
297 </dt>\r
298 <dd>\r
299 <p>\r
300 Parses the configuration file.\r
301 </p>\r
302 </dd>\r
303 <dt class="hdlist1">\r
304 src/debug.c\r
305 </dt>\r
306 <dd>\r
307 <p>\r
308 Contains debugging functions to print unhandled X events.\r
309 </p>\r
310 </dd>\r
311 <dt class="hdlist1">\r
312 src/floating.c\r
313 </dt>\r
314 <dd>\r
315 <p>\r
316 Contains functions for floating mode (mostly resizing/dragging).\r
317 </p>\r
318 </dd>\r
319 <dt class="hdlist1">\r
320 src/handlers.c\r
321 </dt>\r
322 <dd>\r
323 <p>\r
324 Contains all handlers for all kinds of X events (new window title, new hints,\r
325 unmapping, key presses, button presses, …).\r
326 </p>\r
327 </dd>\r
328 <dt class="hdlist1">\r
329 src/ipc.c\r
330 </dt>\r
331 <dd>\r
332 <p>\r
333 Contains code for the IPC interface.\r
334 </p>\r
335 </dd>\r
336 <dt class="hdlist1">\r
337 src/layout.c\r
338 </dt>\r
339 <dd>\r
340 <p>\r
341 Renders your layout (screens, workspaces, containers).\r
342 </p>\r
343 </dd>\r
344 <dt class="hdlist1">\r
345 src/mainx.c\r
346 </dt>\r
347 <dd>\r
348 <p>\r
349 Initializes the window manager.\r
350 </p>\r
351 </dd>\r
352 <dt class="hdlist1">\r
353 src/manage.c\r
354 </dt>\r
355 <dd>\r
356 <p>\r
357 Looks at existing or new windows and decides whether to manage them. If so, it\r
358 reparents the window and inserts it into our data structures.\r
359 </p>\r
360 </dd>\r
361 <dt class="hdlist1">\r
362 src/resize.c\r
363 </dt>\r
364 <dd>\r
365 <p>\r
366 Contains the functions to resize columns/rows in the table.\r
367 </p>\r
368 </dd>\r
369 <dt class="hdlist1">\r
370 src/table.c\r
371 </dt>\r
372 <dd>\r
373 <p>\r
374 Manages the most important internal data structure, the design table.\r
375 </p>\r
376 </dd>\r
377 <dt class="hdlist1">\r
378 src/util.c\r
379 </dt>\r
380 <dd>\r
381 <p>\r
382 Contains useful functions which are not really dependant on anything.\r
383 </p>\r
384 </dd>\r
385 <dt class="hdlist1">\r
386 src/workspace.c\r
387 </dt>\r
388 <dd>\r
389 <p>\r
390 Contains all functions related to workspaces (displaying, hiding, renaming…)\r
391 </p>\r
392 </dd>\r
393 <dt class="hdlist1">\r
394 src/xcb.c\r
395 </dt>\r
396 <dd>\r
397 <p>\r
398 Contains wrappers to use xcb more easily.\r
399 </p>\r
400 </dd>\r
401 <dt class="hdlist1">\r
402 src/xinerama.c\r
403 </dt>\r
404 <dd>\r
405 <p>\r
406 (Re-)initializes the available screens and converts them to virtual screens\r
407 (see below).\r
408 </p>\r
409 </dd>\r
410 </dl></div>\r
411 </div>\r
412 </div>\r
413 <div class="sect1">\r
414 <h2 id="_data_structures">3. Data structures</h2>\r
415 <div class="sectionbody">\r
416 <div class="paragraph"><p>See include/data.h for documented data structures. The most important ones are\r
417 explained right here.</p></div>\r
418 <div class="paragraph"><p><span class="image">\r
419 <img src="bigpicture.png" alt="The Big Picture" />\r
420 </span></p></div>\r
421 <div class="paragraph"><p>So, the hierarchy is:</p></div>\r
422 <div class="olist arabic"><ol class="arabic">\r
423 <li>\r
424 <p>\r
425 <strong>Virtual screens</strong> (Screen 0 in this example)\r
426 </p>\r
427 </li>\r
428 <li>\r
429 <p>\r
430 <strong>Workspaces</strong> (Workspace 1 in this example)\r
431 </p>\r
432 </li>\r
433 <li>\r
434 <p>\r
435 <strong>Table</strong> (There can only be one table per Workspace)\r
436 </p>\r
437 </li>\r
438 <li>\r
439 <p>\r
440 <strong>Container</strong> (left and right in this example)\r
441 </p>\r
442 </li>\r
443 <li>\r
444 <p>\r
445 <strong>Client</strong> (The two clients in the left container)\r
446 </p>\r
447 </li>\r
448 </ol></div>\r
449 <div class="sect2">\r
450 <h3 id="_virtual_screens">3.1. Virtual screens</h3>\r
451 <div class="paragraph"><p>A virtual screen (type <tt>i3Screen</tt>) is generated from the connected screens\r
452 obtained through Xinerama. The difference to the raw Xinerama monitors as seen\r
453 when using <tt>xrandr(1)</tt> is that it falls back to the lowest common resolution of\r
454 the logical screens.</p></div>\r
455 <div class="paragraph"><p>For example, if your notebook has 1280x800 and you connect a video projector\r
456 with 1024x768, set up in clone mode (<tt>xrandr --output VGA --mode 1024x768\r
457 --same-as LVDS</tt>), i3 will have one virtual screen.</p></div>\r
458 <div class="paragraph"><p>However, if you configure it using <tt>xrandr --output VGA --mode 1024x768\r
459 --right-of LVDS</tt>, i3 will generate two virtual screens. For each virtual\r
460 screen, a new workspace will be assigned. New workspaces are created on the\r
461 screen you are currently on.</p></div>\r
462 </div>\r
463 <div class="sect2">\r
464 <h3 id="_workspace">3.2. Workspace</h3>\r
465 <div class="paragraph"><p>A workspace is identified by its number. Basically, you could think of\r
466 workspaces as different desks in your office, if you like the desktop\r
467 methaphor. They just contain different sets of windows and are completely\r
468 separate of each other. Other window managers also call this &#8220;Virtual\r
469 desktops&#8221;.</p></div>\r
470 </div>\r
471 <div class="sect2">\r
472 <h3 id="_the_layout_table_2">3.3. The layout table</h3>\r
473 <div class="paragraph"><p>Each workspace has a table, which is just a two-dimensional dynamic array\r
474 containing Containers (see below). This table grows and shrinks as you need it\r
475 (by moving windows to the right you can create a new column in the table, by\r
476 moving them to the bottom you create a new row).</p></div>\r
477 </div>\r
478 <div class="sect2">\r
479 <h3 id="_container">3.4. Container</h3>\r
480 <div class="paragraph"><p>A container is the content of a table’s cell. It holds an arbitrary amount of\r
481 windows and has a specific layout (default layout, stack layout or tabbed\r
482 layout). Containers can consume multiple table cells by modifying their\r
483 colspan/rowspan attribute.</p></div>\r
484 </div>\r
485 <div class="sect2">\r
486 <h3 id="_client">3.5. Client</h3>\r
487 <div class="paragraph"><p>A client is x11-speak for a window.</p></div>\r
488 </div>\r
489 </div>\r
490 </div>\r
491 <div class="sect1">\r
492 <h2 id="_list_queue_macros">4. List/queue macros</h2>\r
493 <div class="sectionbody">\r
494 <div class="paragraph"><p>i3 makes heavy use of the list macros defined in BSD operating systems. To\r
495 ensure that the operating system on which i3 is compiled has all the expected\r
496 features, i3 comes with <tt>include/queue.h</tt>. On BSD systems, you can use man\r
497 <tt>queue(3)</tt>. On Linux, you have to use google (or read the source).</p></div>\r
498 <div class="paragraph"><p>The lists used are <tt>SLIST</tt> (single linked lists), <tt>CIRCLEQ</tt> (circular\r
499 queues) and TAILQ (tail queues). Usually, only forward traversal is necessary,\r
500 so an <tt>SLIST</tt> works fine. If inserting elements at arbitrary positions or at\r
501 the end of a list is necessary, a <tt>TAILQ</tt> is used instead. However, for the\r
502 windows inside a container, a <tt>CIRCLEQ</tt> is necessary to go from the currently\r
503 selected window to the window above/below.</p></div>\r
504 </div>\r
505 </div>\r
506 <div class="sect1">\r
507 <h2 id="_naming_conventions">5. Naming conventions</h2>\r
508 <div class="sectionbody">\r
509 <div class="paragraph"><p>There is a row of standard variables used in many events. The following names\r
510 should be chosen for those:</p></div>\r
511 <div class="ulist"><ul>\r
512 <li>\r
513 <p>\r
514 &#8220;conn&#8221; is the xcb_connection_t\r
515 </p>\r
516 </li>\r
517 <li>\r
518 <p>\r
519 &#8220;event&#8221; is the event of the particular type\r
520 </p>\r
521 </li>\r
522 <li>\r
523 <p>\r
524 &#8220;container&#8221; names a container\r
525 </p>\r
526 </li>\r
527 <li>\r
528 <p>\r
529 &#8220;client&#8221; names a client, for example when using a <tt>CIRCLEQ_FOREACH</tt>\r
530 </p>\r
531 </li>\r
532 </ul></div>\r
533 </div>\r
534 </div>\r
535 <div class="sect1">\r
536 <h2 id="_startup_src_mainx_c_main">6. Startup (src/mainx.c, main())</h2>\r
537 <div class="sectionbody">\r
538 <div class="ulist"><ul>\r
539 <li>\r
540 <p>\r
541 Establish the xcb connection\r
542 </p>\r
543 </li>\r
544 <li>\r
545 <p>\r
546 Check for XKB extension on the separate X connection\r
547 </p>\r
548 </li>\r
549 <li>\r
550 <p>\r
551 Check for Xinerama screens\r
552 </p>\r
553 </li>\r
554 <li>\r
555 <p>\r
556 Grab the keycodes for which bindings exist\r
557 </p>\r
558 </li>\r
559 <li>\r
560 <p>\r
561 Manage all existing windows\r
562 </p>\r
563 </li>\r
564 <li>\r
565 <p>\r
566 Enter the event loop\r
567 </p>\r
568 </li>\r
569 </ul></div>\r
570 </div>\r
571 </div>\r
572 <div class="sect1">\r
573 <h2 id="_keybindings">7. Keybindings</h2>\r
574 <div class="sectionbody">\r
575 <div class="sect2">\r
576 <h3 id="_grabbing_the_bindings">7.1. Grabbing the bindings</h3>\r
577 <div class="paragraph"><p>Grabbing the bindings is quite straight-forward. You pass X your combination of\r
578 modifiers and the keycode you want to grab and whether you want to grab them\r
579 actively or passively. Most bindings (everything except for bindings using\r
580 Mode_switch) are grabbed passively, that is, just the window manager gets the\r
581 event and cannot replay it.</p></div>\r
582 <div class="paragraph"><p>We need to grab bindings that use Mode_switch actively because of a bug in X.\r
583 When the window manager receives the keypress/keyrelease event for an actively\r
584 grabbed keycode, it has to decide what to do with this event: It can either\r
585 replay it so that other applications get it or it can prevent other\r
586 applications from receiving it.</p></div>\r
587 <div class="paragraph"><p>So, why do we need to grab keycodes actively? Because X does not set the\r
588 state-property of keypress/keyrelease events properly. The Mode_switch bit is\r
589 not set and we need to get it using XkbGetState. This means we cannot pass X\r
590 our combination of modifiers containing Mode_switch when grabbing the key and\r
591 therefore need to grab the keycode itself without any modifiers. This means,\r
592 if you bind Mode_switch + keycode 38 ("a"), i3 will grab keycode 38 ("a") and\r
593 check on each press of "a" if the Mode_switch bit is set using XKB. If yes, it\r
594 will handle the event, if not, it will replay the event.</p></div>\r
595 </div>\r
596 <div class="sect2">\r
597 <h3 id="_handling_a_keypress">7.2. Handling a keypress</h3>\r
598 <div class="paragraph"><p>As mentioned in "Grabbing the bindings", upon a keypress event, i3 first gets\r
599 the correct state.</p></div>\r
600 <div class="paragraph"><p>Then, it looks through all bindings and gets the one which matches the received\r
601 event.</p></div>\r
602 <div class="paragraph"><p>The bound command is parsed directly in command mode.</p></div>\r
603 </div>\r
604 </div>\r
605 </div>\r
606 <div class="sect1">\r
607 <h2 id="_manage_windows_src_mainx_c_manage_window_and_reparent_window">8. Manage windows (src/mainx.c, manage_window() and reparent_window())</h2>\r
608 <div class="sectionbody">\r
609 <div class="paragraph"><p><tt>manage_window()</tt> does some checks to decide whether the window should be\r
610 managed at all:</p></div>\r
611 <div class="ulist"><ul>\r
612 <li>\r
613 <p>\r
614 Windows have to be mapped, that is, visible on screen\r
615 </p>\r
616 </li>\r
617 <li>\r
618 <p>\r
619 The override_redirect must not be set. Windows with override_redirect shall\r
620    not be managed by a window manager\r
621 </p>\r
622 </li>\r
623 </ul></div>\r
624 <div class="paragraph"><p>Afterwards, i3 gets the intial geometry and reparents the window (see\r
625 <tt>reparent_window()</tt>) if it wasn’t already managed.</p></div>\r
626 <div class="paragraph"><p>Reparenting means that for each window which is reparented, a new window,\r
627 slightly larger than the original one, is created. The original window is then\r
628 reparented to the bigger one (called "frame").</p></div>\r
629 <div class="paragraph"><p>After reparenting, the window type (<tt>_NET_WM_WINDOW_TYPE</tt>) is checked to see\r
630 whether this window is a dock (<tt>_NET_WM_WINDOW_TYPE_DOCK</tt>), like dzen2 for\r
631 example. Docks are handled differently, they don’t have decorations and are not\r
632 assigned to a specific container. Instead, they are positioned at the bottom\r
633 of the screen. To get the height which needsd to be reserved for the window,\r
634 the <tt>_NET_WM_STRUT_PARTIAL</tt> property is used.</p></div>\r
635 <div class="paragraph"><p>Furthermore, the list of assignments (to other workspaces, which may be on\r
636 other screens) is checked. If the window matches one of the user’s criteria,\r
637 it may either be put in floating mode or moved to a different workspace. If the\r
638 target workspace is not visible, the window will not be mapped.</p></div>\r
639 </div>\r
640 </div>\r
641 <div class="sect1">\r
642 <h2 id="_what_happens_when_an_application_is_started">9. What happens when an application is started?</h2>\r
643 <div class="sectionbody">\r
644 <div class="paragraph"><p>i3 does not care for applications. All it notices is when new windows are\r
645 mapped (see <tt>src/handlers.c</tt>, <tt>handle_map_request()</tt>). The window is then\r
646 reparented (see section "Manage windows").</p></div>\r
647 <div class="paragraph"><p>After reparenting the window, <tt>render_layout()</tt> is called which renders the\r
648 internal layout table. The new window has been placed in the currently focused\r
649 container and therefore the new window and the old windows (if any) need to be\r
650 moved/resized so that the currently active layout (default/stacking/tabbed mode)\r
651 is rendered correctly. To move/resize windows, a window is &#8220;configured&#8221; in\r
652 X11-speak.</p></div>\r
653 <div class="paragraph"><p>Some applications, such as MPlayer obviously assume the window manager is\r
654 stupid and try to configure their windows by themselves. This generates an\r
655 event called configurerequest. i3 handles these events and tells the window the\r
656 size it had before the configurerequest (with the exception of not yet mapped\r
657 windows, which get configured like they want to, and floating windows, which\r
658 can reconfigure themselves).</p></div>\r
659 </div>\r
660 </div>\r
661 <div class="sect1">\r
662 <h2 id="_net_wm_state">10. _NET_WM_STATE</h2>\r
663 <div class="sectionbody">\r
664 <div class="paragraph"><p>Only the _NET_WM_STATE_FULLSCREEN atom is handled. It calls\r
665 &#8220;toggle_fullscreen()&#8221; for the specific client which just configures the\r
666 client to use the whole screen on which it currently is. Also, it is set as\r
667 fullscreen_client for the i3Screen.</p></div>\r
668 </div>\r
669 </div>\r
670 <div class="sect1">\r
671 <h2 id="_wm_name">11. WM_NAME</h2>\r
672 <div class="sectionbody">\r
673 <div class="paragraph"><p>When the WM_NAME property of a window changes, its decoration (containing the\r
674 title) is re-rendered. Note that WM_NAME is in COMPOUND_TEXT encoding which is\r
675 totally uncommon and cumbersome. Therefore, the _NET_WM_NAME atom will be used\r
676 if present.</p></div>\r
677 </div>\r
678 </div>\r
679 <div class="sect1">\r
680 <h2 id="_net_wm_name">12. _NET_WM_NAME</h2>\r
681 <div class="sectionbody">\r
682 <div class="paragraph"><p>Like WM_NAME, this atom contains the title of a window. However, _NET_WM_NAME\r
683 is encoded in UTF-8. i3 will recode it to UCS-2 in order to be able to pass it\r
684 to X. Using an appropriate font (ISO-10646), you can see most special\r
685 characters (every special character contained in your font).</p></div>\r
686 </div>\r
687 </div>\r
688 <div class="sect1">\r
689 <h2 id="_size_hints">13. Size hints</h2>\r
690 <div class="sectionbody">\r
691 <div class="paragraph"><p>Size hints specify the minimum/maximum size for a given window as well as its\r
692 aspect ratio.  This is important for clients like mplayer, who only set the\r
693 aspect ratio and resize their window to be as small as possible (but only with\r
694 some video outputs, for example in Xv, while when using x11, mplayer does the\r
695 necessary centering for itself).</p></div>\r
696 <div class="paragraph"><p>So, when an aspect ratio was specified, i3 adjusts the height of the window\r
697 until the size maintains the correct aspect ratio. For the code to do this, see\r
698 src/layout.c, function resize_client().</p></div>\r
699 </div>\r
700 </div>\r
701 <div class="sect1">\r
702 <h2 id="_rendering_src_layout_c_render_layout_and_render_container">14. Rendering (src/layout.c, render_layout() and render_container())</h2>\r
703 <div class="sectionbody">\r
704 <div class="paragraph"><p>There are several entry points to rendering: <tt>render_layout()</tt>,\r
705 <tt>render_workspace()</tt> and <tt>render_container()</tt>. The former one calls\r
706 <tt>render_workspace()</tt> for every screen, which in turn will call\r
707 <tt>render_container()</tt> for every container inside its layout table. Therefore, if\r
708 you need to render only a single container, for example because a window was\r
709 removed, added or changed its title, you should directly call\r
710 render_container().</p></div>\r
711 <div class="paragraph"><p>Rendering consists of two steps: In the first one, in <tt>render_workspace()</tt>, each\r
712 container gets its position (screen offset + offset in the table) and size\r
713 (container&#8217;s width times colspan/rowspan). Then, <tt>render_container()</tt> is called,\r
714 which takes different approaches, depending on the mode the container is in:</p></div>\r
715 <div class="sect2">\r
716 <h3 id="_common_parts">14.1. Common parts</h3>\r
717 <div class="paragraph"><p>On the frame (the window which was created around the client’s window for the\r
718 decorations), a black rectangle is drawn as a background for windows like\r
719 MPlayer, which do not completely fit into the frame.</p></div>\r
720 </div>\r
721 <div class="sect2">\r
722 <h3 id="_default_mode">14.2. Default mode</h3>\r
723 <div class="paragraph"><p>Each clients gets the container’s width and an equal amount of height.</p></div>\r
724 </div>\r
725 <div class="sect2">\r
726 <h3 id="_stack_mode">14.3. Stack mode</h3>\r
727 <div class="paragraph"><p>In stack mode, a window containing the decorations of all windows inside the\r
728 container is placed at the top. The currently focused window is then given the\r
729 whole remaining space.</p></div>\r
730 </div>\r
731 <div class="sect2">\r
732 <h3 id="_tabbed_mode">14.4. Tabbed mode</h3>\r
733 <div class="paragraph"><p>Tabbed mode is like stack mode, except that the window decorations are drawn\r
734 in one single line at the top of the container.</p></div>\r
735 </div>\r
736 <div class="sect2">\r
737 <h3 id="_window_decorations">14.5. Window decorations</h3>\r
738 <div class="paragraph"><p>The window decorations consist of a rectangle in the appropriate color (depends\r
739 on whether this window is the currently focused one, the last focused one in a\r
740 not focused container or not focused at all) forming the background.\r
741 Afterwards, two lighter lines are drawn and the last step is drawing the\r
742 window’s title (see WM_NAME) onto it.</p></div>\r
743 </div>\r
744 <div class="sect2">\r
745 <h3 id="_fullscreen_windows">14.6. Fullscreen windows</h3>\r
746 <div class="paragraph"><p>For fullscreen windows, the <tt>rect</tt> (x, y, width, height) is not changed to\r
747 allow the client to easily go back to its previous position. Instead,\r
748 fullscreen windows are skipped when rendering.</p></div>\r
749 </div>\r
750 <div class="sect2">\r
751 <h3 id="_resizing_containers">14.7. Resizing containers</h3>\r
752 <div class="paragraph"><p>By clicking and dragging the border of a container, you can resize the whole\r
753 column (respectively row) which this container is in. This is necessary to keep\r
754 the table layout working and consistent.</p></div>\r
755 <div class="paragraph"><p>The resizing works similarly to the resizing of floating windows or movement of\r
756 floating windows:</p></div>\r
757 <div class="ulist"><ul>\r
758 <li>\r
759 <p>\r
760 A new, invisible window with the size of the root window is created\r
761   (<tt>grabwin</tt>)\r
762 </p>\r
763 </li>\r
764 <li>\r
765 <p>\r
766 Another window, 2px width and as high as your screen (or vice versa for\r
767   horizontal resizing) is created. Its background color is the border color and\r
768   it is only there to inform the user how big the container will be (it\r
769   creates the impression of dragging the border out of the container).\r
770 </p>\r
771 </li>\r
772 <li>\r
773 <p>\r
774 The <tt>drag_pointer</tt> function of <tt>src/floating.c</tt> is called to grab the pointer\r
775   and enter its own event loop which will pass all events (expose events) but\r
776   motion notify events. This function then calls the specified callback\r
777   (<tt>resize_callback</tt>) which does some boundary checking and moves the helper\r
778   window. As soon as the mouse button is released, this loop will be\r
779   terminated.\r
780 </p>\r
781 </li>\r
782 <li>\r
783 <p>\r
784 The new width_factor for each involved column (respectively row) will be\r
785   calculated.\r
786 </p>\r
787 </li>\r
788 </ul></div>\r
789 </div>\r
790 </div>\r
791 </div>\r
792 <div class="sect1">\r
793 <h2 id="_user_commands_commandmode_src_commands_c">15. User commands / commandmode (src/commands.c)</h2>\r
794 <div class="sectionbody">\r
795 <div class="paragraph"><p>Like in vim, you can control i3 using commands. They are intended to be a\r
796 powerful alternative to lots of shortcuts, because they can be combined. There\r
797 are a few special commands, which are the following:</p></div>\r
798 <div class="dlist"><dl>\r
799 <dt class="hdlist1">\r
800 exec &lt;command&gt;\r
801 </dt>\r
802 <dd>\r
803 <p>\r
804 Starts the given command by passing it to <tt>/bin/sh</tt>.\r
805 </p>\r
806 </dd>\r
807 <dt class="hdlist1">\r
808 restart\r
809 </dt>\r
810 <dd>\r
811 <p>\r
812 Restarts i3 by executing <tt>argv[0]</tt> (the path with which you started i3) without\r
813 forking.\r
814 </p>\r
815 </dd>\r
816 <dt class="hdlist1">\r
817 w\r
818 </dt>\r
819 <dd>\r
820 <p>\r
821 "With". This is used to select a bunch of windows. Currently, only selecting\r
822 the whole container in which the window is in, is supported by specifying "w".\r
823 </p>\r
824 </dd>\r
825 <dt class="hdlist1">\r
826 f, s, d\r
827 </dt>\r
828 <dd>\r
829 <p>\r
830 Toggle fullscreen, stacking, default mode for the current window/container.\r
831 </p>\r
832 </dd>\r
833 </dl></div>\r
834 <div class="paragraph"><p>The other commands are to be combined with a direction. The directions are h,\r
835 j, k and l, like in vim (h = left, j = down, k = up, l = right). When you just\r
836 specify the direction keys, i3 will move the focus in that direction. You can\r
837 provide "m" or "s" before the direction to move a window respectively or snap.</p></div>\r
838 </div>\r
839 </div>\r
840 <div class="sect1">\r
841 <h2 id="_gotchas">16. Gotchas</h2>\r
842 <div class="sectionbody">\r
843 <div class="ulist"><ul>\r
844 <li>\r
845 <p>\r
846 Forgetting to call <tt>xcb_flush(conn);</tt> after sending a request. This usually\r
847   leads to code which looks like it works fine but which does not work under\r
848   certain conditions.\r
849 </p>\r
850 </li>\r
851 </ul></div>\r
852 </div>\r
853 </div>\r
854 <div class="sect1">\r
855 <h2 id="_using_git_sending_patches">17. Using git / sending patches</h2>\r
856 <div class="sectionbody">\r
857 <div class="paragraph"><p>For a short introduction into using git, see\r
858 <a href="http://www.spheredev.org/wiki/Git_for_the_lazy">http://www.spheredev.org/wiki/Git_for_the_lazy</a> or, for more documentation, see\r
859 <a href="http://git-scm.com/documentation">http://git-scm.com/documentation</a></p></div>\r
860 <div class="paragraph"><p>When you want to send a patch because you fixed a bug or implemented a cool\r
861 feature (please talk to us before working on features to see whether they are\r
862 maybe already implemented, not possible for some some reason, or don’t fit\r
863 into the concept), please use git to create a patchfile.</p></div>\r
864 <div class="paragraph"><p>First of all, update your working copy to the latest version of the master\r
865 branch:</p></div>\r
866 <div class="listingblock">\r
867 <div class="content">\r
868 <pre><tt>git pull</tt></pre>\r
869 </div></div>\r
870 <div class="paragraph"><p>Afterwards, make the necessary changes for your bugfix/feature. Then, review\r
871 the changes using <tt>git diff</tt> (you might want to enable colors in the diff using\r
872 <tt>git config diff.color auto</tt>).  When you are definitely done, use <tt>git commit\r
873 -a</tt> to commit all changes you’ve made.</p></div>\r
874 <div class="paragraph"><p>Then, use the following command to generate a patchfile which we can directly\r
875 apply to the branch, preserving your commit message and name:</p></div>\r
876 <div class="listingblock">\r
877 <div class="content">\r
878 <pre><tt>git format-patch origin</tt></pre>\r
879 </div></div>\r
880 <div class="paragraph"><p>Just send us the generated file via email.</p></div>\r
881 </div>\r
882 </div>\r
883 </div>\r
884 <div id="footnotes"><hr /></div>\r
885 <div id="footer">\r
886 <div id="footer-text">\r
887 Last updated 2011-07-22 20:29:17 CEST\r
888 </div>\r
889 <div lang="de">\r
890 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>\r
891 </div>\r
892 </div>\r
893 \r
894 </body>\r
895 </html>\r