]> git.sur5r.net Git - i3/i3.github.io/blob - docs/hacking-howto.html
update docs for v4.7
[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 <link rel="icon" type="image/png" href="/favicon.png">\r
6 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />\r
7 <meta name="generator" content="AsciiDoc 8.6.7" />\r
8 <title>i3: Hacking i3: How To</title>\r
9 <link rel="stylesheet" href="/css/style.css" type="text/css" />\r
10 <link rel="stylesheet" href="/css/xhtml11.css" type="text/css" />\r
11 <script type="text/javascript">\r
12 /*<![CDATA[*/\r
13 window.onload = function(){asciidoc.footnotes(); asciidoc.toc(2);}\r
14 /*]]>*/\r
15 </script>\r
16 <script type="text/javascript" src="/js/asciidoc-xhtml11.js"></script>\r
17 </head>\r
18 <body class="article">\r
19 \r
20         <div id="main">\r
21             <a href="/"><h1 id="title">i3 - improved tiling WM</h1></a>\r
22                         <ul id="nav">\r
23                                 <li><a style="border-bottom: 2px solid #fff" href="/docs">Docs</a></li>\r
24                                 <li><a href="/screenshots">Screens</a></li>\r
25                                 <li><a href="/contact">Contact</a></li>\r
26                                 <li><a href="http://bugs.i3wm.org/">Bugs</a></li>\r
27                         </ul>\r
28         <br style="clear: both">\r
29 <div id="content">\r
30 <div id="header">\r
31 <h1>Hacking i3: How To</h1>\r
32 <span id="author">Michael Stapelberg</span><br />\r
33 <span id="email"><tt>&lt;<a href="mailto:michael@i3wm.org">michael@i3wm.org</a>&gt;</tt></span><br />\r
34 <span id="revdate">February 2013</span>\r
35 <div id="toc">
36   <div id="toctitle">Table of Contents</div>
37   <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
38 </div>\r
39 </div>\r
40 <div id="preamble">\r
41 <div class="sectionbody">\r
42 <div class="paragraph"><p>This document is intended to be the first thing you read before looking and/or\r
43 touching i3’s source code. It should contain all important information to help\r
44 you understand why things are like they are. If it does not mention something\r
45 you find necessary, please do not hesitate to contact me.</p></div>\r
46 </div>\r
47 </div>\r
48 <div class="sect1">\r
49 <h2 id="_window_managers">1. Window Managers</h2>\r
50 <div class="sectionbody">\r
51 <div class="paragraph"><p>A window manager is not necessarily needed to run X, but it is usually used in\r
52 combination with X to facilitate some things. The window manager&#8217;s job is to\r
53 take care of the placement of windows, to provide the user with some mechanisms\r
54 to change the position/size of windows and to communicate with clients to a\r
55 certain extent (for example handle fullscreen requests of clients such as\r
56 MPlayer).</p></div>\r
57 <div class="paragraph"><p>There are no different contexts in which X11 clients run, so a window manager\r
58 is just another client, like all other X11 applications. However, it handles\r
59 some events which normal clients usually don’t handle.</p></div>\r
60 <div class="paragraph"><p>In the case of i3, the tasks (and order of them) are the following:</p></div>\r
61 <div class="olist arabic"><ol class="arabic">\r
62 <li>\r
63 <p>\r
64 Grab the key bindings (events will be sent upon keypress/keyrelease)\r
65 </p>\r
66 </li>\r
67 <li>\r
68 <p>\r
69 Iterate through all existing windows (if the window manager is not started as\r
70   the first client of X) and manage them (reparent them, create window\r
71   decorations, etc.)\r
72 </p>\r
73 </li>\r
74 <li>\r
75 <p>\r
76 When new windows are created, manage them\r
77 </p>\r
78 </li>\r
79 <li>\r
80 <p>\r
81 Handle the client’s <tt>_WM_STATE</tt> property, but only <tt>_WM_STATE_FULLSCREEN</tt> and\r
82   <tt>_NET_WM_STATE_DEMANDS_ATTENTION</tt>\r
83 </p>\r
84 </li>\r
85 <li>\r
86 <p>\r
87 Handle the client’s <tt>WM_NAME</tt> property\r
88 </p>\r
89 </li>\r
90 <li>\r
91 <p>\r
92 Handle the client’s size hints to display them proportionally\r
93 </p>\r
94 </li>\r
95 <li>\r
96 <p>\r
97 Handle the client’s urgency hint\r
98 </p>\r
99 </li>\r
100 <li>\r
101 <p>\r
102 Handle enter notifications (focus follows mouse)\r
103 </p>\r
104 </li>\r
105 <li>\r
106 <p>\r
107 Handle button (as in mouse buttons) presses for focus/raise on click\r
108 </p>\r
109 </li>\r
110 <li>\r
111 <p>\r
112 Handle expose events to re-draw own windows such as decorations\r
113 </p>\r
114 </li>\r
115 <li>\r
116 <p>\r
117 React to the user’s commands: Change focus, Move windows, Switch workspaces,\r
118   Change the layout mode of a container (default/stacking/tabbed), start a new\r
119   application, restart the window manager\r
120 </p>\r
121 </li>\r
122 </ol></div>\r
123 <div class="paragraph"><p>In the following chapters, each of these tasks and their implementation details\r
124 will be discussed.</p></div>\r
125 <div class="sect2">\r
126 <h3 id="_tiling_window_managers">1.1. Tiling window managers</h3>\r
127 <div class="paragraph"><p>Traditionally, there are two approaches to managing windows: The most common\r
128 one nowadays is floating, which means the user can freely move/resize the\r
129 windows. The other approach is called tiling, which means that your window\r
130 manager distributes windows to use as much space as possible while not\r
131 overlapping each other.</p></div>\r
132 <div class="paragraph"><p>The idea behind tiling is that you should not need to waste your time\r
133 moving/resizing windows while you usually want to get some work done. After\r
134 all, most users sooner or later tend to lay out their windows in a way which\r
135 corresponds to tiling or stacking mode in i3. Therefore, why not let i3 do this\r
136 for you? Certainly, it’s faster than you could ever do it.</p></div>\r
137 <div class="paragraph"><p>The problem with most tiling window managers is that they are too inflexible.\r
138 In my opinion, a window manager is just another tool, and similar to vim which\r
139 can edit all kinds of text files (like source code, HTML, …) and is not limited\r
140 to a specific file type, a window manager should not limit itself to a certain\r
141 layout (like dwm, awesome, …) but provide mechanisms for you to easily create\r
142 the layout you need at the moment.</p></div>\r
143 </div>\r
144 <div class="sect2">\r
145 <h3 id="_the_layout_tree">1.2. The layout tree</h3>\r
146 <div class="paragraph"><p>The data structure which i3 uses to keep track of your windows is a tree. Every\r
147 node in the tree is a container (type <tt>Con</tt>). Some containers represent actual\r
148 windows (every container with a <tt>window != NULL</tt>), some represent split\r
149 containers and a few have special purposes: they represent workspaces, outputs\r
150 (like VGA1, LVDS1, …) or the X11 root window.</p></div>\r
151 <div class="paragraph"><p>So, when you open a terminal and immediately open another one, they reside in\r
152 the same split container, which uses the default layout. In case of an empty\r
153 workspace, the split container we are talking about is the workspace.</p></div>\r
154 <div class="paragraph"><p>To get an impression of how different layouts are represented, just play around\r
155 and look at the data structures&#8201;&#8212;&#8201;they are exposed as a JSON hash. See\r
156 <a href="http://i3wm.org/docs/ipc.html#_tree_reply">http://i3wm.org/docs/ipc.html#_tree_reply</a> for documentation on that and an\r
157 example.</p></div>\r
158 </div>\r
159 </div>\r
160 </div>\r
161 <div class="sect1">\r
162 <h2 id="_files">2. Files</h2>\r
163 <div class="sectionbody">\r
164 <div class="dlist"><dl>\r
165 <dt class="hdlist1">\r
166 include/atoms.xmacro\r
167 </dt>\r
168 <dd>\r
169 <p>\r
170 A file containing all X11 atoms which i3 uses. This file will be included\r
171 various times (for defining, requesting and receiving the atoms), each time\r
172 with a different definition of xmacro().\r
173 </p>\r
174 </dd>\r
175 <dt class="hdlist1">\r
176 include/data.h\r
177 </dt>\r
178 <dd>\r
179 <p>\r
180 Contains data definitions used by nearly all files. You really need to read\r
181 this first.\r
182 </p>\r
183 </dd>\r
184 <dt class="hdlist1">\r
185 include/*.h\r
186 </dt>\r
187 <dd>\r
188 <p>\r
189 Contains forward definitions for all public functions, as well as\r
190 doxygen-compatible comments (so if you want to get a bit more of the big\r
191 picture, either browse all header files or use doxygen if you prefer that).\r
192 </p>\r
193 </dd>\r
194 <dt class="hdlist1">\r
195 src/config_parser.c\r
196 </dt>\r
197 <dd>\r
198 <p>\r
199 Contains a custom configuration parser. See src/command_parser.c for rationale\r
200  on why we use a custom parser.\r
201 </p>\r
202 </dd>\r
203 <dt class="hdlist1">\r
204 src/click.c\r
205 </dt>\r
206 <dd>\r
207 <p>\r
208 Contains all functions which handle mouse button clicks (right mouse button\r
209 clicks initiate resizing and thus are relatively complex).\r
210 </p>\r
211 </dd>\r
212 <dt class="hdlist1">\r
213 src/command_parser.c\r
214 </dt>\r
215 <dd>\r
216 <p>\r
217 Contains a hand-written parser to parse commands (commands are what\r
218 you bind on keys and what you can send to i3 using the IPC interface, like\r
219 <em>move left</em> or <em>workspace 4</em>).\r
220 </p>\r
221 </dd>\r
222 <dt class="hdlist1">\r
223 src/con.c\r
224 </dt>\r
225 <dd>\r
226 <p>\r
227 Contains all functions which deal with containers directly (creating\r
228 containers, searching containers, getting specific properties from containers,\r
229 …).\r
230 </p>\r
231 </dd>\r
232 <dt class="hdlist1">\r
233 src/config.c\r
234 </dt>\r
235 <dd>\r
236 <p>\r
237 Contains all functions handling the configuration file (calling the parser\r
238 (src/cfgparse.y) with the correct path, switching key bindings mode).\r
239 </p>\r
240 </dd>\r
241 <dt class="hdlist1">\r
242 src/debug.c\r
243 </dt>\r
244 <dd>\r
245 <p>\r
246 Contains debugging functions to print unhandled X events.\r
247 </p>\r
248 </dd>\r
249 <dt class="hdlist1">\r
250 src/ewmh.c\r
251 </dt>\r
252 <dd>\r
253 <p>\r
254 Functions to get/set certain EWMH properties easily.\r
255 </p>\r
256 </dd>\r
257 <dt class="hdlist1">\r
258 src/floating.c\r
259 </dt>\r
260 <dd>\r
261 <p>\r
262 Contains functions for floating mode (mostly resizing/dragging).\r
263 </p>\r
264 </dd>\r
265 <dt class="hdlist1">\r
266 src/handlers.c\r
267 </dt>\r
268 <dd>\r
269 <p>\r
270 Contains all handlers for all kinds of X events (new window title, new hints,\r
271 unmapping, key presses, button presses, …).\r
272 </p>\r
273 </dd>\r
274 <dt class="hdlist1">\r
275 src/ipc.c\r
276 </dt>\r
277 <dd>\r
278 <p>\r
279 Contains code for the IPC interface.\r
280 </p>\r
281 </dd>\r
282 <dt class="hdlist1">\r
283 src/load_layout.c\r
284 </dt>\r
285 <dd>\r
286 <p>\r
287 Contains code for loading layouts from JSON files.\r
288 </p>\r
289 </dd>\r
290 <dt class="hdlist1">\r
291 src/log.c\r
292 </dt>\r
293 <dd>\r
294 <p>\r
295 Contains the logging functions.\r
296 </p>\r
297 </dd>\r
298 <dt class="hdlist1">\r
299 src/main.c\r
300 </dt>\r
301 <dd>\r
302 <p>\r
303 Initializes the window manager.\r
304 </p>\r
305 </dd>\r
306 <dt class="hdlist1">\r
307 src/manage.c\r
308 </dt>\r
309 <dd>\r
310 <p>\r
311 Looks at existing or new windows and decides whether to manage them. If so, it\r
312 reparents the window and inserts it into our data structures.\r
313 </p>\r
314 </dd>\r
315 <dt class="hdlist1">\r
316 src/match.c\r
317 </dt>\r
318 <dd>\r
319 <p>\r
320 A "match" is a data structure which acts like a mask or expression to match\r
321 certain windows or not. For example, when using commands, you can specify a\r
322 command like this: [title="<strong>Firefox</strong>"] kill. The title member of the match\r
323 data structure will then be filled and i3 will check each window using\r
324 match_matches_window() to find the windows affected by this command.\r
325 </p>\r
326 </dd>\r
327 <dt class="hdlist1">\r
328 src/move.c\r
329 </dt>\r
330 <dd>\r
331 <p>\r
332 Contains code to move a container in a specific direction.\r
333 </p>\r
334 </dd>\r
335 <dt class="hdlist1">\r
336 src/output.c\r
337 </dt>\r
338 <dd>\r
339 <p>\r
340 Functions to handle CT_OUTPUT cons.\r
341 </p>\r
342 </dd>\r
343 <dt class="hdlist1">\r
344 src/randr.c\r
345 </dt>\r
346 <dd>\r
347 <p>\r
348 The RandR API is used to get (and re-query) the configured outputs (monitors,\r
349 …).\r
350 </p>\r
351 </dd>\r
352 <dt class="hdlist1">\r
353 src/render.c\r
354 </dt>\r
355 <dd>\r
356 <p>\r
357 Renders the tree data structure by assigning coordinates to every node. These\r
358 values will later be pushed to X11 in <tt>src/x.c</tt>.\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 containers.\r
367 </p>\r
368 </dd>\r
369 <dt class="hdlist1">\r
370 src/sighandler.c\r
371 </dt>\r
372 <dd>\r
373 <p>\r
374 Handles <tt>SIGSEGV</tt>, <tt>SIGABRT</tt> and <tt>SIGFPE</tt> by showing a dialog that i3 crashed.\r
375 You can chose to let it dump core, to restart it in-place or to restart it\r
376 in-place but forget about the layout.\r
377 </p>\r
378 </dd>\r
379 <dt class="hdlist1">\r
380 src/tree.c\r
381 </dt>\r
382 <dd>\r
383 <p>\r
384 Contains functions which open or close containers in the tree, change focus or\r
385 cleanup ("flatten") the tree. See also <tt>src/move.c</tt> for another similar\r
386 function, which was moved into its own file because it is so long.\r
387 </p>\r
388 </dd>\r
389 <dt class="hdlist1">\r
390 src/util.c\r
391 </dt>\r
392 <dd>\r
393 <p>\r
394 Contains useful functions which are not really dependant on anything.\r
395 </p>\r
396 </dd>\r
397 <dt class="hdlist1">\r
398 src/window.c\r
399 </dt>\r
400 <dd>\r
401 <p>\r
402 Handlers to update X11 window properties like <tt>WM_CLASS</tt>, <tt>_NET_WM_NAME</tt>,\r
403 <tt>CLIENT_LEADER</tt>, etc.\r
404 </p>\r
405 </dd>\r
406 <dt class="hdlist1">\r
407 src/workspace.c\r
408 </dt>\r
409 <dd>\r
410 <p>\r
411 Contains all functions related to workspaces (displaying, hiding, renaming…)\r
412 </p>\r
413 </dd>\r
414 <dt class="hdlist1">\r
415 src/x.c\r
416 </dt>\r
417 <dd>\r
418 <p>\r
419 Transfers our in-memory tree (see <tt>src/render.c</tt>) to X11.\r
420 </p>\r
421 </dd>\r
422 <dt class="hdlist1">\r
423 src/xcb.c\r
424 </dt>\r
425 <dd>\r
426 <p>\r
427 Contains wrappers to use xcb more easily.\r
428 </p>\r
429 </dd>\r
430 <dt class="hdlist1">\r
431 src/xcursor.c\r
432 </dt>\r
433 <dd>\r
434 <p>\r
435 XCursor functions (for cursor themes).\r
436 </p>\r
437 </dd>\r
438 <dt class="hdlist1">\r
439 src/xinerama.c\r
440 </dt>\r
441 <dd>\r
442 <p>\r
443 Legacy support for Xinerama. See <tt>src/randr.c</tt> for the preferred API.\r
444 </p>\r
445 </dd>\r
446 </dl></div>\r
447 </div>\r
448 </div>\r
449 <div class="sect1">\r
450 <h2 id="_data_structures">3. Data structures</h2>\r
451 <div class="sectionbody">\r
452 <div class="paragraph"><p>See include/data.h for documented data structures. The most important ones are\r
453 explained right here.</p></div>\r
454 <div class="paragraph"><p>So, the hierarchy is:</p></div>\r
455 <div class="olist arabic"><ol class="arabic">\r
456 <li>\r
457 <p>\r
458 <strong>X11 root window</strong>, the root container\r
459 </p>\r
460 </li>\r
461 <li>\r
462 <p>\r
463 <strong>Output container</strong> (LVDS1 in this example)\r
464 </p>\r
465 </li>\r
466 <li>\r
467 <p>\r
468 <strong>Content container</strong> (there are also containers for dock windows)\r
469 </p>\r
470 </li>\r
471 <li>\r
472 <p>\r
473 <strong>Workspaces</strong> (Workspace 1 in this example, with horizontal orientation)\r
474 </p>\r
475 </li>\r
476 <li>\r
477 <p>\r
478 <strong>Split container</strong> (vertically split)\r
479 </p>\r
480 </li>\r
481 <li>\r
482 <p>\r
483 <strong>X11 window containers</strong>\r
484 </p>\r
485 </li>\r
486 </ol></div>\r
487 <div class="paragraph"><p>The data type is <tt>Con</tt>, in all cases.</p></div>\r
488 <div class="sect2">\r
489 <h3 id="_x11_root_window">3.1. X11 root window</h3>\r
490 <div class="paragraph"><p>The X11 root window is a single window per X11 display (a display is identified\r
491 by <tt>:0</tt> or <tt>:1</tt> etc.). The root window is what you draw your background image\r
492 on. It spans all the available outputs, e.g. <tt>VGA1</tt> is a specific part of the\r
493 root window and <tt>LVDS1</tt> is a specific part of the root window.</p></div>\r
494 </div>\r
495 <div class="sect2">\r
496 <h3 id="_output_container">3.2. Output container</h3>\r
497 <div class="paragraph"><p>Every active output obtained through RandR is represented by one output\r
498 container. Outputs are considered active when a mode is configured (meaning\r
499 something is actually displayed on the output) and the output is not a clone.</p></div>\r
500 <div class="paragraph"><p>For example, if your notebook has a screen resolution of 1280x800 px and you\r
501 connect a video projector with a resolution of 1024x768 px, set it up in clone\r
502 mode (<tt>xrandr --output VGA1 --mode 1024x768 --same-as LVDS1</tt>), i3 will\r
503 reduce the resolution to the lowest common resolution and disable one of the\r
504 cloned outputs afterwards.</p></div>\r
505 <div class="paragraph"><p>However, if you configure it using <tt>xrandr --output VGA1 --mode 1024x768\r
506 --right-of LVDS1</tt>, i3 will set both outputs active. For each output, a new\r
507 workspace will be assigned. New workspaces are created on the output you are\r
508 currently on.</p></div>\r
509 </div>\r
510 <div class="sect2">\r
511 <h3 id="_content_container">3.3. Content container</h3>\r
512 <div class="paragraph"><p>Each output has multiple children. Two of them are dock containers which hold\r
513 dock clients. The other one is the content container, which holds the actual\r
514 content (workspaces) of this output.</p></div>\r
515 </div>\r
516 <div class="sect2">\r
517 <h3 id="_workspace">3.4. Workspace</h3>\r
518 <div class="paragraph"><p>A workspace is identified by its name. Basically, you could think of\r
519 workspaces as different desks in your office, if you like the desktop\r
520 metaphor. They just contain different sets of windows and are completely\r
521 separate of each other. Other window managers also call this &#8220;Virtual\r
522 desktops&#8221;.</p></div>\r
523 </div>\r
524 <div class="sect2">\r
525 <h3 id="_split_container">3.5. Split container</h3>\r
526 <div class="paragraph"><p>A split container is a container which holds an arbitrary amount of split\r
527 containers or X11 window containers. It has an orientation (horizontal or\r
528 vertical) and a layout.</p></div>\r
529 <div class="paragraph"><p>Split containers (and X11 window containers, which are a subtype of split\r
530 containers) can have different border styles.</p></div>\r
531 </div>\r
532 <div class="sect2">\r
533 <h3 id="_x11_window_container">3.6. X11 window container</h3>\r
534 <div class="paragraph"><p>An X11 window container holds exactly one X11 window. These are the leaf nodes\r
535 of the layout tree, they cannot have any children.</p></div>\r
536 </div>\r
537 </div>\r
538 </div>\r
539 <div class="sect1">\r
540 <h2 id="_list_queue_macros">4. List/queue macros</h2>\r
541 <div class="sectionbody">\r
542 <div class="paragraph"><p>i3 makes heavy use of the list macros defined in BSD operating systems. To\r
543 ensure that the operating system on which i3 is compiled has all the expected\r
544 features, i3 comes with <tt>include/queue.h</tt>. On BSD systems, you can use man\r
545 <tt>queue(3)</tt>. On Linux, you have to use google (or read the source).</p></div>\r
546 <div class="paragraph"><p>The lists used are <tt>SLIST</tt> (single linked lists), <tt>CIRCLEQ</tt> (circular\r
547 queues) and <tt>TAILQ</tt> (tail queues). Usually, only forward traversal is necessary,\r
548 so an <tt>SLIST</tt> works fine. If inserting elements at arbitrary positions or at\r
549 the end of a list is necessary, a <tt>TAILQ</tt> is used instead. However, for the\r
550 windows inside a container, a <tt>CIRCLEQ</tt> is necessary to go from the currently\r
551 selected window to the window above/below.</p></div>\r
552 </div>\r
553 </div>\r
554 <div class="sect1">\r
555 <h2 id="_naming_conventions">5. Naming conventions</h2>\r
556 <div class="sectionbody">\r
557 <div class="paragraph"><p>There is a row of standard variables used in many events. The following names\r
558 should be chosen for those:</p></div>\r
559 <div class="ulist"><ul>\r
560 <li>\r
561 <p>\r
562 &#8220;conn&#8221; is the xcb_connection_t\r
563 </p>\r
564 </li>\r
565 <li>\r
566 <p>\r
567 &#8220;event&#8221; is the event of the particular type\r
568 </p>\r
569 </li>\r
570 <li>\r
571 <p>\r
572 &#8220;con&#8221; names a container\r
573 </p>\r
574 </li>\r
575 <li>\r
576 <p>\r
577 &#8220;current&#8221; is a loop variable when using <tt>TAILQ_FOREACH</tt> etc.\r
578 </p>\r
579 </li>\r
580 </ul></div>\r
581 </div>\r
582 </div>\r
583 <div class="sect1">\r
584 <h2 id="_startup_src_mainx_c_main">6. Startup (src/mainx.c, main())</h2>\r
585 <div class="sectionbody">\r
586 <div class="ulist"><ul>\r
587 <li>\r
588 <p>\r
589 Establish the xcb connection\r
590 </p>\r
591 </li>\r
592 <li>\r
593 <p>\r
594 Check for XKB extension on the separate X connection, load Xcursor\r
595 </p>\r
596 </li>\r
597 <li>\r
598 <p>\r
599 Check for RandR screens (with a fall-back to Xinerama)\r
600 </p>\r
601 </li>\r
602 <li>\r
603 <p>\r
604 Grab the keycodes for which bindings exist\r
605 </p>\r
606 </li>\r
607 <li>\r
608 <p>\r
609 Manage all existing windows\r
610 </p>\r
611 </li>\r
612 <li>\r
613 <p>\r
614 Enter the event loop\r
615 </p>\r
616 </li>\r
617 </ul></div>\r
618 </div>\r
619 </div>\r
620 <div class="sect1">\r
621 <h2 id="_keybindings">7. Keybindings</h2>\r
622 <div class="sectionbody">\r
623 <div class="sect2">\r
624 <h3 id="_grabbing_the_bindings">7.1. Grabbing the bindings</h3>\r
625 <div class="paragraph"><p>Grabbing the bindings is quite straight-forward. You pass X your combination of\r
626 modifiers and the keycode you want to grab and whether you want to grab them\r
627 actively or passively. Most bindings (everything except for bindings using\r
628 Mode_switch) are grabbed passively, that is, just the window manager gets the\r
629 event and cannot replay it.</p></div>\r
630 <div class="paragraph"><p>We need to grab bindings that use Mode_switch actively because of a bug in X.\r
631 When the window manager receives the keypress/keyrelease event for an actively\r
632 grabbed keycode, it has to decide what to do with this event: It can either\r
633 replay it so that other applications get it or it can prevent other\r
634 applications from receiving it.</p></div>\r
635 <div class="paragraph"><p>So, why do we need to grab keycodes actively? Because X does not set the\r
636 state-property of keypress/keyrelease events properly. The Mode_switch bit is\r
637 not set and we need to get it using XkbGetState. This means we cannot pass X\r
638 our combination of modifiers containing Mode_switch when grabbing the key and\r
639 therefore need to grab the keycode itself without any modifiers. This means,\r
640 if you bind Mode_switch + keycode 38 ("a"), i3 will grab keycode 38 ("a") and\r
641 check on each press of "a" if the Mode_switch bit is set using XKB. If yes, it\r
642 will handle the event, if not, it will replay the event.</p></div>\r
643 </div>\r
644 <div class="sect2">\r
645 <h3 id="_handling_a_keypress">7.2. Handling a keypress</h3>\r
646 <div class="paragraph"><p>As mentioned in "Grabbing the bindings", upon a keypress event, i3 first gets\r
647 the correct state.</p></div>\r
648 <div class="paragraph"><p>Then, it looks through all bindings and gets the one which matches the received\r
649 event.</p></div>\r
650 <div class="paragraph"><p>The bound command is parsed by the cmdparse lexer/parser, see <tt>parse_cmd</tt> in\r
651 <tt>src/cmdparse.y</tt>.</p></div>\r
652 </div>\r
653 </div>\r
654 </div>\r
655 <div class="sect1">\r
656 <h2 id="_manage_windows_src_main_c_manage_window_and_reparent_window">8. Manage windows (src/main.c, manage_window() and reparent_window())</h2>\r
657 <div class="sectionbody">\r
658 <div class="paragraph"><p><tt>manage_window()</tt> does some checks to decide whether the window should be\r
659 managed at all:</p></div>\r
660 <div class="ulist"><ul>\r
661 <li>\r
662 <p>\r
663 Windows have to be mapped, that is, visible on screen\r
664 </p>\r
665 </li>\r
666 <li>\r
667 <p>\r
668 The override_redirect must not be set. Windows with override_redirect shall\r
669    not be managed by a window manager\r
670 </p>\r
671 </li>\r
672 </ul></div>\r
673 <div class="paragraph"><p>Afterwards, i3 gets the initial geometry and reparents the window (see\r
674 <tt>reparent_window()</tt>) if it wasn’t already managed.</p></div>\r
675 <div class="paragraph"><p>Reparenting means that for each window which is reparented, a new window,\r
676 slightly larger than the original one, is created. The original window is then\r
677 reparented to the bigger one (called "frame").</p></div>\r
678 <div class="paragraph"><p>After reparenting, the window type (<tt>_NET_WM_WINDOW_TYPE</tt>) is checked to see\r
679 whether this window is a dock (<tt>_NET_WM_WINDOW_TYPE_DOCK</tt>), like dzen2 for\r
680 example. Docks are handled differently, they don’t have decorations and are not\r
681 assigned to a specific container. Instead, they are positioned at the bottom\r
682 or top of the screen (in the appropriate dock area containers). To get the\r
683 height which needs to be reserved for the window, the <tt>_NET_WM_STRUT_PARTIAL</tt>\r
684 property is used.</p></div>\r
685 <div class="paragraph"><p>Furthermore, the list of assignments (to other workspaces, which may be on\r
686 other screens) is checked. If the window matches one of the user’s criteria,\r
687 it may either be put in floating mode or moved to a different workspace. If the\r
688 target workspace is not visible, the window will not be mapped.</p></div>\r
689 </div>\r
690 </div>\r
691 <div class="sect1">\r
692 <h2 id="_what_happens_when_an_application_is_started">9. What happens when an application is started?</h2>\r
693 <div class="sectionbody">\r
694 <div class="paragraph"><p>i3 does not care about applications. All it notices is when new windows are\r
695 mapped (see <tt>src/handlers.c</tt>, <tt>handle_map_request()</tt>). The window is then\r
696 reparented (see section "Manage windows").</p></div>\r
697 <div class="paragraph"><p>After reparenting the window, <tt>render_tree()</tt> is called which renders the\r
698 internal layout table. The new window has been placed in the currently focused\r
699 container and therefore the new window and the old windows (if any) need to be\r
700 moved/resized so that the currently active layout (default/stacking/tabbed mode)\r
701 is rendered correctly. To move/resize windows, a window is &#8220;configured&#8221; in\r
702 X11-speak.</p></div>\r
703 <div class="paragraph"><p>Some applications, such as MPlayer obviously assume the window manager is\r
704 stupid and try to configure their windows by themselves. This generates an\r
705 event called configurerequest. i3 handles these events and tells the window the\r
706 size it had before the configurerequest (with the exception of not yet mapped\r
707 windows, which get configured like they want to, and floating windows, which\r
708 can reconfigure themselves).</p></div>\r
709 </div>\r
710 </div>\r
711 <div class="sect1">\r
712 <h2 id="_net_wm_state">10. _NET_WM_STATE</h2>\r
713 <div class="sectionbody">\r
714 <div class="paragraph"><p>Only the _NET_WM_STATE_FULLSCREEN atom is handled. It calls\r
715 &#8220;toggle_fullscreen()&#8221; for the specific client which just configures the\r
716 client to use the whole screen on which it currently is. Also, it is set as\r
717 fullscreen_client for the i3Screen.</p></div>\r
718 </div>\r
719 </div>\r
720 <div class="sect1">\r
721 <h2 id="_wm_name">11. WM_NAME</h2>\r
722 <div class="sectionbody">\r
723 <div class="paragraph"><p>When the WM_NAME property of a window changes, its decoration (containing the\r
724 title) is re-rendered. Note that WM_NAME is in COMPOUND_TEXT encoding which is\r
725 totally uncommon and cumbersome. Therefore, the _NET_WM_NAME atom will be used\r
726 if present.</p></div>\r
727 </div>\r
728 </div>\r
729 <div class="sect1">\r
730 <h2 id="_net_wm_name">12. _NET_WM_NAME</h2>\r
731 <div class="sectionbody">\r
732 <div class="paragraph"><p>Like WM_NAME, this atom contains the title of a window. However, _NET_WM_NAME\r
733 is encoded in UTF-8. i3 will recode it to UCS-2 in order to be able to pass it\r
734 to X. Using an appropriate font (ISO-10646), you can see most special\r
735 characters (every special character contained in your font).</p></div>\r
736 </div>\r
737 </div>\r
738 <div class="sect1">\r
739 <h2 id="_size_hints">13. Size hints</h2>\r
740 <div class="sectionbody">\r
741 <div class="paragraph"><p>Size hints specify the minimum/maximum size for a given window as well as its\r
742 aspect ratio.  This is important for clients like mplayer, who only set the\r
743 aspect ratio and resize their window to be as small as possible (but only with\r
744 some video outputs, for example in Xv, while when using x11, mplayer does the\r
745 necessary centering for itself).</p></div>\r
746 <div class="paragraph"><p>So, when an aspect ratio was specified, i3 adjusts the height of the window\r
747 until the size maintains the correct aspect ratio. For the code to do this, see\r
748 src/layout.c, function resize_client().</p></div>\r
749 </div>\r
750 </div>\r
751 <div class="sect1">\r
752 <h2 id="_rendering_src_layout_c_render_layout_and_render_container">14. Rendering (src/layout.c, render_layout() and render_container())</h2>\r
753 <div class="sectionbody">\r
754 <div class="paragraph"><p>Rendering in i3 version 4 is the step which assigns the correct sizes for\r
755 borders, decoration windows, child windows and the stacking order of all\r
756 windows. In a separate step (<tt>x_push_changes()</tt>), these changes are pushed to\r
757 X11.</p></div>\r
758 <div class="paragraph"><p>Keep in mind that all these properties (<tt>rect</tt>, <tt>window_rect</tt> and <tt>deco_rect</tt>)\r
759 are temporary, meaning they will be overwritten by calling <tt>render_con</tt>.\r
760 Persistent position/size information is kept in <tt>geometry</tt>.</p></div>\r
761 <div class="paragraph"><p>The entry point for every rendering operation (except for the case of moving\r
762 floating windows around) currently is <tt>tree_render()</tt> which will re-render\r
763 everything that’s necessary (for every output, only the currently displayed\r
764 workspace is rendered). This behavior is expected to change in the future,\r
765 since for a lot of updates, re-rendering everything is not actually necessary.\r
766 Focus was on getting it working correct, not getting it work very fast.</p></div>\r
767 <div class="paragraph"><p>What <tt>tree_render()</tt> actually does is calling <tt>render_con()</tt> on the root\r
768 container and then pushing the changes to X11. The following sections talk\r
769 about the different rendering steps, in the order of "top of the tree" (root\r
770 container) to the bottom.</p></div>\r
771 <div class="sect2">\r
772 <h3 id="_rendering_the_root_container">14.1. Rendering the root container</h3>\r
773 <div class="paragraph"><p>The i3 root container (<tt>con-&gt;type == CT_ROOT</tt>) represents the X11 root window.\r
774 It contains one child container for every output (like LVDS1, VGA1, …), which\r
775 is available on your computer.</p></div>\r
776 <div class="paragraph"><p>Rendering the root will first render all tiling windows and then all floating\r
777 windows. This is necessary because a floating window can be positioned in such\r
778 a way that it is visible on two different outputs. Therefore, by first\r
779 rendering all the tiling windows (of all outputs), we make sure that floating\r
780 windows can never be obscured by tiling windows.</p></div>\r
781 <div class="paragraph"><p>Essentially, though, this code path will just call <tt>render_con()</tt> for every\r
782 output and <tt>x_raise_con(); render_con()</tt> for every floating window.</p></div>\r
783 <div class="paragraph"><p>In the special case of having a "global fullscreen" window (fullscreen mode\r
784 spanning all outputs), a shortcut is taken and <tt>x_raise_con(); render_con()</tt> is\r
785 only called for the global fullscreen window.</p></div>\r
786 </div>\r
787 <div class="sect2">\r
788 <h3 id="_rendering_an_output">14.2. Rendering an output</h3>\r
789 <div class="paragraph"><p>Output containers (<tt>con-&gt;layout == L_OUTPUT</tt>) represent a hardware output like\r
790 LVDS1, VGA1, etc. An output container has three children (at the moment): One\r
791 content container (having workspaces as children) and the top/bottom dock area\r
792 containers.</p></div>\r
793 <div class="paragraph"><p>The rendering happens in the function <tt>render_l_output()</tt> in the following\r
794 steps:</p></div>\r
795 <div class="olist arabic"><ol class="arabic">\r
796 <li>\r
797 <p>\r
798 Find the content container (<tt>con-&gt;type == CT_CON</tt>)\r
799 </p>\r
800 </li>\r
801 <li>\r
802 <p>\r
803 Get the currently visible workspace (<tt>con_get_fullscreen_con(content,\r
804    CF_OUTPUT)</tt>).\r
805 </p>\r
806 </li>\r
807 <li>\r
808 <p>\r
809 If there is a fullscreened window on that workspace, directly render it and\r
810    return, thus ignoring the dock areas.\r
811 </p>\r
812 </li>\r
813 <li>\r
814 <p>\r
815 Sum up the space used by all the dock windows (they have a variable height\r
816    only).\r
817 </p>\r
818 </li>\r
819 <li>\r
820 <p>\r
821 Set the workspace rects (x/y/width/height) based on the position of the\r
822    output (stored in <tt>con-&gt;rect</tt>) and the usable space\r
823    (<tt>con-&gt;rect.{width,height}</tt> without the space used for dock windows).\r
824 </p>\r
825 </li>\r
826 <li>\r
827 <p>\r
828 Recursively raise and render the output’s child containers (meaning dock\r
829    area containers and the content container).\r
830 </p>\r
831 </li>\r
832 </ol></div>\r
833 </div>\r
834 <div class="sect2">\r
835 <h3 id="_rendering_a_workspace_or_split_container">14.3. Rendering a workspace or split container</h3>\r
836 <div class="paragraph"><p>From here on, there really is no difference anymore. All containers are of\r
837 <tt>con-&gt;type == CT_CON</tt> (whether workspace or split container) and some of them\r
838 have a <tt>con-&gt;window</tt>, meaning they represent an actual window instead of a\r
839 split container.</p></div>\r
840 <div class="sect3">\r
841 <h4 id="_default_layout">14.3.1. Default layout</h4>\r
842 <div class="paragraph"><p>In default layout, containers are placed horizontally or vertically next to\r
843 each other (depending on the <tt>con-&gt;orientation</tt>). If a child is a leaf node (as\r
844 opposed to a split container) and has border style "normal", appropriate space\r
845 will be reserved for its window decoration.</p></div>\r
846 </div>\r
847 <div class="sect3">\r
848 <h4 id="_stacked_layout">14.3.2. Stacked layout</h4>\r
849 <div class="paragraph"><p>In stacked layout, only the focused window is actually shown (this is achieved\r
850 by calling <tt>x_raise_con()</tt> in reverse focus order at the end of <tt>render_con()</tt>).</p></div>\r
851 <div class="paragraph"><p>The available space for the focused window is the size of the container minus\r
852 the height of the window decoration for all windows inside this stacked\r
853 container.</p></div>\r
854 <div class="paragraph"><p>If border style is "1pixel" or "none", no window decoration height will be\r
855 reserved (or displayed later on), unless there is more than one window inside\r
856 the stacked container.</p></div>\r
857 </div>\r
858 <div class="sect3">\r
859 <h4 id="_tabbed_layout">14.3.3. Tabbed layout</h4>\r
860 <div class="paragraph"><p>Tabbed layout works precisely like stacked layout, but the window decoration\r
861 position/size is different: They are placed next to each other on a single line\r
862 (fixed height).</p></div>\r
863 </div>\r
864 <div class="sect3">\r
865 <h4 id="_dock_area_layout">14.3.4. Dock area layout</h4>\r
866 <div class="paragraph"><p>This is a special case. Users cannot choose the dock area layout, but it will be\r
867 set for the dock area containers. In the dockarea layout (at the moment!),\r
868 windows will be placed above each other.</p></div>\r
869 </div>\r
870 </div>\r
871 <div class="sect2">\r
872 <h3 id="_rendering_a_window">14.4. Rendering a window</h3>\r
873 <div class="paragraph"><p>A window’s size and position will be determined in the following way:</p></div>\r
874 <div class="olist arabic"><ol class="arabic">\r
875 <li>\r
876 <p>\r
877 Subtract the border if border style is not "none" (but "normal" or "1pixel").\r
878 </p>\r
879 </li>\r
880 <li>\r
881 <p>\r
882 Subtract the X11 border, if the window has an X11 border &gt; 0.\r
883 </p>\r
884 </li>\r
885 <li>\r
886 <p>\r
887 Obey the aspect ratio of the window (think MPlayer).\r
888 </p>\r
889 </li>\r
890 <li>\r
891 <p>\r
892 Obey the height- and width-increments of the window (think terminal emulator\r
893    which can only be resized in one-line or one-character steps).\r
894 </p>\r
895 </li>\r
896 </ol></div>\r
897 </div>\r
898 </div>\r
899 </div>\r
900 <div class="sect1">\r
901 <h2 id="_pushing_updates_to_x11_drawing">15. Pushing updates to X11 / Drawing</h2>\r
902 <div class="sectionbody">\r
903 <div class="paragraph"><p>A big problem with i3 before version 4 was that we just sent requests to X11\r
904 anywhere in the source code. This was bad because nobody could understand the\r
905 entirety of our interaction with X11, it lead to subtle bugs and a lot of edge\r
906 cases which we had to consider all over again.</p></div>\r
907 <div class="paragraph"><p>Therefore, since version 4, we have a single file, <tt>src/x.c</tt>, which is\r
908 responsible for repeatedly transferring parts of our tree datastructure to X11.</p></div>\r
909 <div class="paragraph"><p><tt>src/x.c</tt> consists of multiple parts:</p></div>\r
910 <div class="olist arabic"><ol class="arabic">\r
911 <li>\r
912 <p>\r
913 The state pushing: <tt>x_push_changes()</tt>, which calls <tt>x_push_node()</tt>.\r
914 </p>\r
915 </li>\r
916 <li>\r
917 <p>\r
918 State modification functions: <tt>x_con_init</tt>, <tt>x_reinit</tt>,\r
919    <tt>x_reparent_child</tt>, <tt>x_move_win</tt>, <tt>x_con_kill</tt>, <tt>x_raise_con</tt>, <tt>x_set_name</tt>\r
920    and <tt>x_set_warp_to</tt>.\r
921 </p>\r
922 </li>\r
923 <li>\r
924 <p>\r
925 Expose event handling (drawing decorations): <tt>x_deco_recurse()</tt> and\r
926    <tt>x_draw_decoration()</tt>.\r
927 </p>\r
928 </li>\r
929 </ol></div>\r
930 <div class="sect2">\r
931 <h3 id="_pushing_state_to_x11">15.1. Pushing state to X11</h3>\r
932 <div class="paragraph"><p>In general, the function <tt>x_push_changes</tt> should be called to push state\r
933 changes. Only when the scope of the state change is clearly defined (for\r
934 example only the title of a window) and its impact is known beforehand, one can\r
935 optimize this and call <tt>x_push_node</tt> on the appropriate con directly.</p></div>\r
936 <div class="paragraph"><p><tt>x_push_changes</tt> works in the following steps:</p></div>\r
937 <div class="olist arabic"><ol class="arabic">\r
938 <li>\r
939 <p>\r
940 Clear the eventmask for all mapped windows. This leads to not getting\r
941    useless ConfigureNotify or EnterNotify events which are caused by our\r
942    requests. In general, we only want to handle user input.\r
943 </p>\r
944 </li>\r
945 <li>\r
946 <p>\r
947 Stack windows above each other, in reverse stack order (starting with the\r
948    most obscured/bottom window). This is relevant for floating windows which\r
949    can overlap each other, but also for tiling windows in stacked or tabbed\r
950    containers. We also update the <tt>_NET_CLIENT_LIST_STACKING</tt> hint which is\r
951    necessary for tab drag and drop in Chromium.\r
952 </p>\r
953 </li>\r
954 <li>\r
955 <p>\r
956 <tt>x_push_node</tt> will be called for the root container, recursively calling\r
957    itself for the container’s children. This function actually pushes the\r
958    state, see the next paragraph.\r
959 </p>\r
960 </li>\r
961 <li>\r
962 <p>\r
963 If the pointer needs to be warped to a different position (for example when\r
964    changing focus to a differnt output), it will be warped now.\r
965 </p>\r
966 </li>\r
967 <li>\r
968 <p>\r
969 The eventmask is restored for all mapped windows.\r
970 </p>\r
971 </li>\r
972 <li>\r
973 <p>\r
974 Window decorations will be rendered by calling <tt>x_deco_recurse</tt> on the root\r
975    container, which then recursively calls itself for the children.\r
976 </p>\r
977 </li>\r
978 <li>\r
979 <p>\r
980 If the input focus needs to be changed (because the user focused a different\r
981    window), it will be updated now.\r
982 </p>\r
983 </li>\r
984 <li>\r
985 <p>\r
986 <tt>x_push_node_unmaps</tt> will be called for the root container. This function\r
987    only pushes UnmapWindow requests. Separating the state pushing is necessary\r
988    to handle fullscreen windows (and workspace switches) in a smooth fashion:\r
989    The newly visible windows should be visible before the old windows are\r
990    unmapped.\r
991 </p>\r
992 </li>\r
993 </ol></div>\r
994 <div class="paragraph"><p><tt>x_push_node</tt> works in the following steps:</p></div>\r
995 <div class="olist arabic"><ol class="arabic">\r
996 <li>\r
997 <p>\r
998 Update the window’s <tt>WM_NAME</tt>, if changed (the <tt>WM_NAME</tt> is set on i3\r
999    containers mainly for debugging purposes).\r
1000 </p>\r
1001 </li>\r
1002 <li>\r
1003 <p>\r
1004 Reparents a child window into the i3 container if the container was created\r
1005    for a specific managed window.\r
1006 </p>\r
1007 </li>\r
1008 <li>\r
1009 <p>\r
1010 If the size/position of the i3 container changed (due to opening a new\r
1011    window or switching layouts for example), the window will be reconfigured.\r
1012    Also, the pixmap which is used to draw the window decoration/border on is\r
1013    reconfigured (pixmaps are size-dependent).\r
1014 </p>\r
1015 </li>\r
1016 <li>\r
1017 <p>\r
1018 Size/position for the child window is adjusted.\r
1019 </p>\r
1020 </li>\r
1021 <li>\r
1022 <p>\r
1023 The i3 container is mapped if it should be visible and was not yet mapped.\r
1024    When mapping, <tt>WM_STATE</tt> is set to <tt>WM_STATE_NORMAL</tt>. Also, the eventmask of\r
1025    the child window is updated and the i3 container’s contents are copied from\r
1026    the pixmap.\r
1027 </p>\r
1028 </li>\r
1029 <li>\r
1030 <p>\r
1031 <tt>x_push_node</tt> is called recursively for all children of the current\r
1032    container.\r
1033 </p>\r
1034 </li>\r
1035 </ol></div>\r
1036 <div class="paragraph"><p><tt>x_push_node_unmaps</tt> handles the remaining case of an i3 container being\r
1037 unmapped if it should not be visible anymore. <tt>WM_STATE</tt> will be set to\r
1038 <tt>WM_STATE_WITHDRAWN</tt>.</p></div>\r
1039 </div>\r
1040 <div class="sect2">\r
1041 <h3 id="_drawing_window_decorations_borders_backgrounds">15.2. Drawing window decorations/borders/backgrounds</h3>\r
1042 <div class="paragraph"><p><tt>x_draw_decoration</tt> draws window decorations. It is run for every leaf\r
1043 container (representing an actual X11 window) and for every non-leaf container\r
1044 which is in a stacked/tabbed container (because stacked/tabbed containers\r
1045 display a window decoration for split containers, which at the moment just says\r
1046 "another container").</p></div>\r
1047 <div class="paragraph"><p>Then, parameters are collected to be able to determine whether this decoration\r
1048 drawing is actually necessary or was already done. This saves a substantial\r
1049 number of redraws (depending on your workload, but far over 50%).</p></div>\r
1050 <div class="paragraph"><p>Assuming that we need to draw this decoration, we start by filling the empty\r
1051 space around the child window (think of MPlayer with a specific aspect ratio)\r
1052 in the user-configured client background color.</p></div>\r
1053 <div class="paragraph"><p>Afterwards, we draw the appropriate border (in case of border styles "normal"\r
1054 and "1pixel") and the top bar (in case of border style "normal").</p></div>\r
1055 <div class="paragraph"><p>The last step is drawing the window title on the top bar.</p></div>\r
1056 </div>\r
1057 </div>\r
1058 </div>\r
1059 <div class="sect1">\r
1060 <h2 id="_user_commands_parser_specs_commands_spec">16. User commands (parser-specs/commands.spec)</h2>\r
1061 <div class="sectionbody">\r
1062 <div class="paragraph"><p>In the configuration file and when using i3 interactively (with <tt>i3-msg</tt>, for\r
1063 example), you use commands to make i3 do things, like focus a different window,\r
1064 set a window to fullscreen, and so on. An example command is <tt>floating enable</tt>,\r
1065 which enables floating mode for the currently focused window. See the\r
1066 appropriate section in the <a href="userguide.html">User’s Guide</a> for a reference of\r
1067 all commands.</p></div>\r
1068 <div class="paragraph"><p>In earlier versions of i3, interpreting these commands was done using lex and\r
1069 yacc, but experience has shown that lex and yacc are not well suited for our\r
1070 command language. Therefore, starting from version 4.2, we use a custom parser\r
1071 for user commands (not yet for the configuration file).\r
1072 The input specification for this parser can be found in the file\r
1073 <tt>parser-specs/commands.spec</tt>. Should you happen to use Vim as an editor, use\r
1074 :source parser-specs/highlighting.vim to get syntax highlighting for this file\r
1075 (highlighting files for other editors are welcome).</p></div>\r
1076 <div class="listingblock">\r
1077 <div class="title">Excerpt from commands.spec</div>\r
1078 <div class="content">\r
1079 <pre><tt>state INITIAL:\r
1080   '[' -&gt; call cmd_criteria_init(); CRITERIA\r
1081   'move' -&gt; MOVE\r
1082   'exec' -&gt; EXEC\r
1083   'workspace' -&gt; WORKSPACE\r
1084   'exit' -&gt; call cmd_exit()\r
1085   'restart' -&gt; call cmd_restart()\r
1086   'reload' -&gt; call cmd_reload()</tt></pre>\r
1087 </div></div>\r
1088 <div class="paragraph"><p>The input specification is written in an extremely simple format. The\r
1089 specification is then converted into C code by the Perl script\r
1090 generate-commands-parser.pl (the output file names begin with GENERATED and the\r
1091 files are stored in the <tt>include</tt> directory). The parser implementation\r
1092 <tt>src/commands_parser.c</tt> includes the generated C code at compile-time.</p></div>\r
1093 <div class="paragraph"><p>The above excerpt from commands.spec illustrates nearly all features of our\r
1094 specification format: You describe different states and what can happen within\r
1095 each state. State names are all-caps; the state in the above excerpt is called\r
1096 INITIAL. A list of tokens and their actions (separated by an ASCII arrow)\r
1097 follows. In the excerpt, all tokens are literals, that is, simple text strings\r
1098 which will be compared with the input. An action is either the name of a state\r
1099 in which the parser will transition into, or the keyword <em>call</em>, followed by\r
1100 the name of a function (and optionally a state).</p></div>\r
1101 <div class="sect2">\r
1102 <h3 id="_example_the_workspace_state">16.1. Example: The WORKSPACE state</h3>\r
1103 <div class="paragraph"><p>Let’s have a look at the WORKSPACE state, which is a good example of all\r
1104 features. This is its definition:</p></div>\r
1105 <div class="listingblock">\r
1106 <div class="title">WORKSPACE state (commands.spec)</div>\r
1107 <div class="content">\r
1108 <pre><tt># workspace next|prev|next_on_output|prev_on_output\r
1109 # workspace back_and_forth\r
1110 # workspace &lt;name&gt;\r
1111 state WORKSPACE:\r
1112   direction = 'next_on_output', 'prev_on_output', 'next', 'prev'\r
1113       -&gt; call cmd_workspace($direction)\r
1114   'back_and_forth'\r
1115       -&gt; call cmd_workspace_back_and_forth()\r
1116   workspace = string\r
1117       -&gt; call cmd_workspace_name($workspace)</tt></pre>\r
1118 </div></div>\r
1119 <div class="paragraph"><p>As you can see from the commands, there are multiple different valid variants\r
1120 of the workspace command:</p></div>\r
1121 <div class="dlist"><dl>\r
1122 <dt class="hdlist1">\r
1123 workspace &lt;direction&gt;\r
1124 </dt>\r
1125 <dd>\r
1126 <p>\r
1127         The word <em>workspace</em> can be followed by any of the tokens <em>next</em>,\r
1128         <em>prev</em>, <em>next_on_output</em> or <em>prev_on_output</em>. This command will\r
1129         switch to the next or previous workspace (optionally on the same\r
1130         output).<br />\r
1131         There is one function called <tt>cmd_workspace</tt>, which is defined\r
1132         in <tt>src/commands.c</tt>. It will handle this kind of command. To know which\r
1133         direction was specified, the direction token is stored on the stack\r
1134         with the name "direction", which is what the "direction = " means in\r
1135         the beginning.<br />\r
1136 </p>\r
1137 </dd>\r
1138 </dl></div>\r
1139 <div class="admonitionblock">\r
1140 <table><tr>\r
1141 <td class="icon">\r
1142 <div class="title">Note</div>\r
1143 </td>\r
1144 <td class="content">Note that you can specify multiple literals in the same line. This has\r
1145         exactly the same effect as if you specified <tt>direction =\r
1146         'next_on_output' -&gt; call cmd_workspace($direction)</tt> and so forth.<br /></td>\r
1147 </tr></table>\r
1148 </div>\r
1149 <div class="admonitionblock">\r
1150 <table><tr>\r
1151 <td class="icon">\r
1152 <div class="title">Note</div>\r
1153 </td>\r
1154 <td class="content">Also note that the order of literals is important here: If <em>next</em> were\r
1155         ordered before <em>next_on_output</em>, then <em>next_on_output</em> would never\r
1156         match.</td>\r
1157 </tr></table>\r
1158 </div>\r
1159 <div class="dlist"><dl>\r
1160 <dt class="hdlist1">\r
1161 workspace back_and_forth\r
1162 </dt>\r
1163 <dd>\r
1164 <p>\r
1165         This is a very simple case: When the literal <em>back_and_forth</em> is found\r
1166         in the input, the function <tt>cmd_workspace_back_and_forth</tt> will be\r
1167         called without parameters and the parser will return to the INITIAL\r
1168         state (since no other state was specified).\r
1169 </p>\r
1170 </dd>\r
1171 <dt class="hdlist1">\r
1172 workspace &lt;name&gt;\r
1173 </dt>\r
1174 <dd>\r
1175 <p>\r
1176         In this case, the workspace command is followed by an arbitrary string,\r
1177         possibly in quotes, for example "workspace 3" or "workspace bleh".<br />\r
1178         This is the first time that the token is actually not a literal (not in\r
1179         single quotes), but just called string. Other possible tokens are word\r
1180         (the same as string, but stops matching at a whitespace) and end\r
1181         (matches the end of the input).\r
1182 </p>\r
1183 </dd>\r
1184 </dl></div>\r
1185 </div>\r
1186 <div class="sect2">\r
1187 <h3 id="_introducing_a_new_command">16.2. Introducing a new command</h3>\r
1188 <div class="paragraph"><p>The following steps have to be taken in order to properly introduce a new\r
1189 command (or possibly extend an existing command):</p></div>\r
1190 <div class="olist arabic"><ol class="arabic">\r
1191 <li>\r
1192 <p>\r
1193 Define a function beginning with <tt>cmd_</tt> in the file <tt>src/commands.c</tt>. Copy\r
1194    the prototype of an existing function.\r
1195 </p>\r
1196 </li>\r
1197 <li>\r
1198 <p>\r
1199 After adding a comment on what the function does, copy the comment and\r
1200    function definition to <tt>include/commands.h</tt>. Make the comment in the header\r
1201    file use double asterisks to make doxygen pick it up.\r
1202 </p>\r
1203 </li>\r
1204 <li>\r
1205 <p>\r
1206 Write a test case (or extend an existing test case) for your feature, see\r
1207    <a href="testsuite.html">i3 testsuite</a>. For now, it is sufficient to simply call\r
1208    your command in all the various possible ways.\r
1209 </p>\r
1210 </li>\r
1211 <li>\r
1212 <p>\r
1213 Extend the parser specification in <tt>parser-specs/commands.spec</tt>. Run the\r
1214    testsuite and see if your new function gets called with the appropriate\r
1215    arguments for the appropriate input.\r
1216 </p>\r
1217 </li>\r
1218 <li>\r
1219 <p>\r
1220 Actually implement the feature.\r
1221 </p>\r
1222 </li>\r
1223 <li>\r
1224 <p>\r
1225 Document the feature in the <a href="userguide.html">User’s Guide</a>.\r
1226 </p>\r
1227 </li>\r
1228 </ol></div>\r
1229 </div>\r
1230 </div>\r
1231 </div>\r
1232 <div class="sect1">\r
1233 <h2 id="_moving_containers">17. Moving containers</h2>\r
1234 <div class="sectionbody">\r
1235 <div class="paragraph"><p>The movement code is pretty delicate. You need to consider all cases before\r
1236 making any changes or before being able to fully understand how it works.</p></div>\r
1237 <div class="sect2">\r
1238 <h3 id="_case_1_moving_inside_the_same_container">17.1. Case 1: Moving inside the same container</h3>\r
1239 <div class="paragraph"><p>The reference layout for this case is a single workspace in horizontal\r
1240 orientation with two containers on it. Focus is on the left container (1).</p></div>\r
1241 <div class="tableblock">\r
1242 <table rules="all"\r
1243 width="15%"\r
1244 frame="border"\r
1245 cellspacing="0" cellpadding="4">\r
1246 <col width="50%" />\r
1247 <col width="50%" />\r
1248 <tbody>\r
1249 <tr>\r
1250 <td align="center" valign="top"><p class="table">1</p></td>\r
1251 <td align="center" valign="top"><p class="table">2</p></td>\r
1252 </tr>\r
1253 </tbody>\r
1254 </table>\r
1255 </div>\r
1256 <div class="paragraph"><p>When moving the left window to the right (command <tt>move right</tt>), tree_move will\r
1257 look for a container with horizontal orientation and finds the parent of the\r
1258 left container, that is, the workspace. Afterwards, it runs the code branch\r
1259 commented with "the easy case": it calls TAILQ_NEXT to get the container right\r
1260 of the current one and swaps both containers.</p></div>\r
1261 </div>\r
1262 <div class="sect2">\r
1263 <h3 id="_case_2_move_a_container_into_a_split_container">17.2. Case 2: Move a container into a split container</h3>\r
1264 <div class="paragraph"><p>The reference layout for this case is a horizontal workspace with two\r
1265 containers. The right container is a v-split with two containers. Focus is on\r
1266 the left container (1).</p></div>\r
1267 <div class="tableblock">\r
1268 <table rules="all"\r
1269 width="15%"\r
1270 frame="border"\r
1271 cellspacing="0" cellpadding="4">\r
1272 <col width="50%" />\r
1273 <col width="50%" />\r
1274 <tbody>\r
1275 <tr>\r
1276 <td rowspan="2" align="center" valign="middle"><p class="table">1</p></td>\r
1277 <td align="center" valign="top"><p class="table">2</p></td>\r
1278 </tr>\r
1279 <tr>\r
1280 <td align="center" valign="top"><p class="table">3</p></td>\r
1281 </tr>\r
1282 </tbody>\r
1283 </table>\r
1284 </div>\r
1285 <div class="paragraph"><p>When moving to the right (command <tt>move right</tt>), i3 will work like in case 1\r
1286 ("the easy case"). However, as the right container is not a leaf container, but\r
1287 a v-split, the left container (1) will be inserted at the right position (below\r
1288 2, assuming that 2 is focused inside the v-split) by calling <tt>insert_con_into</tt>.</p></div>\r
1289 <div class="paragraph"><p><tt>insert_con_into</tt> detaches the container from its parent and inserts it\r
1290 before/after the given target container. Afterwards, the on_remove_child\r
1291 callback is called on the old parent container which will then be closed, if\r
1292 empty.</p></div>\r
1293 <div class="paragraph"><p>Afterwards, <tt>con_focus</tt> will be called to fix the focus stack and the tree will\r
1294 be flattened.</p></div>\r
1295 </div>\r
1296 <div class="sect2">\r
1297 <h3 id="_case_3_moving_to_non_existant_top_bottom">17.3. Case 3: Moving to non-existant top/bottom</h3>\r
1298 <div class="paragraph"><p>Like in case 1, the reference layout for this case is a single workspace in\r
1299 horizontal orientation with two containers on it. Focus is on the left\r
1300 container:</p></div>\r
1301 <div class="tableblock">\r
1302 <table rules="all"\r
1303 width="15%"\r
1304 frame="border"\r
1305 cellspacing="0" cellpadding="4">\r
1306 <col width="50%" />\r
1307 <col width="50%" />\r
1308 <tbody>\r
1309 <tr>\r
1310 <td align="center" valign="top"><p class="table">1</p></td>\r
1311 <td align="center" valign="top"><p class="table">2</p></td>\r
1312 </tr>\r
1313 </tbody>\r
1314 </table>\r
1315 </div>\r
1316 <div class="paragraph"><p>This time however, the command is <tt>move up</tt> or <tt>move down</tt>. tree_move will look\r
1317 for a container with vertical orientation. As it will not find any,\r
1318 <tt>same_orientation</tt> is NULL and therefore i3 will perform a forced orientation\r
1319 change on the workspace by creating a new h-split container, moving the\r
1320 workspace contents into it and then changing the workspace orientation to\r
1321 vertical. Now it will again search for parent containers with vertical\r
1322 orientation and it will find the workspace.</p></div>\r
1323 <div class="paragraph"><p>This time, the easy case code path will not be run as we are not moving inside\r
1324 the same container. Instead, <tt>insert_con_into</tt> will be called with the focused\r
1325 container and the container above/below the current one (on the level of\r
1326 <tt>same_orientation</tt>).</p></div>\r
1327 <div class="paragraph"><p>Now, <tt>con_focus</tt> will be called to fix the focus stack and the tree will be\r
1328 flattened.</p></div>\r
1329 </div>\r
1330 <div class="sect2">\r
1331 <h3 id="_case_4_moving_to_existant_top_bottom">17.4. Case 4: Moving to existant top/bottom</h3>\r
1332 <div class="paragraph"><p>The reference layout for this case is a vertical workspace with two containers.\r
1333 The bottom one is a h-split containing two containers (1 and 2). Focus is on\r
1334 the bottom left container (1).</p></div>\r
1335 <div class="tableblock">\r
1336 <table rules="all"\r
1337 width="15%"\r
1338 frame="border"\r
1339 cellspacing="0" cellpadding="4">\r
1340 <col width="50%" />\r
1341 <col width="50%" />\r
1342 <tbody>\r
1343 <tr>\r
1344 <td colspan="2" align="center" valign="top"><p class="table">3</p></td>\r
1345 </tr>\r
1346 <tr>\r
1347 <td align="center" valign="top"><p class="table">1</p></td>\r
1348 <td align="center" valign="top"><p class="table">2</p></td>\r
1349 </tr>\r
1350 </tbody>\r
1351 </table>\r
1352 </div>\r
1353 <div class="paragraph"><p>This case is very much like case 3, only this time the forced workspace\r
1354 orientation change does not need to be performed because the workspace already\r
1355 is in vertical orientation.</p></div>\r
1356 </div>\r
1357 <div class="sect2">\r
1358 <h3 id="_case_5_moving_in_one_child_h_split">17.5. Case 5: Moving in one-child h-split</h3>\r
1359 <div class="paragraph"><p>The reference layout for this case is a horizontal workspace with two\r
1360 containers having a v-split on the left side with a one-child h-split on the\r
1361 bottom. Focus is on the bottom left container (2(h)):</p></div>\r
1362 <div class="tableblock">\r
1363 <table rules="all"\r
1364 width="15%"\r
1365 frame="border"\r
1366 cellspacing="0" cellpadding="4">\r
1367 <col width="50%" />\r
1368 <col width="50%" />\r
1369 <tbody>\r
1370 <tr>\r
1371 <td align="center" valign="top"><p class="table">1</p></td>\r
1372 <td rowspan="2" align="center" valign="middle"><p class="table">3</p></td>\r
1373 </tr>\r
1374 <tr>\r
1375 <td align="center" valign="top"><p class="table">2(h)</p></td>\r
1376 </tr>\r
1377 </tbody>\r
1378 </table>\r
1379 </div>\r
1380 <div class="paragraph"><p>In this case, <tt>same_orientation</tt> will be set to the h-split container around\r
1381 the focused container. However, when trying the easy case, the next/previous\r
1382 container <tt>swap</tt> will be NULL. Therefore, i3 will search again for a\r
1383 <tt>same_orientation</tt> container, this time starting from the parent of the h-split\r
1384 container.</p></div>\r
1385 <div class="paragraph"><p>After determining a new <tt>same_orientation</tt> container (if it is NULL, the\r
1386 orientation will be force-changed), this case is equivalent to case 2 or case\r
1387 4.</p></div>\r
1388 </div>\r
1389 <div class="sect2">\r
1390 <h3 id="_case_6_floating_containers">17.6. Case 6: Floating containers</h3>\r
1391 <div class="paragraph"><p>The reference layout for this case is a horizontal workspace with two\r
1392 containers plus one floating h-split container. Focus is on the floating\r
1393 container.</p></div>\r
1394 <div class="paragraph"><p>TODO: nice illustration. table not possible?</p></div>\r
1395 <div class="paragraph"><p>When moving up/down, the container needs to leave the floating container and it\r
1396 needs to be placed on the workspace (at workspace level). This is accomplished\r
1397 by calling the function <tt>attach_to_workspace</tt>.</p></div>\r
1398 </div>\r
1399 </div>\r
1400 </div>\r
1401 <div class="sect1">\r
1402 <h2 id="_click_handling">18. Click handling</h2>\r
1403 <div class="sectionbody">\r
1404 <div class="paragraph"><p>Without much ado, here is the list of cases which need to be considered:</p></div>\r
1405 <div class="ulist"><ul>\r
1406 <li>\r
1407 <p>\r
1408 click to focus (tiling + floating) and raise (floating)\r
1409 </p>\r
1410 </li>\r
1411 <li>\r
1412 <p>\r
1413 click to focus/raise when in stacked/tabbed mode\r
1414 </p>\r
1415 </li>\r
1416 <li>\r
1417 <p>\r
1418 floating_modifier + left mouse button to drag a floating con\r
1419 </p>\r
1420 </li>\r
1421 <li>\r
1422 <p>\r
1423 floating_modifier + right mouse button to resize a floating con\r
1424 </p>\r
1425 </li>\r
1426 <li>\r
1427 <p>\r
1428 click on decoration in a floating con to either initiate a resize (if there\r
1429   is more than one child in the floating con) or to drag the\r
1430   floating con (if it’s the one at the top).\r
1431 </p>\r
1432 </li>\r
1433 <li>\r
1434 <p>\r
1435 click on border in a floating con to resize the floating con\r
1436 </p>\r
1437 </li>\r
1438 <li>\r
1439 <p>\r
1440 floating_modifier + right mouse button to resize a tiling con\r
1441 </p>\r
1442 </li>\r
1443 <li>\r
1444 <p>\r
1445 click on border/decoration to resize a tiling con\r
1446 </p>\r
1447 </li>\r
1448 </ul></div>\r
1449 </div>\r
1450 </div>\r
1451 <div class="sect1">\r
1452 <h2 id="_gotchas">19. Gotchas</h2>\r
1453 <div class="sectionbody">\r
1454 <div class="ulist"><ul>\r
1455 <li>\r
1456 <p>\r
1457 Forgetting to call <tt>xcb_flush(conn);</tt> after sending a request. This usually\r
1458   leads to code which looks like it works fine but which does not work under\r
1459   certain conditions.\r
1460 </p>\r
1461 </li>\r
1462 <li>\r
1463 <p>\r
1464 Forgetting to call <tt>floating_fix_coordinates(con, old_rect, new_rect)</tt> after\r
1465   moving workspaces across outputs. Coordinates for floating containers are\r
1466   not relative to workspace boundaries, so you must correct their coordinates\r
1467   or those containers will show up in the wrong workspace or not at all.\r
1468 </p>\r
1469 </li>\r
1470 </ul></div>\r
1471 </div>\r
1472 </div>\r
1473 <div class="sect1">\r
1474 <h2 id="_using_git_sending_patches">20. Using git / sending patches</h2>\r
1475 <div class="sectionbody">\r
1476 <div class="sect2">\r
1477 <h3 id="_introduction">20.1. Introduction</h3>\r
1478 <div class="paragraph"><p>For a short introduction into using git, see\r
1479 <a href="http://web.archive.org/web/20121024222556/http://www.spheredev.org/wiki/Git_for_the_lazy">http://web.archive.org/web/20121024222556/http://www.spheredev.org/wiki/Git_for_the_lazy</a>\r
1480 or, for more documentation, see <a href="http://git-scm.com/documentation">http://git-scm.com/documentation</a></p></div>\r
1481 <div class="paragraph"><p>Please talk to us before working on new features to see whether they will be\r
1482 accepted. There are a few things which we don’t want to see in i3, e.g. a\r
1483 command which will focus windows in an alt+tab like way.</p></div>\r
1484 <div class="paragraph"><p>When working on bugfixes, please make sure you mention that you are working on\r
1485 it in the corresponding bugreport at <a href="http://bugs.i3wm.org/">http://bugs.i3wm.org/</a>. In case there is no\r
1486 bugreport yet, please create one.</p></div>\r
1487 <div class="paragraph"><p>After you are done, please submit your work for review at <a href="http://cr.i3wm.org/">http://cr.i3wm.org/</a></p></div>\r
1488 <div class="paragraph"><p>Do not send emails to the mailing list or any author directly, and don’t submit\r
1489 them in the bugtracker, since all reviews should be done in public at\r
1490 <a href="http://cr.i3wm.org/">http://cr.i3wm.org/</a>. In order to make your review go as fast as possible, you\r
1491 could have a look at previous reviews and see what the common mistakes are.</p></div>\r
1492 </div>\r
1493 <div class="sect2">\r
1494 <h3 id="_which_branch_to_use">20.2. Which branch to use?</h3>\r
1495 <div class="paragraph"><p>Work on i3 generally happens in two branches: “master” and “next”. Since\r
1496 “master” is what people get when they check out the git repository, its\r
1497 contents are always stable. That is, it contains the source code of the latest\r
1498 release, plus any bugfixes that were applied since that release.</p></div>\r
1499 <div class="paragraph"><p>New features are only found in the “next” branch. Therefore, if you are working\r
1500 on a new feature, use the “next” branch. If you are working on a bugfix, use\r
1501 the “next” branch, too, but make sure your code also works on “master”.</p></div>\r
1502 </div>\r
1503 </div>\r
1504 </div>\r
1505 <div class="sect1">\r
1506 <h2 id="_thought_experiments">21. Thought experiments</h2>\r
1507 <div class="sectionbody">\r
1508 <div class="paragraph"><p>In this section, we collect thought experiments, so that we don’t forget our\r
1509 thoughts about specific topics. They are not necessary to get into hacking i3,\r
1510 but if you are interested in one of the topics they cover, you should read them\r
1511 before asking us why things are the way they are or why we don’t implement\r
1512 things.</p></div>\r
1513 <div class="sect2">\r
1514 <h3 id="_using_cgroups_per_workspace">21.1. Using cgroups per workspace</h3>\r
1515 <div class="paragraph"><p>cgroups (control groups) are a linux-only feature which provides the ability to\r
1516 group multiple processes. For each group, you can individually set resource\r
1517 limits, like allowed memory usage. Furthermore, and more importantly for our\r
1518 purposes, they serve as a namespace, a label which you can attach to processes\r
1519 and their children.</p></div>\r
1520 <div class="paragraph"><p>One interesting use for cgroups is having one cgroup per workspace (or\r
1521 container, doesn’t really matter). That way, you could set different priorities\r
1522 and have a workspace for important stuff (say, writing a LaTeX document or\r
1523 programming) and a workspace for unimportant background stuff (say,\r
1524 JDownloader). Both tasks can obviously consume a lot of I/O resources, but in\r
1525 this example it doesn’t really matter if JDownloader unpacks the download a\r
1526 minute earlier or not. However, your compiler should work as fast as possible.\r
1527 Having one cgroup per workspace, you would assign more resources to the\r
1528 programming workspace.</p></div>\r
1529 <div class="paragraph"><p>Another interesting feature is that an inherent problem of the workspace\r
1530 concept could be solved by using cgroups: When starting an application on\r
1531 workspace 1, then switching to workspace 2, you will get the application’s\r
1532 window(s) on workspace 2 instead of the one you started it on. This is because\r
1533 the window manager does not have any mapping between the process it starts (or\r
1534 gets started in any way) and the window(s) which appear.</p></div>\r
1535 <div class="paragraph"><p>Imagine for example using dmenu: The user starts dmenu by pressing Mod+d, dmenu\r
1536 gets started with PID 3390. The user then decides to launch Firefox, which\r
1537 takes a long time. So he enters firefox into dmenu and presses enter. Firefox\r
1538 gets started with PID 4001. When it finally finishes loading, it creates an X11\r
1539 window and uses MapWindow to make it visible. This is the first time i3\r
1540 actually gets in touch with Firefox. It decides to map the window, but it has\r
1541 no way of knowing that this window (even though it has the _NET_WM_PID property\r
1542 set to 4001) belongs to the dmenu the user started before.</p></div>\r
1543 <div class="paragraph"><p>How do cgroups help with this? Well, when pressing Mod+d to launch dmenu, i3\r
1544 would create a new cgroup, let’s call it i3-3390-1. It launches dmenu in that\r
1545 cgroup, which gets PID 3390. As before, the user enters firefox and Firefox\r
1546 gets launched with PID 4001. This time, though, the Firefox process with PID\r
1547 4001 is <strong>also</strong> member of the cgroup i3-3390-1 (because fork()ing in a cgroup\r
1548 retains the cgroup property). Therefore, when mapping the window, i3 can look\r
1549 up in which cgroup the process is and can establish a mapping between the\r
1550 workspace and the window.</p></div>\r
1551 <div class="paragraph"><p>There are multiple problems with this approach:</p></div>\r
1552 <div class="olist arabic"><ol class="arabic">\r
1553 <li>\r
1554 <p>\r
1555 Every application has to properly set <tt>_NET_WM_PID</tt>. This is acceptable and\r
1556   patches can be written for the few applications which don’t set the hint yet.\r
1557 </p>\r
1558 </li>\r
1559 <li>\r
1560 <p>\r
1561 It does only work on Linux, since cgroups are a Linux-only feature. Again,\r
1562   this is acceptable.\r
1563 </p>\r
1564 </li>\r
1565 <li>\r
1566 <p>\r
1567 The main problem is that some applications create X11 windows completely\r
1568   independent of UNIX processes. An example for this is Chromium (or\r
1569   gnome-terminal), which, when being started a second time, communicates with\r
1570   the first process and lets the first process open a new window. Therefore, if\r
1571   you have a Chromium window on workspace 2 and you are currently working on\r
1572   workspace 3, starting <tt>chromium</tt> does not lead to the desired result (the\r
1573   window will open on workspace 2).\r
1574 </p>\r
1575 </li>\r
1576 </ol></div>\r
1577 <div class="paragraph"><p>Therefore, my conclusion is that the only proper way of fixing the "window gets\r
1578 opened on the wrong workspace" problem is in the application itself. Most\r
1579 modern applications support freedesktop startup-notifications  which can be\r
1580 used for this.</p></div>\r
1581 </div>\r
1582 </div>\r
1583 </div>\r
1584 </div>\r
1585 <div id="footnotes"><hr /></div>\r
1586 <div id="footer" lang="de">\r
1587 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>\r
1588 </div>\r
1589 </body>\r
1590 </html>\r