]> git.sur5r.net Git - i3/i3.github.io/blobdiff - docs/hacking-howto.html
add i3 v4.2
[i3/i3.github.io] / docs / hacking-howto.html
index 382b5c3dde62e9a8ce6e790bf47f46e3e0cb2906..afdca82a59e584601ef97d97dcea3e34dadf55f1 100644 (file)
@@ -141,13 +141,19 @@ layout (like dwm, awesome, …) but provide mechanisms for you to easily create
 the layout you need at the moment.</p></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_the_layout_table">1.2. The layout table</h3>\r
-<div class="sidebarblock">\r
-<div class="content">\r
-<div class="paragraph"><p>This section has not been updated for v4.0 yet, sorry! We wanted to release on\r
-time, but we will update this soon. Please talk to us on IRC if you need to\r
-know stuff <strong>NOW</strong> :).</p></div>\r
-</div></div>\r
+<h3 id="_the_layout_tree">1.2. The layout tree</h3>\r
+<div class="paragraph"><p>The data structure which i3 uses to keep track of your windows is a tree. Every\r
+node in the tree is a container (type <tt>Con</tt>). Some containers represent actual\r
+windows (every container with a <tt>window != NULL</tt>), some represent split\r
+containers and a few have special purposes: they represent workspaces, outputs\r
+(like VGA1, LVDS1, …) or the X11 root window.</p></div>\r
+<div class="paragraph"><p>So, when you open a terminal and immediately open another one, they reside in\r
+the same split container, which uses the default layout. In case of an empty\r
+workspace, the split container we are talking about is the workspace.</p></div>\r
+<div class="paragraph"><p>To get an impression of how different layouts are represented, just play around\r
+and look at the data structures&#8201;&#8212;&#8201;they are exposed as a JSON hash. See\r
+<a href="http://i3wm.org/docs/ipc.html#_get_tree_reply">http://i3wm.org/docs/ipc.html#_get_tree_reply</a> for documentation on that and an\r
+example.</p></div>\r
 </div>\r
 </div>\r
 </div>\r
@@ -257,7 +263,7 @@ src/ewmh.c
 </dt>\r
 <dd>\r
 <p>\r
-iFunctions to get/set certain EWMH properties easily.\r
+Functions to get/set certain EWMH properties easily.\r
 </p>\r
 </dd>\r
 <dt class="hdlist1">\r
@@ -455,12 +461,8 @@ Legacy support for Xinerama. See <tt>src/randr.c</tt> for the preferred API.
 <div class="sect1">\r
 <h2 id="_data_structures">3. Data structures</h2>\r
 <div class="sectionbody">\r
-<div class="sidebarblock">\r
-<div class="content">\r
-<div class="paragraph"><p>This section has not been updated for v4.0 yet, sorry! We wanted to release on\r
-time, but we will update this soon. Please talk to us on IRC if you need to\r
-know stuff <strong>NOW</strong> :).</p></div>\r
-</div></div>\r
+<div class="paragraph"><p>See include/data.h for documented data structures. The most important ones are\r
+explained right here.</p></div>\r
 <div class="paragraph"><p>So, the hierarchy is:</p></div>\r
 <div class="olist arabic"><ol class="arabic">\r
 <li>\r
@@ -470,7 +472,7 @@ know stuff <strong>NOW</strong> :).</p></div>
 </li>\r
 <li>\r
 <p>\r
-<strong>Virtual screens</strong> (Screen 0 in this example)\r
+<strong>Output container</strong> (LVDS1 in this example)\r
 </p>\r
 </li>\r
 <li>\r
@@ -496,49 +498,53 @@ know stuff <strong>NOW</strong> :).</p></div>
 </ol></div>\r
 <div class="paragraph"><p>The data type is <tt>Con</tt>, in all cases.</p></div>\r
 <div class="sect2">\r
-<h3 id="_virtual_screens">3.1. Virtual screens</h3>\r
-<div class="paragraph"><p>A virtual screen (type <tt>i3Screen</tt>) is generated from the connected outputs\r
-obtained through RandR. The difference to the raw RandR outputs as seen\r
-when using <tt>xrandr(1)</tt> is that it falls back to the lowest common resolution of\r
-the actual enabled outputs.</p></div>\r
+<h3 id="_x11_root_window">3.1. X11 root window</h3>\r
+<div class="paragraph"><p>The X11 root window is a single window per X11 display (a display is identified\r
+by <tt>:0</tt> or <tt>:1</tt> etc.). The root window is what you draw your background image\r
+on. It spans all the available outputs, e.g. <tt>VGA1</tt> is a specific part of the\r
+root window and <tt>LVDS1</tt> is a specific part of the root window.</p></div>\r
+</div>\r
+<div class="sect2">\r
+<h3 id="_output_container">3.2. Output container</h3>\r
+<div class="paragraph"><p>Every active output obtained through RandR is represented by one output\r
+container. Outputs are considered active when a mode is configured (meaning\r
+something is actually displayed on the output) and the output is not a clone.</p></div>\r
 <div class="paragraph"><p>For example, if your notebook has a screen resolution of 1280x800 px and you\r
 connect a video projector with a resolution of 1024x768 px, set it up in clone\r
