]> git.sur5r.net Git - i3/i3.github.io/blob - docs/4.13/layout-saving.html
save docs for 4.13
[i3/i3.github.io] / docs / 4.13 / layout-saving.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/x-icon" href="/favicon.ico">\r
6 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />\r
7 <meta name="generator" content="AsciiDoc 8.6.9" />\r
8 <title>i3: Layout saving in i3</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 document.addEventListener("DOMContentLoaded", function(){asciidoc.footnotes(); asciidoc.toc(2);}, false);\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="https://www.reddit.com/r/i3wm/">FAQ</a></li>\r
26                                 <li><a href="/contact">Contact</a></li>\r
27                                 <li><a href="https://github.com/i3/i3/issues">Bugs</a></li>\r
28                         </ul>\r
29         <br style="clear: both">\r
30 <div id="content">\r
31 <div id="header">\r
32 <h1>Layout saving in i3</h1>\r
33 <span id="author">Michael Stapelberg</span><br />\r
34 <span id="email"><tt>&lt;<a href="mailto:michael@i3wm.org">michael@i3wm.org</a>&gt;</tt></span><br />\r
35 <span id="revdate">April 2014</span>\r
36 <div id="toc">
37   <div id="toctitle">Table of Contents</div>
38   <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
39 </div>\r
40 </div>\r
41 <div id="preamble">\r
42 <div class="sectionbody">\r
43 <div class="paragraph"><p>Layout saving/restoring is a feature that was introduced in i3 v4.8.</p></div>\r
44 <div class="paragraph"><p>Layout saving/restoring allows you to load a JSON layout file so that you can\r
45 have a base layout to start working with after powering on your computer.\r
46 Dynamic use-cases also come to mind: if you frequently (but not always!) need a\r
47 grid layout of terminals with ping/traceroute commands to diagnose network\r
48 issues, you can easily automate opening these windows in just the right layout.</p></div>\r
49 </div>\r
50 </div>\r
51 <div class="sect1">\r
52 <h2 id="_saving_the_layout">1. Saving the layout</h2>\r
53 <div class="sectionbody">\r
54 <div class="paragraph"><p>You can save the layout of either a single workspace or an entire output (e.g.\r
55 LVDS1). Of course, you can repeat this step multiple times if you want to\r
56 save/restore multiple workspaces/outputs.</p></div>\r
57 <div class="paragraph"><p><tt>i3-save-tree(1)</tt> is a tool to save the layout. It will print a JSON\r
58 representation of i3’s internal layout data structures to stdout. Typically,\r
59 you may want to take a quick look at the output, then save it to a file and\r
60 tweak it a little bit:</p></div>\r
61 <div class="listingblock">\r
62 <div class="content">\r
63 <pre><tt>i3-save-tree --workspace 1 &gt; ~/.i3/workspace-1.json</tt></pre>\r
64 </div></div>\r
65 <div class="paragraph"><p>Please note that the output of <tt>i3-save-tree(1)</tt> is <strong>NOT useful</strong> until you\r
66 manually modify it — you need to tell i3 how to match/distinguish windows (for\r
67 example based on their WM_CLASS, title, etc.). By default, all the different\r
68 window properties are included in the output, but commented out. This is partly\r
69 to avoid relying on heuristics and partly to make you aware how i3 works so\r
70 that you can easily solve layout restoring problems.</p></div>\r
71 <div class="paragraph"><p>How to modify the file manually is described in <a href="#EditingLayoutFiles">[EditingLayoutFiles]</a>.</p></div>\r
72 </div>\r
73 </div>\r
74 <div class="sect1">\r
75 <h2 id="_restoring_the_layout">2. Restoring the layout</h2>\r
76 <div class="sectionbody">\r
77 <div class="paragraph"><p>After restoring the example layout from <a href="#EditingLayoutFiles">[EditingLayoutFiles]</a>, i3 will open\r
78 placeholder windows for all the windows that were specified in the layout file.\r
79 You can recognize the placeholder windows by the watch symbol\r
80 <span class="footnote"><br />[Depending on the font you are using, a placeholder symbol may show up\r
81 instead of the watch symbol.]<br /></span> in the center of the window, and by the swallow\r
82 criteria specification at the top of the window:</p></div>\r
83 <div class="paragraph"><p><span class="image">\r
84 <a class="image" href="layout-saving-1.png">\r
85 <img src="layout-saving-1.png" alt="Restored layout" width="400" />\r
86 </a>\r
87 </span></p></div>\r
88 <div class="paragraph"><p>When an application opens a window that matches the specified swallow criteria,\r
89 it will be placed in the corresponding placeholder window. We say it gets\r
90 <strong>swallowed</strong> by the placeholder container, hence the term.</p></div>\r
91 <div class="paragraph"><p>Note: Swallowing windows into unsatisfied placeholder windows takes precedence\r
92 over\r
93 <a href="http://i3wm.org/docs/userguide.html#_automatically_putting_clients_on_specific_workspaces">assignment\r
94 rules</a>. For example, if you assign all Emacs windows to workspace 1 in your i3\r
95 configuration file, but there is a placeholder window on workspace 2 which\r
96 matches Emacs as well, your newly started Emacs window will end up in the\r
97 placeholder window on workspace 2.</p></div>\r
98 <div class="paragraph"><p>The placeholder windows are just regular windows, so feel free to move them\r
99 around or close them, for example.</p></div>\r
100 <div class="sect2">\r
101 <h3 id="_append_layout_command">2.1. append_layout command</h3>\r
102 <div class="paragraph"><p>The <tt>append_layout</tt> command is used to load a layout file into i3. It accepts a\r
103 path (relative to i3’s current working directory or absolute) to a JSON file.</p></div>\r
104 <div class="paragraph"><p><strong>Syntax</strong>:</p></div>\r
105 <div class="listingblock">\r
106 <div class="content">\r
107 <pre><tt>append_layout &lt;path&gt;</tt></pre>\r
108 </div></div>\r
109 <div class="paragraph"><p><strong>Examples</strong>:</p></div>\r
110 <div class="listingblock">\r
111 <div class="content">\r
112 <pre><tt># From a terminal or script:\r
113 i3-msg "workspace 1; append_layout /home/michael/.i3/workspace-1.json"\r
114 \r
115 # In your i3 configuration file, you can autostart i3-msg like this:\r
116 # (Note that those lines will quickly become long, so typically you would store\r
117 #  them in a script with proper indentation.)\r
118 exec --no-startup-id "i3-msg 'workspace 1; append_layout /home/michael/.i3/workspace-1.json'"</tt></pre>\r
119 </div></div>\r
120 </div>\r
121 </div>\r
122 </div>\r
123 <div class="sect1">\r
124 <h2 id="_editing_layout_files">3. Editing layout files</h2>\r
125 <div class="sectionbody">\r
126 <div class="sect2">\r
127 <h3 id="EditingLayoutFiles">3.1. Anatomy of a layout file</h3>\r
128 <div class="paragraph"><p>Here is an example layout file that we’ll discuss:</p></div>\r
129 <div class="listingblock">\r
130 <div class="content">\r
131 <pre><tt>{\r
132     // splitv split container with 2 children\r
133     "layout": "splitv",\r
134     "percent": 0.4,\r
135     "type": "con",\r
136     "nodes": [\r
137         {\r
138             "border": "none",\r
139             "name": "irssi",\r
140             "percent": 0.5,\r
141             "type": "con",\r
142             "swallows": [\r
143                 {\r
144                     "class": "^URxvt$",\r
145                     "instance": "^irssi$"\r
146                 }\r
147             ]\r
148         },\r
149         {\r
150             // stacked split container with 2 children\r
151             "layout": "stacked",\r
152             "percent": 0.5,\r
153             "type": "con",\r
154             "nodes": [\r
155                 {\r
156                     "name": "notmuch",\r
157                     "percent": 0.5,\r
158                     "type": "con",\r
159                     "swallows": [\r
160                         {\r
161                             "class": "^Emacs$",\r
162                             "instance": "^notmuch$"\r
163                         }\r
164                     ]\r
165                 },\r
166                 {\r
167                     "name": "midna: ~",\r
168                     "percent": 0.5,\r
169                     "type": "con"\r
170                 }\r
171             ]\r
172         }\r
173     ]\r
174 }\r
175 \r
176 {\r
177     // stacked split container with 1 children\r
178     "layout": "stacked",\r
179     "percent": 0.6,\r
180     "type": "con",\r
181     "nodes": [\r
182         {\r
183             "name": "chrome",\r
184             "type": "con",\r
185             "swallows": [\r
186                 {\r
187                     "class": "^Google-chrome$"\r
188                 }\r
189             ]\r
190         }\r
191     ]\r
192 }</tt></pre>\r
193 </div></div>\r
194 <div class="paragraph"><p>In this layout, the screen is divided into two columns. In the left column,\r
195 which covers 40% of the screen, there is a terminal emulator running irssi on\r
196 the top, and a stacked split container with an Emacs window and a terminal\r
197 emulator on the bottom. In the right column, there is a stacked container with\r
198 a Chrome window:</p></div>\r
199 <div class="paragraph"><p><span class="image">\r
200 <a class="image" href="layout-saving-1.png">\r
201 <img src="layout-saving-1.png" alt="Restored layout" width="400" />\r
202 </a>\r
203 </span></p></div>\r
204 <div class="paragraph"><p>The structure of this JSON file looks a lot like the <tt>TREE</tt> reply, see\r
205 <a href="http://build.i3wm.org/docs/ipc.html#_tree_reply">http://build.i3wm.org/docs/ipc.html#_tree_reply</a> for documentation on that. Some\r
206 properties are excluded because they are not relevant when restoring a layout.</p></div>\r
207 <div class="paragraph"><p>Most importantly, look at the "swallows" section of each window. This is where\r
208 you need to be more or less specific. As an example, remember the section about\r
209 the Emacs window:</p></div>\r
210 <div class="listingblock">\r
211 <div class="content">\r
212 <pre><tt>"swallows": [\r
213     {\r
214         "class": "^Emacs$",\r
215         "instance": "^notmuch$"\r
216     }\r
217 ]</tt></pre>\r
218 </div></div>\r
219 <div class="paragraph"><p>Here you can see that i3 will require both the class and the instance to match.\r
220 Therefore, if you just start Emacs via dmenu, it will not get swallowed by that\r
221 container. Only if you start Emacs with the proper instance name (<tt>emacs24\r
222 --name notmuch</tt>), it will get swallowed.</p></div>\r
223 <div class="paragraph"><p>You can match on "class", "instance", "window_role" and "title". All values are\r
224 case-sensitive regular expressions (PCRE). Use <tt>xprop(1)</tt> and click into a\r
225 window to see its properties:</p></div>\r
226 <div class="listingblock">\r
227 <div class="content">\r
228 <pre><tt>$ xprop\r
229 WM_WINDOW_ROLE(STRING) = "gimp-toolbox-color-dialog"\r
230 WM_CLASS(STRING) = "gimp-2.8", "Gimp-2.8"\r
231 _NET_WM_NAME(UTF8_STRING) = "Change Foreground Color"</tt></pre>\r
232 </div></div>\r
233 <div class="paragraph"><p>The first part of <tt>WM_CLASS</tt> is the "instance" (gimp-2.8 in this case), the\r
234 second part is the "class" (Gimp-2.8 in this case). "title" matches against\r
235 <tt>_NET_WM_NAME</tt> and "window_role" matches against <tt>WM_WINDOW_ROLE</tt>.</p></div>\r
236 <div class="paragraph"><p>In general, you should try to be as specific as possible in your swallow\r
237 criteria. Try to use criteria that match one window and only one window, to\r
238 have a reliable startup procedure.</p></div>\r
239 <div class="paragraph"><p>If you specify multiple swallow criteria, the placeholder will be replaced by\r
240 the window which matches any of the criteria. As an example:</p></div>\r
241 <div class="listingblock">\r
242 <div class="content">\r
243 <pre><tt>// Matches either Emacs or Gvim, whichever one is started first.\r
244 "swallows": [\r
245     {"class": "^Emacs$"},\r
246     {"class": "^Gvim$"}\r
247 ]</tt></pre>\r
248 </div></div>\r
249 </div>\r
250 <div class="sect2">\r
251 <h3 id="_json_standard_non_compliance">3.2. JSON standard non-compliance</h3>\r
252 <div class="paragraph"><p>A layout file as generated by <tt>i3-save-tree(1)</tt> is not strictly valid JSON:</p></div>\r
253 <div class="olist arabic"><ol class="arabic">\r
254 <li>\r
255 <p>\r
256 Layout files contain multiple “JSON documents” on the top level, whereas the\r
257    JSON standard only allows precisely one “document” (array or hash).\r
258 </p>\r
259 </li>\r
260 <li>\r
261 <p>\r
262 Layout files contain comments which are not standardized, but understood by\r
263    many parsers.\r
264 </p>\r
265 </li>\r
266 </ol></div>\r
267 <div class="paragraph"><p>Both deviations from the JSON standard are to make manual editing by humans\r
268 easier. In case you are writing a more elaborate tool for manipulating these\r
269 layouts, you can either use a JSON parser that supports these deviations (for\r
270 example libyajl), transform the layout file to a JSON-conforming file, or\r
271 <a href="http://cr.i3wm.org/">submit a patch</a> to make <tt>i3-save-tree(1)</tt> optionally\r
272 output standard-conforming JSON.</p></div>\r
273 </div>\r
274 </div>\r
275 </div>\r
276 <div class="sect1">\r
277 <h2 id="_troubleshooting">4. Troubleshooting</h2>\r
278 <div class="sectionbody">\r
279 <div class="sect2">\r
280 <h3 id="_restoring_a_vertically_split_workspace">4.1. Restoring a vertically split workspace</h3>\r
281 <div class="paragraph"><p>When using <tt>i3-save-tree</tt> with the <tt>--workspace</tt> switch, only the <strong>contents</strong> of\r
282 the workspace will be dumped. This means that properties of the workspace\r
283 itself will be lost.</p></div>\r
284 <div class="paragraph"><p>This is relevant for, e.g., a vertically split container as the base container of\r
285 a workspace. Since the split mode is a property of the workspace, it will not be\r
286 stored. In this case, you will have to manually wrap your layout in such a\r
287 container:</p></div>\r
288 <div class="listingblock">\r
289 <div class="content">\r
290 <pre><tt>// vim:ts=4:sw=4:et\r
291 {\r
292     // this is a manually added container to restore the vertical split\r
293     "layout": "splitv",\r
294     "percent": 0.5,\r
295     "type": "con",\r
296     "nodes": [\r
297 \r
298         // the dumped workspace layout goes here\r
299 \r
300     ]\r
301 }</tt></pre>\r
302 </div></div>\r
303 </div>\r
304 </div>\r
305 </div>\r
306 </div>\r
307 <div id="footnotes"><hr /></div>\r
308 <div id="footer" lang="de">\r
309 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>\r
310 </div>\r
311 </body>\r
312 </html>\r