]> git.sur5r.net Git - i3/i3.github.io/blob - docs/ipc.html
add i3 4.1.2 to downloads
[i3/i3.github.io] / docs / ipc.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.4" />\r
8 <title>i3: IPC interface (interprocess communication)</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>IPC interface (interprocess communication)</h1>\r
32 <span id="author">Michael Stapelberg</span><br />\r
33 <span id="email"><tt>&lt;<a href="mailto:michael+i3@stapelberg.de">michael+i3@stapelberg.de</a>&gt;</tt></span><br />\r
34 <span id="revdate">October 2011</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 describes how to interface with i3 from a separate process. This\r
43 is useful for example to remote-control i3 (to write test cases for example) or\r
44 to get various information like the current workspaces to implement an external\r
45 workspace bar.</p></div>\r
46 <div class="paragraph"><p>The method of choice for IPC in our case is a unix socket because it has very\r
47 little overhead on both sides and is usually available without headaches in\r
48 most languages. In the default configuration file, the ipc-socket gets created\r
49 in <tt>/tmp/i3-%u.XXXXXX/ipc-socket.%p</tt> where <tt>%u</tt> is your UNIX username, <tt>%p</tt> is\r
50 the PID of i3 and XXXXXX is a string of random characters from the portable\r
51 filename character set (see mkdtemp(3)). You can get the socketpath from i3 by\r
52 calling <tt>i3 --get-socketpath</tt>.</p></div>\r
53 <div class="paragraph"><p>All i3 utilities, like <tt>i3-msg</tt> and <tt>i3-input</tt> will read the <tt>I3_SOCKET_PATH</tt>\r
54 X11 property, stored on the X11 root window.</p></div>\r
55 </div>\r
56 </div>\r
57 <div class="sect1">\r
58 <h2 id="_establishing_a_connection">1. Establishing a connection</h2>\r
59 <div class="sectionbody">\r
60 <div class="paragraph"><p>To establish a connection, simply open the IPC socket. The following code\r
61 snippet illustrates this in Perl:</p></div>\r
62 <div class="listingblock">\r
63 <div class="content">\r
64 <pre><tt>use IO::Socket::UNIX;\r
65 chomp(my $path = qx(i3 --get-socketpath));\r
66 my $sock = IO::Socket::UNIX-&gt;new(Peer =&gt; $path);</tt></pre>\r
67 </div></div>\r
68 </div>\r
69 </div>\r
70 <div class="sect1">\r
71 <h2 id="_sending_messages_to_i3">2. Sending messages to i3</h2>\r
72 <div class="sectionbody">\r
73 <div class="paragraph"><p>To send a message to i3, you have to format in the binary message format which\r
74 i3 expects. This format specifies a magic string in the beginning to ensure\r
75 the integrity of messages (to prevent follow-up errors). Following the magic\r
76 string comes the length of the payload of the message as 32-bit integer, and\r
77 the type of the message as 32-bit integer (the integers are not converted, so\r
78 they are in native byte order).</p></div>\r
79 <div class="paragraph"><p>The magic string currently is "i3-ipc" and will only be changed when a change\r
80 in the IPC API is done which breaks compatibility (we hope that we don’t need\r
81 to do that).</p></div>\r
82 <div class="paragraph"><p>Currently implemented message types are the following:</p></div>\r
83 <div class="dlist"><dl>\r
84 <dt class="hdlist1">\r
85 COMMAND (0)\r
86 </dt>\r
87 <dd>\r
88 <p>\r
89         The payload of the message is a command for i3 (like the commands you\r
90         can bind to keys in the configuration file) and will be executed\r
91         directly after receiving it. There is no reply to this message.\r
92 </p>\r
93 </dd>\r
94 <dt class="hdlist1">\r
95 GET_WORKSPACES (1)\r
96 </dt>\r
97 <dd>\r
98 <p>\r
99         Gets the current workspaces. The reply will be a JSON-encoded list of\r
100         workspaces (see the reply section).\r
101 </p>\r
102 </dd>\r
103 <dt class="hdlist1">\r
104 SUBSCRIBE (2)\r
105 </dt>\r
106 <dd>\r
107 <p>\r
108         Subscribes your connection to certain events. See <a href="#events">[events]</a> for a\r
109         description of this message and the concept of events.\r
110 </p>\r
111 </dd>\r
112 <dt class="hdlist1">\r
113 GET_OUTPUTS (3)\r
114 </dt>\r
115 <dd>\r
116 <p>\r
117         Gets the current outputs. The reply will be a JSON-encoded list of outputs\r
118         (see the reply section).\r
119 </p>\r
120 </dd>\r
121 <dt class="hdlist1">\r
122 GET_TREE (4)\r
123 </dt>\r
124 <dd>\r
125 <p>\r
126         Gets the layout tree. i3 uses a tree as data structure which includes\r
127         every container. The reply will be the JSON-encoded tree (see the reply\r
128         section).\r
129 </p>\r
130 </dd>\r
131 <dt class="hdlist1">\r
132 GET_MARKS (5)\r
133 </dt>\r
134 <dd>\r
135 <p>\r
136         Gets a list of marks (identifiers for containers to easily jump to them\r
137         later). The reply will be a JSON-encoded list of window marks (see\r
138         reply section).\r
139 </p>\r
140 </dd>\r
141 <dt class="hdlist1">\r
142 GET_BAR_CONFIG (6)\r
143 </dt>\r
144 <dd>\r
145 <p>\r
146         Gets the configuration (as JSON map) of the workspace bar with the\r
147         given ID. If no ID is provided, an array with all configured bar IDs is\r
148         returned instead.\r
149 </p>\r
150 </dd>\r
151 </dl></div>\r
152 <div class="paragraph"><p>So, a typical message could look like this:</p></div>\r
153 <div class="listingblock">\r
154 <div class="content">\r
155 <pre><tt>"i3-ipc" &lt;message length&gt; &lt;message type&gt; &lt;payload&gt;</tt></pre>\r
156 </div></div>\r
157 <div class="paragraph"><p>Or, as a hexdump:</p></div>\r
158 <div class="listingblock">\r
159 <div class="content">\r
160 <pre><tt>00000000  69 33 2d 69 70 63 04 00  00 00 00 00 00 00 65 78  |i3-ipc........ex|\r
161 00000010  69 74 0a                                          |it.|</tt></pre>\r
162 </div></div>\r
163 <div class="paragraph"><p>To generate and send such a message, you could use the following code in Perl:</p></div>\r
164 <div class="listingblock">\r
165 <div class="content">\r
166 <pre><tt>sub format_ipc_command {\r
167     my ($msg) = @_;\r
168     my $len;\r
169     # Get the real byte count (vs. amount of characters)\r
170     { use bytes; $len = length($msg); }\r
171     return "i3-ipc" . pack("LL", $len, 0) . $msg;\r
172 }\r
173 \r
174 $sock-&gt;write(format_ipc_command("exit"));</tt></pre>\r
175 </div></div>\r
176 </div>\r
177 </div>\r
178 <div class="sect1">\r
179 <h2 id="_receiving_replies_from_i3">3. Receiving replies from i3</h2>\r
180 <div class="sectionbody">\r
181 <div class="paragraph"><p>Replies from i3 usually consist of a simple string (the length of the string\r
182 is the message_length, so you can consider them length-prefixed) which in turn\r
183 contain the JSON serialization of a data structure. For example, the\r
184 GET_WORKSPACES message returns an array of workspaces (each workspace is a map\r
185 with certain attributes).</p></div>\r
186 <div class="sect2">\r
187 <h3 id="_reply_format">3.1. Reply format</h3>\r
188 <div class="paragraph"><p>The reply format is identical to the normal message format. There also is\r
189 the magic string, then the message length, then the message type and the\r
190 payload.</p></div>\r
191 <div class="paragraph"><p>The following reply types are implemented:</p></div>\r
192 <div class="dlist"><dl>\r
193 <dt class="hdlist1">\r
194 COMMAND (0)\r
195 </dt>\r
196 <dd>\r
197 <p>\r
198         Confirmation/Error code for the COMMAND message.\r
199 </p>\r
200 </dd>\r
201 <dt class="hdlist1">\r
202 GET_WORKSPACES (1)\r
203 </dt>\r
204 <dd>\r
205 <p>\r
206         Reply to the GET_WORKSPACES message.\r
207 </p>\r
208 </dd>\r
209 <dt class="hdlist1">\r
210 SUBSCRIBE (2)\r
211 </dt>\r
212 <dd>\r
213 <p>\r
214         Confirmation/Error code for the SUBSCRIBE message.\r
215 </p>\r
216 </dd>\r
217 <dt class="hdlist1">\r
218 GET_OUTPUTS (3)\r
219 </dt>\r
220 <dd>\r
221 <p>\r
222         Reply to the GET_OUTPUTS message.\r
223 </p>\r
224 </dd>\r
225 <dt class="hdlist1">\r
226 GET_TREE (4)\r
227 </dt>\r
228 <dd>\r
229 <p>\r
230         Reply to the GET_TREE message.\r
231 </p>\r
232 </dd>\r
233 <dt class="hdlist1">\r
234 GET_MARKS (5)\r
235 </dt>\r
236 <dd>\r
237 <p>\r
238         Reply to the GET_MARKS message.\r
239 </p>\r
240 </dd>\r
241 <dt class="hdlist1">\r
242 GET_BAR_CONFIG (6)\r
243 </dt>\r
244 <dd>\r
245 <p>\r
246         Reply to the GET_BAR_CONFIG message.\r
247 </p>\r
248 </dd>\r
249 </dl></div>\r
250 </div>\r
251 <div class="sect2">\r
252 <h3 id="_command_reply">3.2. COMMAND reply</h3>\r
253 <div class="paragraph"><p>The reply consists of a single serialized map. At the moment, the only\r
254 property is <tt>success (bool)</tt>, but this will be expanded in future versions.</p></div>\r
255 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
256 <div class="listingblock">\r
257 <div class="content">\r
258 <pre><tt>{ "success": true }</tt></pre>\r
259 </div></div>\r
260 </div>\r
261 <div class="sect2">\r
262 <h3 id="_get_workspaces_reply">3.3. GET_WORKSPACES reply</h3>\r
263 <div class="paragraph"><p>The reply consists of a serialized list of workspaces. Each workspace has the\r
264 following properties:</p></div>\r
265 <div class="dlist"><dl>\r
266 <dt class="hdlist1">\r
267 num (integer)\r
268 </dt>\r
269 <dd>\r
270 <p>\r
271         The logical number of the workspace. Corresponds to the command\r
272         to switch to this workspace.\r
273 </p>\r
274 </dd>\r
275 <dt class="hdlist1">\r
276 name (string)\r
277 </dt>\r
278 <dd>\r
279 <p>\r
280         The name of this workspace (by default num+1), as changed by the\r
281         user. Encoded in UTF-8.\r
282 </p>\r
283 </dd>\r
284 <dt class="hdlist1">\r
285 visible (boolean)\r
286 </dt>\r
287 <dd>\r
288 <p>\r
289         Whether this workspace is currently visible on an output (multiple\r
290         workspaces can be visible at the same time).\r
291 </p>\r
292 </dd>\r
293 <dt class="hdlist1">\r
294 focused (boolean)\r
295 </dt>\r
296 <dd>\r
297 <p>\r
298         Whether this workspace currently has the focus (only one workspace\r
299         can have the focus at the same time).\r
300 </p>\r
301 </dd>\r
302 <dt class="hdlist1">\r
303 urgent (boolean)\r
304 </dt>\r
305 <dd>\r
306 <p>\r
307         Whether a window on this workspace has the "urgent" flag set.\r
308 </p>\r
309 </dd>\r
310 <dt class="hdlist1">\r
311 rect (map)\r
312 </dt>\r
313 <dd>\r
314 <p>\r
315         The rectangle of this workspace (equals the rect of the output it\r
316         is on), consists of x, y, width, height.\r
317 </p>\r
318 </dd>\r
319 <dt class="hdlist1">\r
320 output (string)\r
321 </dt>\r
322 <dd>\r
323 <p>\r
324         The video output this workspace is on (LVDS1, VGA1, …).\r
325 </p>\r
326 </dd>\r
327 </dl></div>\r
328 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
329 <div class="listingblock">\r
330 <div class="content">\r
331 <pre><tt>[\r
332  {\r
333   "num": 0,\r
334   "name": "1",\r
335   "visible": true,\r
336   "focused": true,\r
337   "urgent": false,\r
338   "rect": {\r
339    "x": 0,\r
340    "y": 0,\r
341    "width": 1280,\r
342    "height": 800\r
343   },\r
344   "output": "LVDS1"\r
345  },\r
346  {\r
347   "num": 1,\r
348   "name": "2",\r
349   "visible": false,\r
350   "focused": false,\r
351   "urgent": false,\r
352   "rect": {\r
353    "x": 0,\r
354    "y": 0,\r
355    "width": 1280,\r
356    "height": 800\r
357   },\r
358   "output": "LVDS1"\r
359  }\r
360 ]</tt></pre>\r
361 </div></div>\r
362 </div>\r
363 <div class="sect2">\r
364 <h3 id="_subscribe_reply">3.4. SUBSCRIBE reply</h3>\r
365 <div class="paragraph"><p>The reply consists of a single serialized map. The only property is\r
366 <tt>success (bool)</tt>, indicating whether the subscription was successful (the\r
367 default) or whether a JSON parse error occurred.</p></div>\r
368 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
369 <div class="listingblock">\r
370 <div class="content">\r
371 <pre><tt>{ "success": true }</tt></pre>\r
372 </div></div>\r
373 </div>\r
374 <div class="sect2">\r
375 <h3 id="_get_outputs_reply">3.5. GET_OUTPUTS reply</h3>\r
376 <div class="paragraph"><p>The reply consists of a serialized list of outputs. Each output has the\r
377 following properties:</p></div>\r
378 <div class="dlist"><dl>\r
379 <dt class="hdlist1">\r
380 name (string)\r
381 </dt>\r
382 <dd>\r
383 <p>\r
384         The name of this output (as seen in <tt>xrandr(1)</tt>). Encoded in UTF-8.\r
385 </p>\r
386 </dd>\r
387 <dt class="hdlist1">\r
388 active (boolean)\r
389 </dt>\r
390 <dd>\r
391 <p>\r
392         Whether this output is currently active (has a valid mode).\r
393 </p>\r
394 </dd>\r
395 <dt class="hdlist1">\r
396 current_workspace (integer)\r
397 </dt>\r
398 <dd>\r
399 <p>\r
400         The current workspace which is visible on this output. <tt>null</tt> if the\r
401         output is not active.\r
402 </p>\r
403 </dd>\r
404 <dt class="hdlist1">\r
405 rect (map)\r
406 </dt>\r
407 <dd>\r
408 <p>\r
409         The rectangle of this output (equals the rect of the output it\r
410         is on), consists of x, y, width, height.\r
411 </p>\r
412 </dd>\r
413 </dl></div>\r
414 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
415 <div class="listingblock">\r
416 <div class="content">\r
417 <pre><tt>[\r
418  {\r
419   "name": "LVDS1",\r
420   "active": true,\r
421   "current_workspace": 4,\r
422   "rect": {\r
423    "x": 0,\r
424    "y": 0,\r
425    "width": 1280,\r
426    "height": 800\r
427   }\r
428  },\r
429  {\r
430   "name": "VGA1",\r
431   "active": true,\r
432   "current_workspace": 1,\r
433   "rect": {\r
434    "x": 1280,\r
435    "y": 0,\r
436    "width": 1280,\r
437    "height": 1024\r
438   },\r
439  }\r
440 ]</tt></pre>\r
441 </div></div>\r
442 </div>\r
443 <div class="sect2">\r
444 <h3 id="_get_tree_reply">3.6. GET_TREE reply</h3>\r
445 <div class="paragraph"><p>The reply consists of a serialized tree. Each node in the tree (representing\r
446 one container) has at least the properties listed below. While the nodes might\r
447 have more properties, please do not use any properties which are not documented\r
448 here. They are not yet finalized and will probably change!</p></div>\r
449 <div class="dlist"><dl>\r
450 <dt class="hdlist1">\r
451 id (integer)\r
452 </dt>\r
453 <dd>\r
454 <p>\r
455         The internal ID (actually a C pointer value) of this container. Do not\r
456         make any assumptions about it. You can use it to (re-)identify and\r
457         address containers when talking to i3.\r
458 </p>\r
459 </dd>\r
460 <dt class="hdlist1">\r
461 name (string)\r
462 </dt>\r
463 <dd>\r
464 <p>\r
465         The internal name of this container. For all containers which are part\r
466         of the tree structure down to the workspace contents, this is set to a\r
467         nice human-readable name of the container.\r
468         For all other containers, the content is not defined (yet).\r
469 </p>\r
470 </dd>\r
471 <dt class="hdlist1">\r
472 border (string)\r
473 </dt>\r
474 <dd>\r
475 <p>\r
476         Can be either "normal", "none" or "1pixel", dependending on the\r
477         container’s border style.\r
478 </p>\r
479 </dd>\r
480 <dt class="hdlist1">\r
481 layout (string)\r
482 </dt>\r
483 <dd>\r
484 <p>\r
485         Can be either "default", "stacked", "tabbed", "dockarea" or "output".\r
486         Other values might be possible in the future, should we add new\r
487         layouts.\r
488 </p>\r
489 </dd>\r
490 <dt class="hdlist1">\r
491 orientation (string)\r
492 </dt>\r
493 <dd>\r
494 <p>\r
495         Can be either "none" (for non-split containers), "horizontal" or\r
496         "vertical".\r
497 </p>\r
498 </dd>\r
499 <dt class="hdlist1">\r
500 percent (float)\r
501 </dt>\r
502 <dd>\r
503 <p>\r
504         The percentage which this container takes in its parent. A value of\r
505         <tt>null</tt> means that the percent property does not make sense for this\r
506         container, for example for the root container.\r
507 </p>\r
508 </dd>\r
509 <dt class="hdlist1">\r
510 rect (map)\r
511 </dt>\r
512 <dd>\r
513 <p>\r
514         The absolute display coordinates for this container. Display\r
515         coordinates means that when you have two 1600x1200 monitors on a single\r
516         X11 Display (the standard way), the coordinates of the first window on\r
517         the second monitor are <tt>{ "x": 1600, "y": 0, "width": 1600, "height":\r
518         1200 }</tt>.\r
519 </p>\r
520 </dd>\r
521 <dt class="hdlist1">\r
522 window_rect (map)\r
523 </dt>\r
524 <dd>\r
525 <p>\r
526         The coordinates of the <strong>actual client window</strong> inside its container.\r
527         These coordinates are relative to the container and do not include the\r
528         window decoration (which is actually rendered on the parent container).\r
529         So, when using the <tt>default</tt> layout, you will have a 2 pixel border on\r
530         each side, making the window_rect <tt>{ "x": 2, "y": 0, "width": 632,\r
531         "height": 366 }</tt> (for example).\r
532 </p>\r
533 </dd>\r
534 <dt class="hdlist1">\r
535 geometry (map)\r
536 </dt>\r
537 <dd>\r
538 <p>\r
539         The original geometry the window specified when i3 mapped it. Used when\r
540         switching a window to floating mode, for example.\r
541 </p>\r
542 </dd>\r
543 <dt class="hdlist1">\r
544 urgent (bool)\r
545 </dt>\r
546 <dd>\r
547 <p>\r
548         Whether this container (window or workspace) has the urgency hint set.\r
549 </p>\r
550 </dd>\r
551 <dt class="hdlist1">\r
552 focused (bool)\r
553 </dt>\r
554 <dd>\r
555 <p>\r
556         Whether this container is currently focused.\r
557 </p>\r
558 </dd>\r
559 </dl></div>\r
560 <div class="paragraph"><p>Please note that in the following example, I have left out some keys/values\r
561 which are not relevant for the type of the node. Otherwise, the example would\r
562 be by far too long (it already is quite long, despite showing only 1 window and\r
563 one dock window).</p></div>\r
564 <div class="paragraph"><p>It is useful to have an overview of the structure before taking a look at the\r
565 JSON dump:</p></div>\r
566 <div class="ulist"><ul>\r
567 <li>\r
568 <p>\r
569 root\r
570 </p>\r
571 <div class="ulist"><ul>\r
572 <li>\r
573 <p>\r
574 LVDS1\r
575 </p>\r
576 <div class="ulist"><ul>\r
577 <li>\r
578 <p>\r
579 topdock\r
580 </p>\r
581 </li>\r
582 <li>\r
583 <p>\r
584 content\r
585 </p>\r
586 <div class="ulist"><ul>\r
587 <li>\r
588 <p>\r
589 workspace 1\r
590 </p>\r
591 <div class="ulist"><ul>\r
592 <li>\r
593 <p>\r
594 window 1\r
595 </p>\r
596 </li>\r
597 </ul></div>\r
598 </li>\r
599 </ul></div>\r
600 </li>\r
601 <li>\r
602 <p>\r
603 bottomdock\r
604 </p>\r
605 <div class="ulist"><ul>\r
606 <li>\r
607 <p>\r
608 dock window 1\r
609 </p>\r
610 </li>\r
611 </ul></div>\r
612 </li>\r
613 </ul></div>\r
614 </li>\r
615 <li>\r
616 <p>\r
617 VGA1\r
618 </p>\r
619 </li>\r
620 </ul></div>\r
621 </li>\r
622 </ul></div>\r
623 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
624 <div class="listingblock">\r
625 <div class="content">\r
626 <pre><tt>{\r
627  "id": 6875648,\r
628  "name": "root",\r
629  "rect": {\r
630    "x": 0,\r
631    "y": 0,\r
632    "width": 1280,\r
633    "height": 800\r
634  },\r
635  "nodes": [\r
636 \r
637    {\r
638     "id": 6878320,\r
639     "name": "LVDS1",\r
640     "layout": "output",\r
641     "rect": {\r
642       "x": 0,\r
643       "y": 0,\r
644       "width": 1280,\r
645       "height": 800\r
646     },\r
647     "nodes": [\r
648 \r
649       {\r
650        "id": 6878784,\r
651        "name": "topdock",\r
652        "layout": "dockarea",\r
653        "orientation": "vertical",\r
654        "rect": {\r
655          "x": 0,\r
656          "y": 0,\r
657          "width": 1280,\r
658          "height": 0\r
659        },\r
660       },\r
661 \r
662       {\r
663        "id": 6879344,\r
664        "name": "content",\r
665        "rect": {\r
666          "x": 0,\r
667          "y": 0,\r
668          "width": 1280,\r
669          "height": 782\r
670        },\r
671        "nodes": [\r
672 \r
673          {\r
674           "id": 6880464,\r
675           "name": "1",\r
676           "orientation": "horizontal",\r
677           "rect": {\r
678             "x": 0,\r
679             "y": 0,\r
680             "width": 1280,\r
681             "height": 782\r
682           },\r
683           "floating_nodes": [],\r
684           "nodes": [\r
685 \r
686             {\r
687              "id": 6929968,\r
688              "name": "#aa0000",\r
689              "border": "normal",\r
690              "percent": 1,\r
691              "rect": {\r
692                "x": 0,\r
693                "y": 18,\r
694                "width": 1280,\r
695                "height": 782\r
696              }\r
697             }\r
698 \r
699           ]\r
700          }\r
701 \r
702        ]\r
703       },\r
704 \r
705       {\r
706        "id": 6880208,\r
707        "name": "bottomdock",\r
708        "layout": "dockarea",\r
709        "orientation": "vertical",\r
710        "rect": {\r
711          "x": 0,\r
712          "y": 782,\r
713          "width": 1280,\r
714          "height": 18\r
715        },\r
716        "nodes": [\r
717 \r
718          {\r
719           "id": 6931312,\r
720           "name": "#00aa00",\r
721           "percent": 1,\r
722           "rect": {\r
723             "x": 0,\r
724             "y": 782,\r
725             "width": 1280,\r
726             "height": 18\r
727           }\r
728          }\r
729 \r
730        ]\r
731       }\r
732     ]\r
733    }\r
734  ]\r
735 }</tt></pre>\r
736 </div></div>\r
737 </div>\r
738 <div class="sect2">\r
739 <h3 id="_get_marks_reply">3.7. GET_MARKS reply</h3>\r
740 <div class="paragraph"><p>The reply consists of a single array of strings for each container that has a\r
741 mark. The order of that array is undefined. If more than one container has the\r
742 same mark, it will be represented multiple times in the reply (the array\r
743 contents are not unique).</p></div>\r
744 <div class="paragraph"><p>If no window has a mark the response will be the empty array [].</p></div>\r
745 </div>\r
746 <div class="sect2">\r
747 <h3 id="_get_bar_config_reply">3.8. GET_BAR_CONFIG reply</h3>\r
748 <div class="paragraph"><p>This can be used by third-party workspace bars (especially i3bar, but others\r
749 are free to implement compatible alternatives) to get the <tt>bar</tt> block\r
750 configuration from i3.</p></div>\r
751 <div class="paragraph"><p>Depending on the input, the reply is either:</p></div>\r
752 <div class="dlist"><dl>\r
753 <dt class="hdlist1">\r
754 empty input\r
755 </dt>\r
756 <dd>\r
757 <p>\r
758         An array of configured bar IDs\r
759 </p>\r
760 </dd>\r
761 <dt class="hdlist1">\r
762 Bar ID\r
763 </dt>\r
764 <dd>\r
765 <p>\r
766         A JSON map containing the configuration for the specified bar.\r
767 </p>\r
768 </dd>\r
769 </dl></div>\r
770 <div class="paragraph"><p>Each bar configuration has the following properties:</p></div>\r
771 <div class="dlist"><dl>\r
772 <dt class="hdlist1">\r
773 id (string)\r
774 </dt>\r
775 <dd>\r
776 <p>\r
777         The ID for this bar. Included in case you request multiple\r
778         configurations and want to differentiate the different replies.\r
779 </p>\r
780 </dd>\r
781 <dt class="hdlist1">\r
782 mode (string)\r
783 </dt>\r
784 <dd>\r
785 <p>\r
786         Either <tt>dock</tt> (the bar sets the dock window type) or <tt>hide</tt> (the bar\r
787         does not show unless a specific key is pressed).\r
788 </p>\r
789 </dd>\r
790 <dt class="hdlist1">\r
791 position (string)\r
792 </dt>\r
793 <dd>\r
794 <p>\r
795         Either <tt>bottom</tt> or <tt>top</tt> at the moment.\r
796 </p>\r
797 </dd>\r
798 <dt class="hdlist1">\r
799 status_command (string)\r
800 </dt>\r
801 <dd>\r
802 <p>\r
803         Command which will be run to generate a statusline. Each line on stdout\r
804         of this command will be displayed in the bar. At the moment, no\r
805         formatting is supported.\r
806 </p>\r
807 </dd>\r
808 <dt class="hdlist1">\r
809 font (string)\r
810 </dt>\r
811 <dd>\r
812 <p>\r
813         The font to use for text on the bar.\r
814 </p>\r
815 </dd>\r
816 <dt class="hdlist1">\r
817 workspace_buttons (boolean)\r
818 </dt>\r
819 <dd>\r
820 <p>\r
821         Display workspace buttons or not? Defaults to true.\r
822 </p>\r
823 </dd>\r
824 <dt class="hdlist1">\r
825 verbose (boolean)\r
826 </dt>\r
827 <dd>\r
828 <p>\r
829         Should the bar enable verbose output for debugging? Defaults to false.\r
830 </p>\r
831 </dd>\r
832 <dt class="hdlist1">\r
833 colors (map)\r
834 </dt>\r
835 <dd>\r
836 <p>\r
837         Contains key/value pairs of colors. Each value is a color code in hex,\r
838         formatted #rrggbb (like in HTML).\r
839 </p>\r
840 </dd>\r
841 </dl></div>\r
842 <div class="paragraph"><p>The following colors can be configured at the moment:</p></div>\r
843 <div class="dlist"><dl>\r
844 <dt class="hdlist1">\r
845 background\r
846 </dt>\r
847 <dd>\r
848 <p>\r
849         Background color of the bar.\r
850 </p>\r
851 </dd>\r
852 <dt class="hdlist1">\r
853 statusline\r
854 </dt>\r
855 <dd>\r
856 <p>\r
857         Text color to be used for the statusline.\r
858 </p>\r
859 </dd>\r
860 <dt class="hdlist1">\r
861 focused_workspace_text/focused_workspace_bg\r
862 </dt>\r
863 <dd>\r
864 <p>\r
865         Text color/background color for a workspace button when the workspace\r
866         has focus.\r
867 </p>\r
868 </dd>\r
869 <dt class="hdlist1">\r
870 active_workspace_text/active_workspace_bg\r
871 </dt>\r
872 <dd>\r
873 <p>\r
874         Text color/background color for a workspace button when the workspace\r
875         is active (visible) on some output, but the focus is on another one.\r
876         You can only tell this apart from the focused workspace when you are\r
877         using multiple monitors.\r
878 </p>\r
879 </dd>\r
880 <dt class="hdlist1">\r
881 inactive_workspace_text/inactive_workspace_bg\r
882 </dt>\r
883 <dd>\r
884 <p>\r
885         Text color/background color for a workspace button when the workspace\r
886         does not have focus and is not active (visible) on any output. This\r
887         will be the case for most workspaces.\r
888 </p>\r
889 </dd>\r
890 <dt class="hdlist1">\r
891 urgent_workspace_text/urgent_workspace_bar\r
892 </dt>\r
893 <dd>\r
894 <p>\r
895         Text color/background color for workspaces which contain at least one\r
896         window with the urgency hint set.\r
897 </p>\r
898 </dd>\r
899 </dl></div>\r
900 <div class="paragraph"><p><strong>Example of configured bars:</strong></p></div>\r
901 <div class="listingblock">\r
902 <div class="content">\r
903 <pre><tt>["bar-bxuqzf"]</tt></pre>\r
904 </div></div>\r
905 <div class="paragraph"><p><strong>Example of bar configuration:</strong></p></div>\r
906 <div class="listingblock">\r
907 <div class="content">\r
908 <pre><tt>{\r
909  "id": "bar-bxuqzf",\r
910  "mode": "dock",\r
911  "position": "bottom",\r
912  "status_command": "i3status",\r
913  "font": "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1",\r
914  "workspace_buttons": true,\r
915  "verbose": false,\r
916  "colors": {\r
917    "background": "#c0c0c0",\r
918    "statusline": "#00ff00",\r
919    "focused_workspace_text": "#ffffff",\r
920    "focused_workspace_bg": "#000000"\r
921  }\r
922 }</tt></pre>\r
923 </div></div>\r
924 </div>\r
925 </div>\r
926 </div>\r
927 <div class="sect1">\r
928 <h2 id="_events">4. Events</h2>\r
929 <div class="sectionbody">\r
930 <div class="paragraph" id="events"><p>To get informed when certain things happen in i3, clients can subscribe to\r
931 events. Events consist of a name (like "workspace") and an event reply type\r
932 (like I3_IPC_EVENT_WORKSPACE). The events sent by i3 are in the same format\r
933 as replies to specific commands. However, the highest bit of the message type\r
934 is set to 1 to indicate that this is an event reply instead of a normal reply.</p></div>\r
935 <div class="paragraph"><p>Caveat: As soon as you subscribe to an event, it is not guaranteed any longer\r
936 that the requests to i3 are processed in order. This means, the following\r
937 situation can happen: You send a GET_WORKSPACES request but you receive a\r
938 "workspace" event before receiving the reply to GET_WORKSPACES. If your\r
939 program does not want to cope which such kinds of race conditions (an\r
940 event based library may not have a problem here), I suggest you create a\r
941 separate connection to receive events.</p></div>\r
942 <div class="sect2">\r
943 <h3 id="_subscribing_to_events">4.1. Subscribing to events</h3>\r
944 <div class="paragraph"><p>By sending a message of type SUBSCRIBE with a JSON-encoded array as payload\r
945 you can register to an event.</p></div>\r
946 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
947 <div class="listingblock">\r
948 <div class="content">\r
949 <pre><tt>type: SUBSCRIBE\r
950 payload: [ "workspace", "focus" ]</tt></pre>\r
951 </div></div>\r
952 </div>\r
953 <div class="sect2">\r
954 <h3 id="_available_events">4.2. Available events</h3>\r
955 <div class="paragraph"><p>The numbers in parenthesis is the event type (keep in mind that you need to\r
956 strip the highest bit first).</p></div>\r
957 <div class="dlist"><dl>\r
958 <dt class="hdlist1">\r
959 workspace (0)\r
960 </dt>\r
961 <dd>\r
962 <p>\r
963         Sent when the user switches to a different workspace, when a new\r
964         workspace is initialized or when a workspace is removed (because the\r
965         last client vanished).\r
966 </p>\r
967 </dd>\r
968 <dt class="hdlist1">\r
969 output (1)\r
970 </dt>\r
971 <dd>\r
972 <p>\r
973         Sent when RandR issues a change notification (of either screens,\r
974         outputs, CRTCs or output properties).\r
975 </p>\r
976 </dd>\r
977 </dl></div>\r
978 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
979 <div class="listingblock">\r
980 <div class="content">\r
981 <pre><tt># the appropriate 4 bytes read from the socket are stored in $input\r
982 \r
983 # unpack a 32-bit unsigned integer\r
984 my $message_type = unpack("L", $input);\r
985 \r
986 # check if the highest bit is 1\r
987 my $is_event = (($message_type &gt;&gt; 31) == 1);\r
988 \r
989 # use the other bits\r
990 my $event_type = ($message_type &amp; 0x7F);\r
991 \r
992 if ($is_event) {\r
993   say "Received event of type $event_type";\r
994 }</tt></pre>\r
995 </div></div>\r
996 </div>\r
997 <div class="sect2">\r
998 <h3 id="_workspace_event">4.3. workspace event</h3>\r
999 <div class="paragraph"><p>This event consists of a single serialized map containing a property\r
1000 <tt>change (string)</tt> which indicates the type of the change ("focus", "init",\r
1001 "empty", "urgent").</p></div>\r
1002 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1003 <div class="listingblock">\r
1004 <div class="content">\r
1005 <pre><tt>{ "change": "focus" }</tt></pre>\r
1006 </div></div>\r
1007 </div>\r
1008 <div class="sect2">\r
1009 <h3 id="_output_event">4.4. output event</h3>\r
1010 <div class="paragraph"><p>This event consists of a single serialized map containing a property\r
1011 <tt>change (string)</tt> which indicates the type of the change (currently only\r
1012 "unspecified").</p></div>\r
1013 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1014 <div class="listingblock">\r
1015 <div class="content">\r
1016 <pre><tt>{ "change": "unspecified" }</tt></pre>\r
1017 </div></div>\r
1018 </div>\r
1019 </div>\r
1020 </div>\r
1021 <div class="sect1">\r
1022 <h2 id="_see_also">5. See also</h2>\r
1023 <div class="sectionbody">\r
1024 <div class="paragraph"><p>For some languages, libraries are available (so you don’t have to implement\r
1025 all this on your own). This list names some (if you wrote one, please let me\r
1026 know):</p></div>\r
1027 <div class="dlist"><dl>\r
1028 <dt class="hdlist1">\r
1029 C\r
1030 </dt>\r
1031 <dd>\r
1032 <p>\r
1033         i3 includes a headerfile <tt>i3/ipc.h</tt> which provides you all constants.\r
1034         However, there is no library yet.\r
1035 </p>\r
1036 </dd>\r
1037 <dt class="hdlist1">\r
1038 Ruby\r
1039 </dt>\r
1040 <dd>\r
1041 <p>\r
1042         <a href="http://github.com/badboy/i3-ipc">http://github.com/badboy/i3-ipc</a>\r
1043 </p>\r
1044 </dd>\r
1045 <dt class="hdlist1">\r
1046 Perl\r
1047 </dt>\r
1048 <dd>\r
1049 <p>\r
1050         <a href="http://search.cpan.org/search?query=AnyEvent::I3">http://search.cpan.org/search?query=AnyEvent::I3</a>\r
1051 </p>\r
1052 </dd>\r
1053 <dt class="hdlist1">\r
1054 Python\r
1055 </dt>\r
1056 <dd>\r
1057 <p>\r
1058         <a href="http://github.com/thepub/i3ipc">http://github.com/thepub/i3ipc</a>\r
1059 </p>\r
1060 </dd>\r
1061 </dl></div>\r
1062 </div>\r
1063 </div>\r
1064 </div>\r
1065 <div id="footnotes"><hr /></div>\r
1066 <div id="footer" lang="de">\r
1067 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>\r
1068 </div>\r
1069 </body>\r
1070 </html>\r