-mode (<tt>xrandr --output VGA1 --mode 1024x768 --same-as LVDS1</tt>), i3 will have\r
-one virtual screen.</p></div>\r
+mode (<tt>xrandr --output VGA1 --mode 1024x768 --same-as LVDS1</tt>), i3 will\r
+reduce the resolution to the lowest common resolution and disable one of the\r
+cloned outputs afterwards.</p></div>\r
 <div class="paragraph"><p>However, if you configure it using <tt>xrandr --output VGA1 --mode 1024x768\r
---right-of LVDS1</tt>, i3 will generate two virtual screens. For each virtual\r
-screen, a new workspace will be assigned. New workspaces are created on the\r
-screen you are currently on.</p></div>\r
+--right-of LVDS1</tt>, i3 will set both outputs active. For each output, a new\r
+workspace will be assigned. New workspaces are created on the output you are\r
+currently on.</p></div>\r
+</div>\r
+<div class="sect2">\r
+<h3 id="_content_container">3.3. Content container</h3>\r
+<div class="paragraph"><p>Each output has multiple children. Two of them are dock containers which hold\r
+dock clients. The other one is the content container, which holds the actual\r
+content (workspaces) of this output.</p></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_workspace">3.2. Workspace</h3>\r
+<h3 id="_workspace">3.4. Workspace</h3>\r
 <div class="paragraph"><p>A workspace is identified by its name. Basically, you could think of\r
 workspaces as different desks in your office, if you like the desktop\r
-methaphor. They just contain different sets of windows and are completely\r
+metaphor. They just contain different sets of windows and are completely\r
 separate of each other. Other window managers also call this &#8220;Virtual\r
 desktops&#8221;.</p></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_the_layout_table_2">3.3. The layout table</h3>\r
-<div class="sidebarblock">\r
-<div class="content">\r
-<div class="paragraph"><p>This section has not been updated for v4.0 yet, sorry! We wanted to release on\r
-time, but we will update this soon. Please talk to us on IRC if you need to\r
-know stuff <strong>NOW</strong> :).</p></div>\r
-</div></div>\r
+<h3 id="_split_container">3.5. Split container</h3>\r
+<div class="paragraph"><p>A split container is a container which holds an arbitrary amount of split\r
+containers or X11 window containers. It has an orientation (horizontal or\r
+vertical) and a layout.</p></div>\r
+<div class="paragraph"><p>Split containers (and X11 window containers, which are a subtype of split\r
+containers) can have different border styles.</p></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_container">3.4. Container</h3>\r
-<div class="sidebarblock">\r
-<div class="content">\r
-<div class="paragraph"><p>This section has not been updated for v4.0 yet, sorry! We wanted to release on\r
-time, but we will update this soon. Please talk to us on IRC if you need to\r
-know stuff <strong>NOW</strong> :).</p></div>\r
-</div></div>\r
-</div>\r
-<div class="sect2">\r
-<h3 id="_client">3.5. Client</h3>\r
-<div class="paragraph"><p>A client is x11-speak for a window.</p></div>\r
+<h3 id="_x11_window_container">3.6. X11 window container</h3>\r
+<div class="paragraph"><p>An X11 window container holds exactly one X11 window. These are the leaf nodes\r
+of the layout tree, they cannot have any children.</p></div>\r
 </div>\r
 </div>\r
 </div>\r
@@ -685,8 +691,9 @@ reparented to the bigger one (called "frame").</p></div>
 whether this window is a dock (<tt>_NET_WM_WINDOW_TYPE_DOCK</tt>), like dzen2 for\r
 example. Docks are handled differently, they don’t have decorations and are not\r
 assigned to a specific container. Instead, they are positioned at the bottom\r
-of the screen. To get the height which needs to be reserved for the window,\r
-the <tt>_NET_WM_STRUT_PARTIAL</tt> property is used.</p></div>\r
+or top of the screen (in the appropriate dock area containers). To get the\r
+height which needs to be reserved for the window, the <tt>_NET_WM_STRUT_PARTIAL</tt>\r
+property is used.</p></div>\r
 <div class="paragraph"><p>Furthermore, the list of assignments (to other workspaces, which may be on\r
 other screens) is checked. If the window matches one of the user’s criteria,\r
 it may either be put in floating mode or moved to a different workspace. If the\r
@@ -756,32 +763,491 @@ src/layout.c, function resize_client().</p></div>
 <div class="sect1">\r
 <h2 id="_rendering_src_layout_c_render_layout_and_render_container">14. Rendering (src/layout.c, render_layout() and render_container())</h2>\r
 <div class="sectionbody">\r
