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