-<div class="sidebarblock">\r
-<div class="content">\r
-<div class="paragraph"><p>This section has not been updated for v4.0 yet, sorry! We wanted to release on\r
-time, but we will update this soon. Please talk to us on IRC if you need to\r
-know stuff <strong>NOW</strong> :).</p></div>\r
-</div></div>\r
+<div class="paragraph"><p>Rendering in i3 version 4 is the step which assigns the correct sizes for\r
+borders, decoration windows, child windows and the stacking order of all\r
+windows. In a separate step (<tt>x_push_changes()</tt>), these changes are pushed to\r
+X11.</p></div>\r
+<div class="paragraph"><p>Keep in mind that all these properties (<tt>rect</tt>, <tt>window_rect</tt> and <tt>deco_rect</tt>)\r
+are temporary, meaning they will be overwritten by calling <tt>render_con</tt>.\r
+Persistent position/size information is kept in <tt>geometry</tt>.</p></div>\r
+<div class="paragraph"><p>The entry point for every rendering operation (except for the case of moving\r
+floating windows around) currently is <tt>tree_render()</tt> which will re-render\r
+everything that’s necessary (for every output, only the currently displayed\r
+workspace is rendered). This behavior is expected to change in the future,\r
+since for a lot of updates, re-rendering everything is not actually necessary.\r
+Focus was on getting it working correct, not getting it work very fast.</p></div>\r
+<div class="paragraph"><p>What <tt>tree_render()</tt> actually does is calling <tt>render_con()</tt> on the root\r
+container and then pushing the changes to X11. The following sections talk\r
+about the different rendering steps, in the order of "top of the tree" (root\r
+container) to the bottom.</p></div>\r
+<div class="sect2">\r
+<h3 id="_rendering_the_root_container">14.1. Rendering the root container</h3>\r
+<div class="paragraph"><p>The i3 root container (<tt>con-&gt;type == CT_ROOT</tt>) represents the X11 root window.\r
+It contains one child container for every output (like LVDS1, VGA1, …), which\r
+is available on your computer.</p></div>\r
+<div class="paragraph"><p>Rendering the root will first render all tiling windows and then all floating\r
+windows. This is necessary because a floating window can be positioned in such\r
+a way that it is visible on two different outputs. Therefore, by first\r
+rendering all the tiling windows (of all outputs), we make sure that floating\r
+windows can never be obscured by tiling windows.</p></div>\r
+<div class="paragraph"><p>Essentially, though, this code path will just call <tt>render_con()</tt> for every\r
+output and <tt>x_raise_con(); render_con()</tt> for every floating window.</p></div>\r
+<div class="paragraph"><p>In the special case of having a "global fullscreen" window (fullscreen mode\r
+spanning all outputs), a shortcut is taken and <tt>x_raise_con(); render_con()</tt> is\r
+only called for the global fullscreen window.</p></div>\r
+</div>\r
+<div class="sect2">\r
+<h3 id="_rendering_an_output">14.2. Rendering an output</h3>\r
+<div class="paragraph"><p>Output containers (<tt>con-&gt;layout == L_OUTPUT</tt>) represent a hardware output like\r
+LVDS1, VGA1, etc. An output container has three children (at the moment): One\r
+content container (having workspaces as children) and the top/bottom dock area\r
+containers.</p></div>\r
+<div class="paragraph"><p>The rendering happens in the function <tt>render_l_output()</tt> in the following\r
+steps:</p></div>\r
+<div class="olist arabic"><ol class="arabic">\r
+<li>\r
+<p>\r
+Find the content container (<tt>con-&gt;type == CT_CON</tt>)\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Get the currently visible workspace (<tt>con_get_fullscreen_con(content,\r
+   CF_OUTPUT)</tt>).\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+If there is a fullscreened window on that workspace, directly render it and\r
+   return, thus ignoring the dock areas.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Sum up the space used by all the dock windows (they have a variable height\r
+   only).\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Set the workspace rects (x/y/width/height) based on the position of the\r
+   output (stored in <tt>con-&gt;rect</tt>) and the usable space\r
+   (<tt>con-&gt;rect.{width,height}</tt> without the space used for dock windows).\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Recursively raise and render the output’s child containers (meaning dock\r
+   area containers and the content container).\r
+</p>\r
+</li>\r
+</ol></div>\r
+</div>\r
+<div class="sect2">\r
+<h3 id="_rendering_a_workspace_or_split_container">14.3. Rendering a workspace or split container</h3>\r
+<div class="paragraph"><p>From here on, there really is no difference anymore. All containers are of\r
+<tt>con-&gt;type == CT_CON</tt> (whether workspace or split container) and some of them\r
+have a <tt>con-&gt;window</tt>, meaning they represent an actual window instead of a\r
+split container.</p></div>\r
+<div class="sect3">\r
+<h4 id="_default_layout">14.3.1. Default layout</h4>\r
+<div class="paragraph"><p>In default layout, containers are placed horizontally or vertically next to\r
+each other (depending on the <tt>con-&gt;orientation</tt>). If a child is a leaf node (as\r
+opposed to a split container) and has border style "normal", appropriate space\r
+will be reserved for its window decoration.</p></div>\r
+</div>\r
+<div class="sect3">\r
+<h4 id="_stacked_layout">14.3.2. Stacked layout</h4>\r
+<div class="paragraph"><p>In stacked layout, only the focused window is actually shown (this is achieved\r
+by calling <tt>x_raise_con()</tt> in reverse focus order at the end of <tt>render_con()</tt>).</p></div>\r
+<div class="paragraph"><p>The available space for the focused window is the size of the container minus\r
+the height of the window decoration for all windows inside this stacked\r
+container.</p></div>\r
+<div class="paragraph"><p>If border style is "1pixel" or "none", no window decoration height will be\r
+reserved (or displayed later on), unless there is more than one window inside\r
+the stacked container.</p></div>\r
+</div>\r
+<div class="sect3">\r
+<h4 id="_tabbed_layout">14.3.3. Tabbed layout</h4>\r
+<div class="paragraph"><p>Tabbed layout works precisely like stacked layout, but the window decoration\r
+position/size is different: They are placed next to each other on a single line\r
+(fixed height).</p></div>\r
+</div>\r
+<div class="sect3">\r
+<h4 id="_dock_area_layout">14.3.4. Dock area layout</h4>\r
+<div class="paragraph"><p>This is a special case. Users cannot chose the dock area layout, but it will be\r
+set for the dock area containers. In the dockarea layout (at the moment!),\r
+windows will be placed above each other.</p></div>\r
+</div>\r
+</div>\r
+<div class="sect2">\r
+<h3 id="_rendering_a_window">14.4. Rendering a window</h3>\r
+<div class="paragraph"><p>A window’s size and position will be determined in the following way:</p></div>\r
+<div class="olist arabic"><ol class="arabic">\r
+<li>\r
+<p>\r
+Subtract the border if border style is not "none" (but "normal" or "1pixel").\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Subtract the X11 border, if the window has an X11 border &gt; 0.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Obey the aspect ratio of the window (think MPlayer).\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Obey the height- and width-increments of the window (think terminal emulator\r
+   which can only be resized in one-line or one-character steps).\r
+</p>\r
+</li>\r
+</ol></div>\r
+</div>\r
 </div>\r
 </div>\r
 <div class="sect1">\r
-<h2 id="_user_commands_commandmode_src_cmdparse_l_y">15. User commands / commandmode (src/cmdparse.{l,y})</h2>\r
+<h2 id="_pushing_updates_to_x11_drawing">15. Pushing updates to X11 / Drawing</h2>\r
 <div class="sectionbody">\r
-<div class="sidebarblock">\r
+<div class="paragraph"><p>A big problem with i3 before version 4 was that we just sent requests to X11\r
+anywhere in the source code. This was bad because nobody could understand the\r
+entirety of our interaction with X11, it lead to subtle bugs and a lot of edge\r
+cases which we had to consider all over again.</p></div>\r
+<div class="paragraph"><p>Therefore, since version 4, we have a single file, <tt>src/x.c</tt>, which is\r
+responsible for repeatedly transferring parts of our tree datastructure to X11.</p></div>\r
+<div class="paragraph"><p><tt>src/x.c</tt> consists of multiple parts:</p></div>\r
+<div class="olist arabic"><ol class="arabic">\r
+<li>\r
+<p>\r
+The state pushing: <tt>x_push_changes()</tt>, which calls <tt>x_push_node()</tt>.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+State modification functions: <tt>x_con_init</tt>, <tt>x_reinit</tt>,\r
+   <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
+   and <tt>x_set_warp_to</tt>.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Expose event handling (drawing decorations): <tt>x_deco_recurse()</tt> and\r
+   <tt>x_draw_decoration()</tt>.\r
+</p>\r
+</li>\r
+</ol></div>\r
+<div class="sect2">\r
+<h3 id="_pushing_state_to_x11">15.1. Pushing state to X11</h3>\r
+<div class="paragraph"><p>In general, the function <tt>x_push_changes</tt> should be called to push state\r
+changes. Only when the scope of the state change is clearly defined (for\r
+example only the title of a window) and its impact is known beforehand, one can\r
+optimize this and call <tt>x_push_node</tt> on the appropriate con directly.</p></div>\r
+<div class="paragraph"><p><tt>x_push_changes</tt> works in the following steps:</p></div>\r
+<div class="olist arabic"><ol class="arabic">\r
+<li>\r
+<p>\r
+Clear the eventmask for all mapped windows. This leads to not getting\r
+   useless ConfigureNotify or EnterNotify events which are caused by our\r
+   requests. In general, we only want to handle user input.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Stack windows above each other, in reverse stack order (starting with the\r
+   most obscured/bottom window). This is relevant for floating windows which\r
+   can overlap each other, but also for tiling windows in stacked or tabbed\r
+   containers. We also update the <tt>_NET_CLIENT_LIST_STACKING</tt> hint which is\r
+   necessary for tab drag and drop in Chromium.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+<tt>x_push_node</tt> will be called for the root container, recursively calling\r
+   itself for the container’s children. This function actually pushes the\r
+   state, see the next paragraph.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+If the pointer needs to be warped to a different position (for example when\r
+   changing focus to a differnt output), it will be warped now.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+The eventmask is restored for all mapped windows.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Window decorations will be rendered by calling <tt>x_deco_recurse</tt> on the root\r
+   container, which then recursively calls itself for the children.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+If the input focus needs to be changed (because the user focused a different\r
+   window), it will be updated now.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+<tt>x_push_node_unmaps</tt> will be called for the root container. This function\r
+   only pushes UnmapWindow requests. Separating the state pushing is necessary\r
+   to handle fullscreen windows (and workspace switches) in a smooth fashion:\r
+   The newly visible windows should be visible before the old windows are\r
+   unmapped.\r
+</p>\r
+</li>\r
+</ol></div>\r
+<div class="paragraph"><p><tt>x_push_node</tt> works in the following steps:</p></div>\r
+<div class="olist arabic"><ol class="arabic">\r
+<li>\r
+<p>\r
+Update the window’s <tt>WM_NAME</tt>, if changed (the <tt>WM_NAME</tt> is set on i3\r
+   containers mainly for debugging purposes).\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Reparents a child window into the i3 container if the container was created\r
+   for a specific managed window.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+If the size/position of the i3 container changed (due to opening a new\r
+   window or switching layouts for example), the window will be reconfigured.\r
+   Also, the pixmap which is used to draw the window decoration/border on is\r
+   reconfigured (pixmaps are size-dependent).\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Size/position for the child window is adjusted.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+The i3 container is mapped if it should be visible and was not yet mapped.\r
+   When mapping, <tt>WM_STATE</tt> is set to <tt>WM_STATE_NORMAL</tt>. Also, the eventmask of\r
+   the child window is updated and the i3 container’s contents are copied from\r
+   the pixmap.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+<tt>x_push_node</tt> is called recursively for all children of the current\r
+   container.\r
+</p>\r
+</li>\r
+</ol></div>\r
+<div class="paragraph"><p><tt>x_push_node_unmaps</tt> handles the remaining case of an i3 container being\r
+unmapped if it should not be visible anymore. <tt>WM_STATE</tt> will be set to\r
+<tt>WM_STATE_WITHDRAWN</tt>.</p></div>\r
+</div>\r
+<div class="sect2">\r
+<h3 id="_drawing_window_decorations_borders_backgrounds">15.2. Drawing window decorations/borders/backgrounds</h3>\r
+<div class="paragraph"><p><tt>x_draw_decoration</tt> draws window decorations. It is run for every leaf\r
+container (representing an actual X11 window) and for every non-leaf container\r
+which is in a stacked/tabbed container (because stacked/tabbed containers\r
+display a window decoration for split containers, which at the moment just says\r
+"another container").</p></div>\r
+<div class="paragraph"><p>Then, parameters are collected to be able to determine whether this decoration\r
+drawing is actually necessary or was already done. This saves a substantial\r
+number of redraws (depending on your workload, but far over 50%).</p></div>\r
+<div class="paragraph"><p>Assuming that we need to draw this decoration, we start by filling the empty\r
+space around the child window (think of MPlayer with a specific aspect ratio)\r
+in the user-configured client background color.</p></div>\r
+<div class="paragraph"><p>Afterwards, we draw the appropriate border (in case of border styles "normal"\r
+and "1pixel") and the top bar (in case of border style "normal").</p></div>\r
+<div class="paragraph"><p>The last step is drawing the window title on the top bar.</p></div>\r
+</div>\r
+</div>\r
+</div>\r
+<div class="sect1">\r
+<h2 id="_user_commands_parser_specs_commands_spec">16. User commands (parser-specs/commands.spec)</h2>\r
+<div class="sectionbody">\r
+<div class="paragraph"><p>In the configuration file and when using i3 interactively (with <tt>i3-msg</tt>, for\r
+example), you use commands to make i3 do things, like focus a different window,\r
+set a window to fullscreen, and so on. An example command is <tt>floating enable</tt>,\r
+which enables floating mode for the currently focused window. See the\r
+appropriate section in the <a href="userguide.html">User’s Guide</a> for a reference of\r
+all commands.</p></div>\r
+<div class="paragraph"><p>In earlier versions of i3, interpreting these commands was done using lex and\r
+yacc, but experience has shown that lex and yacc are not well suited for our\r
+command language. Therefore, starting from version 4.2, we use a custom parser\r
+for user commands (not yet for the configuration file).\r
+The input specification for this parser can be found in the file\r
+<tt>parser-specs/commands.spec</tt>. Should you happen to use Vim as an editor, use\r
+:source parser-specs/highlighting.vim to get syntax highlighting for this file\r
+(highlighting files for other editors are welcome).</p></div>\r
+<div class="listingblock">\r
+<div class="title">Excerpt from commands.spec</div>\r
 <div class="content">\r
-<div class="paragraph"><p>This section has not been updated for v4.0 yet, sorry! We wanted to release on\r
-time, but we will update this soon. Please talk to us on IRC if you need to\r
-know stuff <strong>NOW</strong> :).</p></div>\r
+<pre><tt>state INITIAL:\r
+  '[' -&gt; call cmd_criteria_init(); CRITERIA\r
+  'move' -&gt; MOVE\r
+  'exec' -&gt; EXEC\r
+  'workspace' -&gt; WORKSPACE\r
+  'exit' -&gt; call cmd_exit()\r
+  'restart' -&gt; call cmd_restart()\r
+  'reload' -&gt; call cmd_reload()</tt></pre>\r
 </div></div>\r
+<div class="paragraph"><p>The input specification is written in an extremely simple format. The\r
+specification is then converted into C code by the Perl script\r
+generate-commands-parser.pl (the output file names begin with GENERATED and the\r
+files are stored in the <tt>include</tt> directory). The parser implementation\r
+<tt>src/commands_parser.c</tt> includes the generated C code at compile-time.</p></div>\r
+<div class="paragraph"><p>The above excerpt from commands.spec illustrates nearly all features of our\r
+specification format: You describe different states and what can happen within\r
+each state. State names are all-caps; the state in the above excerpt is called\r
+INITIAL. A list of tokens and their actions (separated by an ASCII arrow)\r
+follows. In the excerpt, all tokens are literals, that is, simple text strings\r
+which will be compared with the input. An action is either the name of a state\r
+in which the parser will transition into, or the keyword <em>call</em>, followed by\r
+the name of a function (and optionally a state).</p></div>\r
+<div class="sect2">\r
+<h3 id="_example_the_workspace_state">16.1. Example: The WORKSPACE state</h3>\r
+<div class="paragraph"><p>Let’s have a look at the WORKSPACE state, which is a good example of all\r
+features. This is its definition:</p></div>\r
+<div class="listingblock">\r
+<div class="title">WORKSPACE state (commands.spec)</div>\r
+<div class="content">\r
+<pre><tt># workspace next|prev|next_on_output|prev_on_output\r
+# workspace back_and_forth\r
+# workspace &lt;name&gt;\r
+state WORKSPACE:\r
+  direction = 'next_on_output', 'prev_on_output', 'next', 'prev'\r
+      -&gt; call cmd_workspace($direction)\r
+  'back_and_forth'\r
+      -&gt; call cmd_workspace_back_and_forth()\r
+  workspace = string\r
+      -&gt; call cmd_workspace_name($workspace)</tt></pre>\r
+</div></div>\r
+<div class="paragraph"><p>As you can see from the commands, there are multiple different valid variants\r
+of the workspace command:</p></div>\r
+<div class="dlist"><dl>\r
+<dt class="hdlist1">\r
+workspace &lt;direction&gt;\r
+</dt>\r
+<dd>\r
+<p>\r
+        The word <em>workspace</em> can be followed by any of the tokens <em>next</em>,\r
+        <em>prev</em>, <em>next_on_output</em> or <em>prev_on_output</em>. This command will\r
+        switch to the next or previous workspace (optionally on the same\r
+        output).<br />\r
+        There is one function called <tt>cmd_workspace</tt>, which is defined\r
+        in <tt>src/commands.c</tt>. It will handle this kind of command. To know which\r
+        direction was specified, the direction token is stored on the stack\r
+        with the name "direction", which is what the "direction = " means in\r
+        the beginning.<br />\r
+</p>\r
+</dd>\r
+</dl></div>\r
+<div class="admonitionblock">\r
+<table><tr>\r
+<td class="icon">\r
+<div class="title">Note</div>\r
+</td>\r
+<td class="content">Note that you can specify multiple literals in the same line. This has\r
+        exactly the same effect as if you specified <tt>direction =\r
+        'next_on_output' -&gt; call cmd_workspace($direction)</tt> and so forth.<br /></td>\r
+</tr></table>\r
+</div>\r
+<div class="admonitionblock">\r
+<table><tr>\r
+<td class="icon">\r
+<div class="title">Note</div>\r
+</td>\r
+<td class="content">Also note that the order of literals is important here: If <em>next</em> were\r
+        ordered before <em>next_on_output</em>, then <em>next_on_output</em> would never\r
+        match.</td>\r
+</tr></table>\r
+</div>\r
+<div class="dlist"><dl>\r
+<dt class="hdlist1">\r
+workspace back_and_forth\r
+</dt>\r
+<dd>\r
+<p>\r
+        This is a very simple case: When the literal <em>back_and_forth</em> is found\r
+        in the input, the function <tt>cmd_workspace_back_and_forth</tt> will be\r
+        called without parameters and the parser will return to the INITIAL\r
+        state (since no other state was specified).\r
+</p>\r
+</dd>\r
+<dt class="hdlist1">\r
+workspace &lt;name&gt;\r
+</dt>\r
+<dd>\r
+<p>\r
+        In this case, the workspace command is followed by an arbitrary string,\r
+        possibly in quotes, for example "workspace 3" or "workspace bleh".<br />\r
+        This is the first time that the token is actually not a literal (not in\r
+        single quotes), but just called string. Other possible tokens are word\r
+        (the same as string, but stops matching at a whitespace) and end\r
+        (matches the end of the input).\r
+</p>\r
+</dd>\r
+</dl></div>\r
+</div>\r
+<div class="sect2">\r
+<h3 id="_introducing_a_new_command">16.2. Introducing a new command</h3>\r
+<div class="paragraph"><p>The following steps have to be taken in order to properly introduce a new\r
+command (or possibly extend an existing command):</p></div>\r
+<div class="olist arabic"><ol class="arabic">\r
+<li>\r
+<p>\r
+Define a function beginning with <tt>cmd_</tt> in the file <tt>src/commands.c</tt>. Copy\r
+   the prototype of an existing function.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+After adding a comment on what the function does, copy the comment and\r
+   function definition to <tt>include/commands.h</tt>. Make the comment in the header\r
+   file use double asterisks to make doxygen pick it up.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Write a test case (or extend an existing test case) for your feature, see\r
+   <a href="testsuite.html">i3 testsuite</a>. For now, it is sufficient to simply call\r
+   your command in all the various possible ways.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Extend the parser specification in <tt>parser-specs/commands.spec</tt>. Run the\r
+   testsuite and see if your new function gets called with the appropriate\r
+   arguments for the appropriate input.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Actually implement the feature.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Document the feature in the <a href="userguide.html">User’s Guide</a>.\r
+</p>\r
+</li>\r
+</ol></div>\r
+</div>\r
 </div>\r
 </div>\r
 <div class="sect1">\r
-<h2 id="_moving_containers">16. Moving containers</h2>\r
+<h2 id="_moving_containers">17. Moving containers</h2>\r
 <div class="sectionbody">\r
 <div class="paragraph"><p>The movement code is pretty delicate. You need to consider all cases before\r
 making any changes or before being able to fully understand how it works.</p></div>\r
 <div class="sect2">\r
-<h3 id="_case_1_moving_inside_the_same_container">16.1. Case 1: Moving inside the same container</h3>\r
+<h3 id="_case_1_moving_inside_the_same_container">17.1. Case 1: Moving inside the same container</h3>\r
 <div class="paragraph"><p>The reference layout for this case is a single workspace in horizontal\r
 orientation with two containers on it. Focus is on the left container (1).</p></div>\r
 <div class="tableblock">\r
@@ -806,7 +1272,7 @@ commented with "the easy case": it calls TAILQ_NEXT to get the container right
 of the current one and swaps both containers.</p></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_case_2_move_a_container_into_a_split_container">16.2. Case 2: Move a container into a split container</h3>\r
+<h3 id="_case_2_move_a_container_into_a_split_container">17.2. Case 2: Move a container into a split container</h3>\r
 <div class="paragraph"><p>The reference layout for this case is a horizontal workspace with two\r
 containers. The right container is a v-split with two containers. Focus is on\r
 the left container (1).</p></div>\r
@@ -840,7 +1306,7 @@ empty.</p></div>
 be flattened.</p></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_case_3_moving_to_non_existant_top_bottom">16.3. Case 3: Moving to non-existant top/bottom</h3>\r
+<h3 id="_case_3_moving_to_non_existant_top_bottom">17.3. Case 3: Moving to non-existant top/bottom</h3>\r
 <div class="paragraph"><p>Like in case 1, the reference layout for this case is a single workspace in\r
 horizontal orientation with two containers on it. Focus is on the left\r
 container:</p></div>\r
@@ -874,7 +1340,7 @@ container and the container above/below the current one (on the level of
 flattened.</p></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_case_4_moving_to_existant_top_bottom">16.4. Case 4: Moving to existant top/bottom</h3>\r
+<h3 id="_case_4_moving_to_existant_top_bottom">17.4. Case 4: Moving to existant top/bottom</h3>\r
 <div class="paragraph"><p>The reference layout for this case is a vertical workspace with two containers.\r
 The bottom one is a h-split containing two containers (1 and 2). Focus is on\r
 the bottom left container (1).</p></div>\r
@@ -901,7 +1367,7 @@ orientation change does not need to be performed because the workspace already
 is in vertical orientation.</p></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_case_5_moving_in_one_child_h_split">16.5. Case 5: Moving in one-child h-split</h3>\r
+<h3 id="_case_5_moving_in_one_child_h_split">17.5. Case 5: Moving in one-child h-split</h3>\r
 <div class="paragraph"><p>The reference layout for this case is a horizontal workspace with two\r
 containers having a v-split on the left side with a one-child h-split on the\r
 bottom. Focus is on the bottom left container (2(h)):</p></div>\r
@@ -933,7 +1399,7 @@ orientation will be force-changed), this case is equivalent to case 2 or case
 4.</p></div>\r
 </div>\r
 <div class="sect2">\r
-<h3 id="_case_6_floating_containers">16.6. Case 6: Floating containers</h3>\r
+<h3 id="_case_6_floating_containers">17.6. Case 6: Floating containers</h3>\r
 <div class="paragraph"><p>The reference layout for this case is a horizontal workspace with two\r
 containers plus one floating h-split container. Focus is on the floating\r
 container.</p></div>\r
@@ -945,7 +1411,7 @@ by calling the function <tt>attach_to_workspace</tt>.</p></div>
 </div>\r
 </div>\r
 <div class="sect1">\r
-<h2 id="_click_handling">17. Click handling</h2>\r
+<h2 id="_click_handling">18. Click handling</h2>\r
 <div class="sectionbody">\r
 <div class="paragraph"><p>Without much ado, here is the list of cases which need to be considered:</p></div>\r
 <div class="ulist"><ul>\r
@@ -995,7 +1461,7 @@ click on border/decoration to resize a tiling con
 </div>\r
 </div>\r
 <div class="sect1">\r
-<h2 id="_gotchas">18. Gotchas</h2>\r
+<h2 id="_gotchas">19. Gotchas</h2>\r
 <div class="sectionbody">\r
 <div class="ulist"><ul>\r
 <li>\r
@@ -1005,11 +1471,19 @@ Forgetting to call <tt>xcb_flush(conn);</tt> after sending a request. This usual
   certain conditions.\r
 </p>\r
 </li>\r
+<li>\r
+<p>\r
+Forgetting to call <tt>floating_fix_coordinates(con, old_rect, new_rect)</tt> after\r
+  moving workspaces across outputs. Coordinates for floating containers are\r
+  not relative to workspace boundaries, so you must correct their coordinates\r
+  or those containers will show up in the wrong workspace or not at all.\r
+</p>\r
+</li>\r
 </ul></div>\r
 </div>\r
 </div>\r
 <div class="sect1">\r
-<h2 id="_using_git_sending_patches">19. Using git / sending patches</h2>\r
+<h2 id="_using_git_sending_patches">20. Using git / sending patches</h2>\r
 <div class="sectionbody">\r
 <div class="paragraph"><p>For a short introduction into using git, see\r
 <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
@@ -1037,6 +1511,85 @@ apply to the branch, preserving your commit message and name:</p></div>
 <div class="paragraph"><p>Just send us the generated file via email.</p></div>\r
 </div>\r
 </div>\r
+<div class="sect1">\r
+<h2 id="_thought_experiments">21. Thought experiments</h2>\r
+<div class="sectionbody">\r
+<div class="paragraph"><p>In this section, we collect thought experiments, so that we don’t forget our\r
+thoughts about specific topics. They are not necessary to get into hacking i3,\r
+but if you are interested in one of the topics they cover, you should read them\r
+before asking us why things are the way they are or why we don’t implement\r
+things.</p></div>\r
+<div class="sect2">\r
+<h3 id="_using_cgroups_per_workspace">21.1. Using cgroups per workspace</h3>\r
+<div class="paragraph"><p>cgroups (control groups) are a linux-only feature which provides the ability to\r
+group multiple processes. For each group, you can individually set resource\r
+limits, like allowed memory usage. Furthermore, and more importantly for our\r
+purposes, they serve as a namespace, a label which you can attach to processes\r
+and their children.</p></div>\r
+<div class="paragraph"><p>One interesting use for cgroups is having one cgroup per workspace (or\r
+container, doesn’t really matter). That way, you could set different priorities\r
+and have a workspace for important stuff (say, writing a LaTeX document or\r
+programming) and a workspace for unimportant background stuff (say,\r
+JDownloader). Both tasks can obviously consume a lot of I/O resources, but in\r
+this example it doesn’t really matter if JDownloader unpacks the download a\r
+minute earlier or not. However, your compiler should work as fast as possible.\r
+Having one cgroup per workspace, you would assign more resources to the\r
+programming workspace.</p></div>\r
+<div class="paragraph"><p>Another interesting feature is that an inherent problem of the workspace\r
+concept could be solved by using cgroups: When starting an application on\r
+workspace 1, then switching to workspace 2, you will get the application’s\r
+window(s) on workspace 2 instead of the one you started it on. This is because\r
+the window manager does not have any mapping between the process it starts (or\r
+gets started in any way) and the window(s) which appear.</p></div>\r
+<div class="paragraph"><p>Imagine for example using dmenu: The user starts dmenu by pressing Mod+d, dmenu\r
+gets started with PID 3390. The user then decides to launch Firefox, which\r
+takes a long time. So he enters firefox into dmenu and presses enter. Firefox\r
+gets started with PID 4001. When it finally finishes loading, it creates an X11\r
+window and uses MapWindow to make it visible. This is the first time i3\r
+actually gets in touch with Firefox. It decides to map the window, but it has\r
+no way of knowing that this window (even though it has the _NET_WM_PID property\r
+set to 4001) belongs to the dmenu the user started before.</p></div>\r
+<div class="paragraph"><p>How do cgroups help with this? Well, when pressing Mod+d to launch dmenu, i3\r
+would create a new cgroup, let’s call it i3-3390-1. It launches dmenu in that\r
+cgroup, which gets PID 3390. As before, the user enters firefox and Firefox\r
+gets launched with PID 4001. This time, though, the Firefox process with PID\r
+4001 is <strong>also</strong> member of the cgroup i3-3390-1 (because fork()ing in a cgroup\r
+retains the cgroup property). Therefore, when mapping the window, i3 can look\r
+up in which cgroup the process is and can establish a mapping between the\r
+workspace and the window.</p></div>\r
+<div class="paragraph"><p>There are multiple problems with this approach:</p></div>\r
+<div class="olist arabic"><ol class="arabic">\r
+<li>\r
+<p>\r
+Every application has to properly set <tt>_NET_WM_PID</tt>. This is acceptable and\r
+  patches can be written for the few applications which don’t set the hint yet.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+It does only work on Linux, since cgroups are a Linux-only feature. Again,\r
+  this is acceptable.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+The main problem is that some applications create X11 windows completely\r
+  independent of UNIX processes. An example for this is Chromium (or\r
+  gnome-terminal), which, when being started a second time, communicates with\r
+  the first process and lets the first process open a new window. Therefore, if\r
+  you have a Chromium window on workspace 2 and you are currently working on\r
+  workspace 3, starting <tt>chromium</tt> does not lead to the desired result (the\r
+  window will open on workspace 2).\r
+</p>\r
+</li>\r
+</ol></div>\r
+<div class="paragraph"><p>Therefore, my conclusion is that the only proper way of fixing the "window gets\r
+opened on the wrong workspace" problem is in the application itself. Most\r
+modern applications support freedesktop startup-notifications  which can be\r
+used for this.</p></div>\r
+</div>\r
+</div>\r
+</div>\r
 </div>\r
 <div id="footnotes"><hr /></div>\r
 <div id="footer" lang="de">\r