]> git.sur5r.net Git - i3/i3.github.io/blob - docs/ipc.html
Added python IPC library i3msg-python to docs
[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/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: 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 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>IPC interface (interprocess communication)</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">September 2017</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>This document describes how to interface with i3 from a separate process. This\r
44 is useful for example to remote-control i3 (to write test cases for example) or\r
45 to get various information like the current workspaces to implement an external\r
46 workspace bar.</p></div>\r
47 <div class="paragraph"><p>The method of choice for IPC in our case is a unix socket because it has very\r
48 little overhead on both sides and is usually available without headaches in\r
49 most languages. In the default configuration file, the ipc-socket gets created\r
50 in <tt>/tmp/i3-%u.XXXXXX/ipc-socket.%p</tt> where <tt>%u</tt> is your UNIX username, <tt>%p</tt> is\r
51 the PID of i3 and XXXXXX is a string of random characters from the portable\r
52 filename character set (see mkdtemp(3)). You can get the socketpath from i3 by\r
53 calling <tt>i3 --get-socketpath</tt>.</p></div>\r
54 <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
55 X11 property, stored on the X11 root window.</p></div>\r
56 <div class="admonitionblock">\r
57 <table><tr>\r
58 <td class="icon">\r
59 <div class="title">Warning</div>\r
60 </td>\r
61 <td class="content">\r
62 <div class="title">Use an existing library!</div>There are existing libraries for many languages. You can have a look at\r
63 <a href="#libraries">[libraries]</a> or search the web if your language of choice is not mentioned.\r
64 Usually, it is not necessary to implement low-level communication with i3\r
65 directly.</td>\r
66 </tr></table>\r
67 </div>\r
68 </div>\r
69 </div>\r
70 <div class="sect1">\r
71 <h2 id="_establishing_a_connection">1. Establishing a connection</h2>\r
72 <div class="sectionbody">\r
73 <div class="paragraph"><p>To establish a connection, simply open the IPC socket. The following code\r
74 snippet illustrates this in Perl:</p></div>\r
75 <div class="listingblock">\r
76 <div class="content">\r
77 <pre><tt>use IO::Socket::UNIX;\r
78 chomp(my $path = qx(i3 --get-socketpath));\r
79 my $sock = IO::Socket::UNIX-&gt;new(Peer =&gt; $path);</tt></pre>\r
80 </div></div>\r
81 </div>\r
82 </div>\r
83 <div class="sect1">\r
84 <h2 id="_sending_messages_to_i3">2. Sending messages to i3</h2>\r
85 <div class="sectionbody">\r
86 <div class="paragraph"><p>To send a message to i3, you have to format in the binary message format which\r
87 i3 expects. This format specifies a magic string in the beginning to ensure\r
88 the integrity of messages (to prevent follow-up errors). Following the magic\r
89 string comes the length of the payload of the message as 32-bit integer, and\r
90 the type of the message as 32-bit integer (the integers are not converted, so\r
91 they are in native byte order).</p></div>\r
92 <div class="paragraph"><p>The magic string currently is "i3-ipc" and will only be changed when a change\r
93 in the IPC API is done which breaks compatibility (we hope that we don’t need\r
94 to do that).</p></div>\r
95 <div class="tableblock">\r
96 <table rules="all"\r
97 width="100%"\r
98 frame="border"\r
99 cellspacing="0" cellpadding="4">\r
100 <caption class="title">Table 1. Currently implemented message types</caption>\r
101 <col width="10%" />\r
102 <col width="20%" />\r
103 <col width="20%" />\r
104 <col width="50%" />\r
105 <thead>\r
106 <tr>\r
107 <th align="center" valign="top"> Type (numeric) </th>\r
108 <th align="center" valign="top"> Type (name) </th>\r
109 <th align="center" valign="top"> Reply type </th>\r
110 <th align="center" valign="top"> Purpose</th>\r
111 </tr>\r
112 </thead>\r
113 <tbody>\r
114 <tr>\r
115 <td align="center" valign="top"><p class="table">0</p></td>\r
116 <td align="center" valign="top"><p class="table"><tt>RUN_COMMAND</tt></p></td>\r
117 <td align="center" valign="top"><p class="table"><a href="#_command_reply">COMMAND</a></p></td>\r
118 <td align="center" valign="top"><p class="table">Run the payload as an i3 command (like the commands you can bind to keys).</p></td>\r
119 </tr>\r
120 <tr>\r
121 <td align="center" valign="top"><p class="table">1</p></td>\r
122 <td align="center" valign="top"><p class="table"><tt>GET_WORKSPACES</tt></p></td>\r
123 <td align="center" valign="top"><p class="table"><a href="#_workspaces_reply">WORKSPACES</a></p></td>\r
124 <td align="center" valign="top"><p class="table">Get the list of current workspaces.</p></td>\r
125 </tr>\r
126 <tr>\r
127 <td align="center" valign="top"><p class="table">2</p></td>\r
128 <td align="center" valign="top"><p class="table"><tt>SUBSCRIBE</tt></p></td>\r
129 <td align="center" valign="top"><p class="table"><a href="#_subscribe_reply">SUBSCRIBE</a></p></td>\r
130 <td align="center" valign="top"><p class="table">Subscribe this IPC connection to the event types specified in the message payload. See <a href="#events">[events]</a>.</p></td>\r
131 </tr>\r
132 <tr>\r
133 <td align="center" valign="top"><p class="table">3</p></td>\r
134 <td align="center" valign="top"><p class="table"><tt>GET_OUTPUTS</tt></p></td>\r
135 <td align="center" valign="top"><p class="table"><a href="#_outputs_reply">OUTPUTS</a></p></td>\r
136 <td align="center" valign="top"><p class="table">Get the list of current outputs.</p></td>\r
137 </tr>\r
138 <tr>\r
139 <td align="center" valign="top"><p class="table">4</p></td>\r
140 <td align="center" valign="top"><p class="table"><tt>GET_TREE</tt></p></td>\r
141 <td align="center" valign="top"><p class="table"><a href="#_tree_reply">TREE</a></p></td>\r
142 <td align="center" valign="top"><p class="table">Get the i3 layout tree.</p></td>\r
143 </tr>\r
144 <tr>\r
145 <td align="center" valign="top"><p class="table">5</p></td>\r
146 <td align="center" valign="top"><p class="table"><tt>GET_MARKS</tt></p></td>\r
147 <td align="center" valign="top"><p class="table"><a href="#_marks_reply">MARKS</a></p></td>\r
148 <td align="center" valign="top"><p class="table">Gets the names of all currently set marks.</p></td>\r
149 </tr>\r
150 <tr>\r
151 <td align="center" valign="top"><p class="table">6</p></td>\r
152 <td align="center" valign="top"><p class="table"><tt>GET_BAR_CONFIG</tt></p></td>\r
153 <td align="center" valign="top"><p class="table"><a href="#_bar_config_reply">BAR_CONFIG</a></p></td>\r
154 <td align="center" valign="top"><p class="table">Gets the specified bar configuration or the names of all bar configurations if payload is empty.</p></td>\r
155 </tr>\r
156 <tr>\r
157 <td align="center" valign="top"><p class="table">7</p></td>\r
158 <td align="center" valign="top"><p class="table"><tt>GET_VERSION</tt></p></td>\r
159 <td align="center" valign="top"><p class="table"><a href="#_version_reply">VERSION</a></p></td>\r
160 <td align="center" valign="top"><p class="table">Gets the i3 version.</p></td>\r
161 </tr>\r
162 <tr>\r
163 <td align="center" valign="top"><p class="table">8</p></td>\r
164 <td align="center" valign="top"><p class="table"><tt>GET_BINDING_MODES</tt></p></td>\r
165 <td align="center" valign="top"><p class="table"><a href="#_binding_modes_reply">BINDING_MODES</a></p></td>\r
166 <td align="center" valign="top"><p class="table">Gets the names of all currently configured binding modes.</p></td>\r
167 </tr>\r
168 <tr>\r
169 <td align="center" valign="top"><p class="table">9</p></td>\r
170 <td align="center" valign="top"><p class="table"><tt>GET_CONFIG</tt></p></td>\r
171 <td align="center" valign="top"><p class="table"><a href="#_config_reply">CONFIG</a></p></td>\r
172 <td align="center" valign="top"><p class="table">Returns the last loaded i3 config.</p></td>\r
173 </tr>\r
174 </tbody>\r
175 </table>\r
176 </div>\r
177 <div class="paragraph"><p>So, a typical message could look like this:</p></div>\r
178 <div class="listingblock">\r
179 <div class="content">\r
180 <pre><tt>"i3-ipc" &lt;message length&gt; &lt;message type&gt; &lt;payload&gt;</tt></pre>\r
181 </div></div>\r
182 <div class="paragraph"><p>Or, as a hexdump:</p></div>\r
183 <div class="listingblock">\r
184 <div class="content">\r
185 <pre><tt>00000000  69 33 2d 69 70 63 04 00  00 00 00 00 00 00 65 78  |i3-ipc........ex|\r
186 00000010  69 74                                             |it|</tt></pre>\r
187 </div></div>\r
188 <div class="paragraph"><p>To generate and send such a message, you could use the following code in Perl:</p></div>\r
189 <div class="listingblock">\r
190 <div class="content">\r
191 <pre><tt>sub format_ipc_command {\r
192     my ($msg) = @_;\r
193     my $len;\r
194     # Get the real byte count (vs. amount of characters)\r
195     { use bytes; $len = length($msg); }\r
196     return "i3-ipc" . pack("LL", $len, 0) . $msg;\r
197 }\r
198 \r
199 $sock-&gt;write(format_ipc_command("exit"));</tt></pre>\r
200 </div></div>\r
201 </div>\r
202 </div>\r
203 <div class="sect1">\r
204 <h2 id="_receiving_replies_from_i3">3. Receiving replies from i3</h2>\r
205 <div class="sectionbody">\r
206 <div class="paragraph"><p>Replies from i3 usually consist of a simple string (the length of the string\r
207 is the message_length, so you can consider them length-prefixed) which in turn\r
208 contain the JSON serialization of a data structure. For example, the\r
209 GET_WORKSPACES message returns an array of workspaces (each workspace is a map\r
210 with certain attributes).</p></div>\r
211 <div class="sect2">\r
212 <h3 id="_reply_format">3.1. Reply format</h3>\r
213 <div class="paragraph"><p>The reply format is identical to the normal message format. There also is\r
214 the magic string, then the message length, then the message type and the\r
215 payload.</p></div>\r
216 <div class="paragraph"><p>The following reply types are implemented:</p></div>\r
217 <div class="dlist"><dl>\r
218 <dt class="hdlist1">\r
219 COMMAND (0)\r
220 </dt>\r
221 <dd>\r
222 <p>\r
223         Confirmation/Error code for the RUN_COMMAND message.\r
224 </p>\r
225 </dd>\r
226 <dt class="hdlist1">\r
227 WORKSPACES (1)\r
228 </dt>\r
229 <dd>\r
230 <p>\r
231         Reply to the GET_WORKSPACES message.\r
232 </p>\r
233 </dd>\r
234 <dt class="hdlist1">\r
235 SUBSCRIBE (2)\r
236 </dt>\r
237 <dd>\r
238 <p>\r
239         Confirmation/Error code for the SUBSCRIBE message.\r
240 </p>\r
241 </dd>\r
242 <dt class="hdlist1">\r
243 OUTPUTS (3)\r
244 </dt>\r
245 <dd>\r
246 <p>\r
247         Reply to the GET_OUTPUTS message.\r
248 </p>\r
249 </dd>\r
250 <dt class="hdlist1">\r
251 TREE (4)\r
252 </dt>\r
253 <dd>\r
254 <p>\r
255         Reply to the GET_TREE message.\r
256 </p>\r
257 </dd>\r
258 <dt class="hdlist1">\r
259 MARKS (5)\r
260 </dt>\r
261 <dd>\r
262 <p>\r
263         Reply to the GET_MARKS message.\r
264 </p>\r
265 </dd>\r
266 <dt class="hdlist1">\r
267 BAR_CONFIG (6)\r
268 </dt>\r
269 <dd>\r
270 <p>\r
271         Reply to the GET_BAR_CONFIG message.\r
272 </p>\r
273 </dd>\r
274 <dt class="hdlist1">\r
275 VERSION (7)\r
276 </dt>\r
277 <dd>\r
278 <p>\r
279         Reply to the GET_VERSION message.\r
280 </p>\r
281 </dd>\r
282 <dt class="hdlist1">\r
283 BINDING_MODES (8)\r
284 </dt>\r
285 <dd>\r
286 <p>\r
287         Reply to the GET_BINDING_MODES message.\r
288 </p>\r
289 </dd>\r
290 <dt class="hdlist1">\r
291 GET_CONFIG (9)\r
292 </dt>\r
293 <dd>\r
294 <p>\r
295         Reply to the GET_CONFIG message.\r
296 </p>\r
297 </dd>\r
298 </dl></div>\r
299 </div>\r
300 <div class="sect2">\r
301 <h3 id="_command_reply">3.2. COMMAND reply</h3>\r
302 <div class="paragraph"><p>The reply consists of a list of serialized maps for each command that was\r
303 parsed. Each has the property <tt>success (bool)</tt> and may also include a\r
304 human-readable error message in the property <tt>error (string)</tt>.</p></div>\r
305 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
306 <div class="listingblock">\r
307 <div class="content">\r
308 <pre><tt>[{ "success": true }]</tt></pre>\r
309 </div></div>\r
310 </div>\r
311 <div class="sect2">\r
312 <h3 id="_workspaces_reply">3.3. WORKSPACES reply</h3>\r
313 <div class="paragraph"><p>The reply consists of a serialized list of workspaces. Each workspace has the\r
314 following properties:</p></div>\r
315 <div class="dlist"><dl>\r
316 <dt class="hdlist1">\r
317 num (integer)\r
318 </dt>\r
319 <dd>\r
320 <p>\r
321         The logical number of the workspace. Corresponds to the command\r
322         to switch to this workspace. For named workspaces, this will be -1.\r
323 </p>\r
324 </dd>\r
325 <dt class="hdlist1">\r
326 name (string)\r
327 </dt>\r
328 <dd>\r
329 <p>\r
330         The name of this workspace (by default num+1), as changed by the\r
331         user. Encoded in UTF-8.\r
332 </p>\r
333 </dd>\r
334 <dt class="hdlist1">\r
335 visible (boolean)\r
336 </dt>\r
337 <dd>\r
338 <p>\r
339         Whether this workspace is currently visible on an output (multiple\r
340         workspaces can be visible at the same time).\r
341 </p>\r
342 </dd>\r
343 <dt class="hdlist1">\r
344 focused (boolean)\r
345 </dt>\r
346 <dd>\r
347 <p>\r
348         Whether this workspace currently has the focus (only one workspace\r
349         can have the focus at the same time).\r
350 </p>\r
351 </dd>\r
352 <dt class="hdlist1">\r
353 urgent (boolean)\r
354 </dt>\r
355 <dd>\r
356 <p>\r
357         Whether a window on this workspace has the "urgent" flag set.\r
358 </p>\r
359 </dd>\r
360 <dt class="hdlist1">\r
361 rect (map)\r
362 </dt>\r
363 <dd>\r
364 <p>\r
365         The rectangle of this workspace (equals the rect of the output it\r
366         is on), consists of x, y, width, height.\r
367 </p>\r
368 </dd>\r
369 <dt class="hdlist1">\r
370 output (string)\r
371 </dt>\r
372 <dd>\r
373 <p>\r
374         The video output this workspace is on (LVDS1, VGA1, …).\r
375 </p>\r
376 </dd>\r
377 </dl></div>\r
378 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
379 <div class="listingblock">\r
380 <div class="content">\r
381 <pre><tt>[\r
382  {\r
383   "num": 0,\r
384   "name": "1",\r
385   "visible": true,\r
386   "focused": true,\r
387   "urgent": false,\r
388   "rect": {\r
389    "x": 0,\r
390    "y": 0,\r
391    "width": 1280,\r
392    "height": 800\r
393   },\r
394   "output": "LVDS1"\r
395  },\r
396  {\r
397   "num": 1,\r
398   "name": "2",\r
399   "visible": false,\r
400   "focused": false,\r
401   "urgent": false,\r
402   "rect": {\r
403    "x": 0,\r
404    "y": 0,\r
405    "width": 1280,\r
406    "height": 800\r
407   },\r
408   "output": "LVDS1"\r
409  }\r
410 ]</tt></pre>\r
411 </div></div>\r
412 </div>\r
413 <div class="sect2">\r
414 <h3 id="_subscribe_reply">3.4. SUBSCRIBE reply</h3>\r
415 <div class="paragraph"><p>The reply consists of a single serialized map. The only property is\r
416 <tt>success (bool)</tt>, indicating whether the subscription was successful (the\r
417 default) or whether a JSON parse error occurred.</p></div>\r
418 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
419 <div class="listingblock">\r
420 <div class="content">\r
421 <pre><tt>{ "success": true }</tt></pre>\r
422 </div></div>\r
423 </div>\r
424 <div class="sect2">\r
425 <h3 id="_outputs_reply">3.5. OUTPUTS reply</h3>\r
426 <div class="paragraph"><p>The reply consists of a serialized list of outputs. Each output has the\r
427 following properties:</p></div>\r
428 <div class="dlist"><dl>\r
429 <dt class="hdlist1">\r
430 name (string)\r
431 </dt>\r
432 <dd>\r
433 <p>\r
434         The name of this output (as seen in <tt>xrandr(1)</tt>). Encoded in UTF-8.\r
435 </p>\r
436 </dd>\r
437 <dt class="hdlist1">\r
438 active (boolean)\r
439 </dt>\r
440 <dd>\r
441 <p>\r
442         Whether this output is currently active (has a valid mode).\r
443 </p>\r
444 </dd>\r
445 <dt class="hdlist1">\r
446 primary (boolean)\r
447 </dt>\r
448 <dd>\r
449 <p>\r
450         Whether this output is currently the primary output.\r
451 </p>\r
452 </dd>\r
453 <dt class="hdlist1">\r
454 current_workspace (string)\r
455 </dt>\r
456 <dd>\r
457 <p>\r
458         The name of the current workspace that is visible on this output. <tt>null</tt> if\r
459         the output is not active.\r
460 </p>\r
461 </dd>\r
462 <dt class="hdlist1">\r
463 rect (map)\r
464 </dt>\r
465 <dd>\r
466 <p>\r
467         The rectangle of this output (equals the rect of the output it\r
468         is on), consists of x, y, width, height.\r
469 </p>\r
470 </dd>\r
471 </dl></div>\r
472 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
473 <div class="listingblock">\r
474 <div class="content">\r
475 <pre><tt>[\r
476  {\r
477   "name": "LVDS1",\r
478   "active": true,\r
479   "current_workspace": "4",\r
480   "rect": {\r
481    "x": 0,\r
482    "y": 0,\r
483    "width": 1280,\r
484    "height": 800\r
485   }\r
486  },\r
487  {\r
488   "name": "VGA1",\r
489   "active": true,\r
490   "current_workspace": "1",\r
491   "rect": {\r
492    "x": 1280,\r
493    "y": 0,\r
494    "width": 1280,\r
495    "height": 1024\r
496   }\r
497  }\r
498 ]</tt></pre>\r
499 </div></div>\r
500 </div>\r
501 <div class="sect2">\r
502 <h3 id="_tree_reply">3.6. TREE reply</h3>\r
503 <div class="paragraph"><p>The reply consists of a serialized tree. Each node in the tree (representing\r
504 one container) has at least the properties listed below. While the nodes might\r
505 have more properties, please do not use any properties which are not documented\r
506 here. They are not yet finalized and will probably change!</p></div>\r
507 <div class="dlist"><dl>\r
508 <dt class="hdlist1">\r
509 id (integer)\r
510 </dt>\r
511 <dd>\r
512 <p>\r
513         The internal ID (actually a C pointer value) of this container. Do not\r
514         make any assumptions about it. You can use it to (re-)identify and\r
515         address containers when talking to i3.\r
516 </p>\r
517 </dd>\r
518 <dt class="hdlist1">\r
519 name (string)\r
520 </dt>\r
521 <dd>\r
522 <p>\r
523         The internal name of this container. For all containers which are part\r
524         of the tree structure down to the workspace contents, this is set to a\r
525         nice human-readable name of the container.\r
526         For containers that have an X11 window, the content is the title\r
527         (_NET_WM_NAME property) of that window.\r
528         For all other containers, the content is not defined (yet).\r
529 </p>\r
530 </dd>\r
531 <dt class="hdlist1">\r
532 type (string)\r
533 </dt>\r
534 <dd>\r
535 <p>\r
536         Type of this container. Can be one of "root", "output", "con",\r
537         "floating_con", "workspace" or "dockarea".\r
538 </p>\r
539 </dd>\r
540 <dt class="hdlist1">\r
541 border (string)\r
542 </dt>\r
543 <dd>\r
544 <p>\r
545         Can be either "normal", "none" or "pixel", depending on the\r
546         container’s border style.\r
547 </p>\r
548 </dd>\r
549 <dt class="hdlist1">\r
550 current_border_width (integer)\r
551 </dt>\r
552 <dd>\r
553 <p>\r
554         Number of pixels of the border width.\r
555 </p>\r
556 </dd>\r
557 <dt class="hdlist1">\r
558 layout (string)\r
559 </dt>\r
560 <dd>\r
561 <p>\r
562         Can be either "splith", "splitv", "stacked", "tabbed", "dockarea" or\r
563         "output".\r
564         Other values might be possible in the future, should we add new\r
565         layouts.\r
566 </p>\r
567 </dd>\r
568 <dt class="hdlist1">\r
569 orientation (string)\r
570 </dt>\r
571 <dd>\r
572 <p>\r
573         Can be either "none" (for non-split containers), "horizontal" or\r
574         "vertical".\r
575         THIS FIELD IS OBSOLETE. It is still present, but your code should not\r
576         use it. Instead, rely on the layout field.\r
577 </p>\r
578 </dd>\r
579 <dt class="hdlist1">\r
580 percent (float)\r
581 </dt>\r
582 <dd>\r
583 <p>\r
584         The percentage which this container takes in its parent. A value of\r
585         <tt>null</tt> means that the percent property does not make sense for this\r
586         container, for example for the root container.\r
587 </p>\r
588 </dd>\r
589 <dt class="hdlist1">\r
590 rect (map)\r
591 </dt>\r
592 <dd>\r
593 <p>\r
594         The absolute display coordinates for this container. Display\r
595         coordinates means that when you have two 1600x1200 monitors on a single\r
596         X11 Display (the standard way), the coordinates of the first window on\r
597         the second monitor are <tt>{ "x": 1600, "y": 0, "width": 1600, "height":\r
598         1200 }</tt>.\r
599 </p>\r
600 </dd>\r
601 <dt class="hdlist1">\r
602 window_rect (map)\r
603 </dt>\r
604 <dd>\r
605 <p>\r
606         The coordinates of the <strong>actual client window</strong> inside its container.\r
607         These coordinates are relative to the container and do not include the\r
608         window decoration (which is actually rendered on the parent container).\r
609         So, when using the <tt>default</tt> layout, you will have a 2 pixel border on\r
610         each side, making the window_rect <tt>{ "x": 2, "y": 0, "width": 632,\r
611         "height": 366 }</tt> (for example).\r
612 </p>\r
613 </dd>\r
614 <dt class="hdlist1">\r
615 deco_rect (map)\r
616 </dt>\r
617 <dd>\r
618 <p>\r
619         The coordinates of the <strong>window decoration</strong> inside its container. These\r
620         coordinates are relative to the container and do not include the actual\r
621         client window.\r
622 </p>\r
623 </dd>\r
624 <dt class="hdlist1">\r
625 geometry (map)\r
626 </dt>\r
627 <dd>\r
628 <p>\r
629         The original geometry the window specified when i3 mapped it. Used when\r
630         switching a window to floating mode, for example.\r
631 </p>\r
632 </dd>\r
633 <dt class="hdlist1">\r
634 window (integer)\r
635 </dt>\r
636 <dd>\r
637 <p>\r
638         The X11 window ID of the <strong>actual client window</strong> inside this container.\r
639         This field is set to null for split containers or otherwise empty\r
640         containers. This ID corresponds to what xwininfo(1) and other\r
641         X11-related tools display (usually in hex).\r
642 </p>\r
643 </dd>\r
644 <dt class="hdlist1">\r
645 urgent (bool)\r
646 </dt>\r
647 <dd>\r
648 <p>\r
649         Whether this container (window, split container, floating container or\r
650         workspace) has the urgency hint set, directly or indirectly. All parent\r
651         containers up until the workspace container will be marked urgent if they\r
652         have at least one urgent child.\r
653 </p>\r
654 </dd>\r
655 <dt class="hdlist1">\r
656 focused (bool)\r
657 </dt>\r
658 <dd>\r
659 <p>\r
660         Whether this container is currently focused.\r
661 </p>\r
662 </dd>\r
663 <dt class="hdlist1">\r
664 focus (array of integer)\r
665 </dt>\r
666 <dd>\r
667 <p>\r
668         List of child node IDs (see <tt>nodes</tt>, <tt>floating_nodes</tt> and <tt>id</tt>) in focus\r
669         order. Traversing the tree by following the first entry in this array\r
670         will result in eventually reaching the one node with <tt>focused</tt> set to\r
671         true.\r
672 </p>\r
673 </dd>\r
674 <dt class="hdlist1">\r
675 nodes (array of node)\r
676 </dt>\r
677 <dd>\r
678 <p>\r
679         The tiling (i.e. non-floating) child containers of this node.\r
680 </p>\r
681 </dd>\r
682 <dt class="hdlist1">\r
683 floating_nodes (array of node)\r
684 </dt>\r
685 <dd>\r
686 <p>\r
687         The floating child containers of this node. Only non-empty on nodes with\r
688         type <tt>workspace</tt>.\r
689 </p>\r
690 </dd>\r
691 </dl></div>\r
692 <div class="paragraph"><p>Please note that in the following example, I have left out some keys/values\r
693 which are not relevant for the type of the node. Otherwise, the example would\r
694 be by far too long (it already is quite long, despite showing only 1 window and\r
695 one dock window).</p></div>\r
696 <div class="paragraph"><p>It is useful to have an overview of the structure before taking a look at the\r
697 JSON dump:</p></div>\r
698 <div class="ulist"><ul>\r
699 <li>\r
700 <p>\r
701 root\r
702 </p>\r
703 <div class="ulist"><ul>\r
704 <li>\r
705 <p>\r
706 LVDS1\r
707 </p>\r
708 <div class="ulist"><ul>\r
709 <li>\r
710 <p>\r
711 topdock\r
712 </p>\r
713 </li>\r
714 <li>\r
715 <p>\r
716 content\r
717 </p>\r
718 <div class="ulist"><ul>\r
719 <li>\r
720 <p>\r
721 workspace 1\r
722 </p>\r
723 <div class="ulist"><ul>\r
724 <li>\r
725 <p>\r
726 window 1\r
727 </p>\r
728 </li>\r
729 </ul></div>\r
730 </li>\r
731 </ul></div>\r
732 </li>\r
733 <li>\r
734 <p>\r
735 bottomdock\r
736 </p>\r
737 <div class="ulist"><ul>\r
738 <li>\r
739 <p>\r
740 dock window 1\r
741 </p>\r
742 </li>\r
743 </ul></div>\r
744 </li>\r
745 </ul></div>\r
746 </li>\r
747 <li>\r
748 <p>\r
749 VGA1\r
750 </p>\r
751 </li>\r
752 </ul></div>\r
753 </li>\r
754 </ul></div>\r
755 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
756 <div class="listingblock">\r
757 <div class="content">\r
758 <pre><tt>{\r
759  "id": 6875648,\r
760  "name": "root",\r
761  "rect": {\r
762    "x": 0,\r
763    "y": 0,\r
764    "width": 1280,\r
765    "height": 800\r
766  },\r
767  "nodes": [\r
768 \r
769    {\r
770     "id": 6878320,\r
771     "name": "LVDS1",\r
772     "layout": "output",\r
773     "rect": {\r
774       "x": 0,\r
775       "y": 0,\r
776       "width": 1280,\r
777       "height": 800\r
778     },\r
779     "nodes": [\r
780 \r
781       {\r
782        "id": 6878784,\r
783        "name": "topdock",\r
784        "layout": "dockarea",\r
785        "orientation": "vertical",\r
786        "rect": {\r
787          "x": 0,\r
788          "y": 0,\r
789          "width": 1280,\r
790          "height": 0\r
791        }\r
792       },\r
793 \r
794       {\r
795        "id": 6879344,\r
796        "name": "content",\r
797        "rect": {\r
798          "x": 0,\r
799          "y": 0,\r
800          "width": 1280,\r
801          "height": 782\r
802        },\r
803        "nodes": [\r
804 \r
805          {\r
806           "id": 6880464,\r
807           "name": "1",\r
808           "orientation": "horizontal",\r
809           "rect": {\r
810             "x": 0,\r
811             "y": 0,\r
812             "width": 1280,\r
813             "height": 782\r
814           },\r
815           "floating_nodes": [],\r
816           "nodes": [\r
817 \r
818             {\r
819              "id": 6929968,\r
820              "name": "#aa0000",\r
821              "border": "normal",\r
822              "percent": 1,\r
823              "rect": {\r
824                "x": 0,\r
825                "y": 18,\r
826                "width": 1280,\r
827                "height": 782\r
828              }\r
829             }\r
830 \r
831           ]\r
832          }\r
833 \r
834        ]\r
835       },\r
836 \r
837       {\r
838        "id": 6880208,\r
839        "name": "bottomdock",\r
840        "layout": "dockarea",\r
841        "orientation": "vertical",\r
842        "rect": {\r
843          "x": 0,\r
844          "y": 782,\r
845          "width": 1280,\r
846          "height": 18\r
847        },\r
848        "nodes": [\r
849 \r
850          {\r
851           "id": 6931312,\r
852           "name": "#00aa00",\r
853           "percent": 1,\r
854           "rect": {\r
855             "x": 0,\r
856             "y": 782,\r
857             "width": 1280,\r
858             "height": 18\r
859           }\r
860          }\r
861 \r
862        ]\r
863       }\r
864     ]\r
865    }\r
866  ]\r
867 }</tt></pre>\r
868 </div></div>\r
869 </div>\r
870 <div class="sect2">\r
871 <h3 id="_marks_reply">3.7. MARKS reply</h3>\r
872 <div class="paragraph"><p>The reply consists of a single array of strings for each container that has a\r
873 mark. A mark can only be set on one container, so the array is unique.\r
874 The order of that array is undefined.</p></div>\r
875 <div class="paragraph"><p>If no window has a mark the response will be the empty array [].</p></div>\r
876 </div>\r
877 <div class="sect2">\r
878 <h3 id="_bar_config_reply">3.8. BAR_CONFIG reply</h3>\r
879 <div class="paragraph"><p>This can be used by third-party workspace bars (especially i3bar, but others\r
880 are free to implement compatible alternatives) to get the <tt>bar</tt> block\r
881 configuration from i3.</p></div>\r
882 <div class="paragraph"><p>Depending on the input, the reply is either:</p></div>\r
883 <div class="dlist"><dl>\r
884 <dt class="hdlist1">\r
885 empty input\r
886 </dt>\r
887 <dd>\r
888 <p>\r
889         An array of configured bar IDs\r
890 </p>\r
891 </dd>\r
892 <dt class="hdlist1">\r
893 Bar ID\r
894 </dt>\r
895 <dd>\r
896 <p>\r
897         A JSON map containing the configuration for the specified bar.\r
898 </p>\r
899 </dd>\r
900 </dl></div>\r
901 <div class="paragraph"><p>Each bar configuration has the following properties:</p></div>\r
902 <div class="dlist"><dl>\r
903 <dt class="hdlist1">\r
904 id (string)\r
905 </dt>\r
906 <dd>\r
907 <p>\r
908         The ID for this bar. Included in case you request multiple\r
909         configurations and want to differentiate the different replies.\r
910 </p>\r
911 </dd>\r
912 <dt class="hdlist1">\r
913 mode (string)\r
914 </dt>\r
915 <dd>\r
916 <p>\r
917         Either <tt>dock</tt> (the bar sets the dock window type) or <tt>hide</tt> (the bar\r
918         does not show unless a specific key is pressed).\r
919 </p>\r
920 </dd>\r
921 <dt class="hdlist1">\r
922 position (string)\r
923 </dt>\r
924 <dd>\r
925 <p>\r
926         Either <tt>bottom</tt> or <tt>top</tt> at the moment.\r
927 </p>\r
928 </dd>\r
929 <dt class="hdlist1">\r
930 status_command (string)\r
931 </dt>\r
932 <dd>\r
933 <p>\r
934         Command which will be run to generate a statusline. Each line on stdout\r
935         of this command will be displayed in the bar. At the moment, no\r
936         formatting is supported.\r
937 </p>\r
938 </dd>\r
939 <dt class="hdlist1">\r
940 font (string)\r
941 </dt>\r
942 <dd>\r
943 <p>\r
944         The font to use for text on the bar.\r
945 </p>\r
946 </dd>\r
947 <dt class="hdlist1">\r
948 workspace_buttons (boolean)\r
949 </dt>\r
950 <dd>\r
951 <p>\r
952         Display workspace buttons or not? Defaults to true.\r
953 </p>\r
954 </dd>\r
955 <dt class="hdlist1">\r
956 binding_mode_indicator (boolean)\r
957 </dt>\r
958 <dd>\r
959 <p>\r
960         Display the mode indicator or not? Defaults to true.\r
961 </p>\r
962 </dd>\r
963 <dt class="hdlist1">\r
964 verbose (boolean)\r
965 </dt>\r
966 <dd>\r
967 <p>\r
968         Should the bar enable verbose output for debugging? Defaults to false.\r
969 </p>\r
970 </dd>\r
971 <dt class="hdlist1">\r
972 colors (map)\r
973 </dt>\r
974 <dd>\r
975 <p>\r
976         Contains key/value pairs of colors. Each value is a color code in hex,\r
977         formatted #rrggbb (like in HTML).\r
978 </p>\r
979 </dd>\r
980 </dl></div>\r
981 <div class="paragraph"><p>The following colors can be configured at the moment:</p></div>\r
982 <div class="dlist"><dl>\r
983 <dt class="hdlist1">\r
984 background\r
985 </dt>\r
986 <dd>\r
987 <p>\r
988         Background color of the bar.\r
989 </p>\r
990 </dd>\r
991 <dt class="hdlist1">\r
992 statusline\r
993 </dt>\r
994 <dd>\r
995 <p>\r
996         Text color to be used for the statusline.\r
997 </p>\r
998 </dd>\r
999 <dt class="hdlist1">\r
1000 separator\r
1001 </dt>\r
1002 <dd>\r
1003 <p>\r
1004         Text color to be used for the separator.\r
1005 </p>\r
1006 </dd>\r
1007 <dt class="hdlist1">\r
1008 focused_background\r
1009 </dt>\r
1010 <dd>\r
1011 <p>\r
1012         Background color of the bar on the currently focused monitor output.\r
1013 </p>\r
1014 </dd>\r
1015 <dt class="hdlist1">\r
1016 focused_statusline\r
1017 </dt>\r
1018 <dd>\r
1019 <p>\r
1020         Text color to be used for the statusline on the currently focused\r
1021         monitor output.\r
1022 </p>\r
1023 </dd>\r
1024 <dt class="hdlist1">\r
1025 focused_separator\r
1026 </dt>\r
1027 <dd>\r
1028 <p>\r
1029         Text color to be used for the separator on the currently focused\r
1030         monitor output.\r
1031 </p>\r
1032 </dd>\r
1033 <dt class="hdlist1">\r
1034 focused_workspace_text/focused_workspace_bg/focused_workspace_border\r
1035 </dt>\r
1036 <dd>\r
1037 <p>\r
1038         Text/background/border color for a workspace button when the workspace\r
1039         has focus.\r
1040 </p>\r
1041 </dd>\r
1042 <dt class="hdlist1">\r
1043 active_workspace_text/active_workspace_bg/active_workspace_border\r
1044 </dt>\r
1045 <dd>\r
1046 <p>\r
1047         Text/background/border color for a workspace button when the workspace\r
1048         is active (visible) on some output, but the focus is on another one.\r
1049         You can only tell this apart from the focused workspace when you are\r
1050         using multiple monitors.\r
1051 </p>\r
1052 </dd>\r
1053 <dt class="hdlist1">\r
1054 inactive_workspace_text/inactive_workspace_bg/inactive_workspace_border\r
1055 </dt>\r
1056 <dd>\r
1057 <p>\r
1058         Text/background/border color for a workspace button when the workspace\r
1059         does not have focus and is not active (visible) on any output. This\r
1060         will be the case for most workspaces.\r
1061 </p>\r
1062 </dd>\r
1063 <dt class="hdlist1">\r
1064 urgent_workspace_text/urgent_workspace_bg/urgent_workspace_border\r
1065 </dt>\r
1066 <dd>\r
1067 <p>\r
1068         Text/background/border color for workspaces which contain at least one\r
1069         window with the urgency hint set.\r
1070 </p>\r
1071 </dd>\r
1072 <dt class="hdlist1">\r
1073 binding_mode_text/binding_mode_bg/binding_mode_border\r
1074 </dt>\r
1075 <dd>\r
1076 <p>\r
1077         Text/background/border color for the binding mode indicator.\r
1078 </p>\r
1079 </dd>\r
1080 </dl></div>\r
1081 <div class="paragraph"><p><strong>Example of configured bars:</strong></p></div>\r
1082 <div class="listingblock">\r
1083 <div class="content">\r
1084 <pre><tt>["bar-bxuqzf"]</tt></pre>\r
1085 </div></div>\r
1086 <div class="paragraph"><p><strong>Example of bar configuration:</strong></p></div>\r
1087 <div class="listingblock">\r
1088 <div class="content">\r
1089 <pre><tt>{\r
1090  "id": "bar-bxuqzf",\r
1091  "mode": "dock",\r
1092  "position": "bottom",\r
1093  "status_command": "i3status",\r
1094  "font": "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1",\r
1095  "workspace_buttons": true,\r
1096  "binding_mode_indicator": true,\r
1097  "verbose": false,\r
1098  "colors": {\r
1099    "background": "#c0c0c0",\r
1100    "statusline": "#00ff00",\r
1101    "focused_workspace_text": "#ffffff",\r
1102    "focused_workspace_bg": "#000000"\r
1103  }\r
1104 }</tt></pre>\r
1105 </div></div>\r
1106 </div>\r
1107 <div class="sect2">\r
1108 <h3 id="_version_reply">3.9. VERSION reply</h3>\r
1109 <div class="paragraph"><p>The reply consists of a single JSON dictionary with the following keys:</p></div>\r
1110 <div class="dlist"><dl>\r
1111 <dt class="hdlist1">\r
1112 major (integer)\r
1113 </dt>\r
1114 <dd>\r
1115 <p>\r
1116         The major version of i3, such as <tt>4</tt>.\r
1117 </p>\r
1118 </dd>\r
1119 <dt class="hdlist1">\r
1120 minor (integer)\r
1121 </dt>\r
1122 <dd>\r
1123 <p>\r
1124         The minor version of i3, such as <tt>2</tt>. Changes in the IPC interface (new\r
1125         features) will only occur with new minor (or major) releases. However,\r
1126         bugfixes might be introduced in patch releases, too.\r
1127 </p>\r
1128 </dd>\r
1129 <dt class="hdlist1">\r
1130 patch (integer)\r
1131 </dt>\r
1132 <dd>\r
1133 <p>\r
1134         The patch version of i3, such as <tt>1</tt> (when the complete version is\r
1135         <tt>4.2.1</tt>). For versions such as <tt>4.2</tt>, patch will be set to <tt>0</tt>.\r
1136 </p>\r
1137 </dd>\r
1138 <dt class="hdlist1">\r
1139 human_readable (string)\r
1140 </dt>\r
1141 <dd>\r
1142 <p>\r
1143         A human-readable version of i3 containing the precise git version,\r
1144         build date and branch name. When you need to display the i3 version to\r
1145         your users, use the human-readable version whenever possible (since\r
1146         this is what <tt>i3 --version</tt> displays, too).\r
1147 </p>\r
1148 </dd>\r
1149 <dt class="hdlist1">\r
1150 loaded_config_file_name (string)\r
1151 </dt>\r
1152 <dd>\r
1153 <p>\r
1154         The current config path.\r
1155 </p>\r
1156 </dd>\r
1157 </dl></div>\r
1158 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1159 <div class="listingblock">\r
1160 <div class="content">\r
1161 <pre><tt>{\r
1162    "human_readable" : "4.2-169-gf80b877 (2012-08-05, branch \"next\")",\r
1163    "loaded_config_file_name" : "/home/hwangcc23/.i3/config",\r
1164    "minor" : 2,\r
1165    "patch" : 0,\r
1166    "major" : 4\r
1167 }</tt></pre>\r
1168 </div></div>\r
1169 </div>\r
1170 <div class="sect2">\r
1171 <h3 id="_binding_modes_reply">3.10. BINDING_MODES reply</h3>\r
1172 <div class="paragraph"><p>The reply consists of an array of all currently configured binding modes.</p></div>\r
1173 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1174 <div class="listingblock">\r
1175 <div class="content">\r
1176 <pre><tt>["default", "resize"]</tt></pre>\r
1177 </div></div>\r
1178 </div>\r
1179 <div class="sect2">\r
1180 <h3 id="_config_reply">3.11. CONFIG reply</h3>\r
1181 <div class="paragraph"><p>The config reply is a map which currently only contains the "config" member,\r
1182 which is a string containing the config file as loaded by i3 most recently.</p></div>\r
1183 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1184 <div class="listingblock">\r
1185 <div class="content">\r
1186 <pre><tt>{ "config": "font pango:monospace 8\nbindsym Mod4+q exit\n" }</tt></pre>\r
1187 </div></div>\r
1188 </div>\r
1189 </div>\r
1190 </div>\r
1191 <div class="sect1">\r
1192 <h2 id="_events">4. Events</h2>\r
1193 <div class="sectionbody">\r
1194 <div class="paragraph" id="events"><p>To get informed when certain things happen in i3, clients can subscribe to\r
1195 events. Events consist of a name (like "workspace") and an event reply type\r
1196 (like I3_IPC_EVENT_WORKSPACE). The events sent by i3 are in the same format\r
1197 as replies to specific commands. However, the highest bit of the message type\r
1198 is set to 1 to indicate that this is an event reply instead of a normal reply.</p></div>\r
1199 <div class="paragraph"><p>Caveat: As soon as you subscribe to an event, it is not guaranteed any longer\r
1200 that the requests to i3 are processed in order. This means, the following\r
1201 situation can happen: You send a GET_WORKSPACES request but you receive a\r
1202 "workspace" event before receiving the reply to GET_WORKSPACES. If your\r
1203 program does not want to cope which such kinds of race conditions (an\r
1204 event based library may not have a problem here), I suggest you create a\r
1205 separate connection to receive events.</p></div>\r
1206 <div class="sect2">\r
1207 <h3 id="_subscribing_to_events">4.1. Subscribing to events</h3>\r
1208 <div class="paragraph"><p>By sending a message of type SUBSCRIBE with a JSON-encoded array as payload\r
1209 you can register to an event.</p></div>\r
1210 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1211 <div class="listingblock">\r
1212 <div class="content">\r
1213 <pre><tt>type: SUBSCRIBE\r
1214 payload: [ "workspace", "output" ]</tt></pre>\r
1215 </div></div>\r
1216 </div>\r
1217 <div class="sect2">\r
1218 <h3 id="_available_events">4.2. Available events</h3>\r
1219 <div class="paragraph"><p>The numbers in parenthesis is the event type (keep in mind that you need to\r
1220 strip the highest bit first).</p></div>\r
1221 <div class="dlist"><dl>\r
1222 <dt class="hdlist1">\r
1223 workspace (0)\r
1224 </dt>\r
1225 <dd>\r
1226 <p>\r
1227         Sent when the user switches to a different workspace, when a new\r
1228         workspace is initialized or when a workspace is removed (because the\r
1229         last client vanished).\r
1230 </p>\r
1231 </dd>\r
1232 <dt class="hdlist1">\r
1233 output (1)\r
1234 </dt>\r
1235 <dd>\r
1236 <p>\r
1237         Sent when RandR issues a change notification (of either screens,\r
1238         outputs, CRTCs or output properties).\r
1239 </p>\r
1240 </dd>\r
1241 <dt class="hdlist1">\r
1242 mode (2)\r
1243 </dt>\r
1244 <dd>\r
1245 <p>\r
1246         Sent whenever i3 changes its binding mode.\r
1247 </p>\r
1248 </dd>\r
1249 <dt class="hdlist1">\r
1250 window (3)\r
1251 </dt>\r
1252 <dd>\r
1253 <p>\r
1254         Sent when a client&#8217;s window is successfully reparented (that is when i3\r
1255         has finished fitting it into a container), when a window received input\r
1256         focus or when certain properties of the window have changed.\r
1257 </p>\r
1258 </dd>\r
1259 <dt class="hdlist1">\r
1260 barconfig_update (4)\r
1261 </dt>\r
1262 <dd>\r
1263 <p>\r
1264     Sent when the hidden_state or mode field in the barconfig of any bar\r
1265     instance was updated and when the config is reloaded.\r
1266 </p>\r
1267 </dd>\r
1268 <dt class="hdlist1">\r
1269 binding (5)\r
1270 </dt>\r
1271 <dd>\r
1272 <p>\r
1273         Sent when a configured command binding is triggered with the keyboard or\r
1274         mouse\r
1275 </p>\r
1276 </dd>\r
1277 <dt class="hdlist1">\r
1278 shutdown (6)\r
1279 </dt>\r
1280 <dd>\r
1281 <p>\r
1282         Sent when the ipc shuts down because of a restart or exit by user command\r
1283 </p>\r
1284 </dd>\r
1285 </dl></div>\r
1286 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1287 <div class="listingblock">\r
1288 <div class="content">\r
1289 <pre><tt># the appropriate 4 bytes read from the socket are stored in $input\r
1290 \r
1291 # unpack a 32-bit unsigned integer\r
1292 my $message_type = unpack("L", $input);\r
1293 \r
1294 # check if the highest bit is 1\r
1295 my $is_event = (($message_type &gt;&gt; 31) == 1);\r
1296 \r
1297 # use the other bits\r
1298 my $event_type = ($message_type &amp; 0x7F);\r
1299 \r
1300 if ($is_event) {\r
1301   say "Received event of type $event_type";\r
1302 }</tt></pre>\r
1303 </div></div>\r
1304 </div>\r
1305 <div class="sect2">\r
1306 <h3 id="_workspace_event">4.3. workspace event</h3>\r
1307 <div class="paragraph"><p>This event consists of a single serialized map containing a property\r
1308 <tt>change (string)</tt> which indicates the type of the change ("focus", "init",\r
1309 "empty", "urgent", "reload", "rename", "restored", "move"). A\r
1310 <tt>current (object)</tt> property will be present with the affected workspace\r
1311 whenever the type of event affects a workspace (otherwise, it will be +null).</p></div>\r
1312 <div class="paragraph"><p>When the change is "focus", an <tt>old (object)</tt> property will be present with the\r
1313 previous workspace.  When the first switch occurs (when i3 focuses the\r
1314 workspace visible at the beginning) there is no previous workspace, and the\r
1315 <tt>old</tt> property will be set to <tt>null</tt>.  Also note that if the previous is empty\r
1316 it will get destroyed when switching, but will still be present in the "old"\r
1317 property.</p></div>\r
1318 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1319 <div class="listingblock">\r
1320 <div class="content">\r
1321 <pre><tt>{\r
1322  "change": "focus",\r
1323  "current": {\r
1324   "id": 28489712,\r
1325   "type": "workspace",\r
1326   ...\r
1327  }\r
1328  "old": {\r
1329   "id": 28489715,\r
1330   "type": "workspace",\r
1331   ...\r
1332  }\r
1333 }</tt></pre>\r
1334 </div></div>\r
1335 </div>\r
1336 <div class="sect2">\r
1337 <h3 id="_output_event">4.4. output event</h3>\r
1338 <div class="paragraph"><p>This event consists of a single serialized map containing a property\r
1339 <tt>change (string)</tt> which indicates the type of the change (currently only\r
1340 "unspecified").</p></div>\r
1341 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1342 <div class="listingblock">\r
1343 <div class="content">\r
1344 <pre><tt>{ "change": "unspecified" }</tt></pre>\r
1345 </div></div>\r
1346 </div>\r
1347 <div class="sect2">\r
1348 <h3 id="_mode_event">4.5. mode event</h3>\r
1349 <div class="paragraph"><p>This event consists of a single serialized map containing a property\r
1350 <tt>change (string)</tt> which holds the name of current mode in use. The name\r
1351 is the same as specified in config when creating a mode. The default\r
1352 mode is simply named default. It contains a second property, <tt>pango_markup</tt>, which\r
1353 defines whether pango markup shall be used for displaying this mode.</p></div>\r
1354 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1355 <div class="listingblock">\r
1356 <div class="content">\r
1357 <pre><tt>{\r
1358   "change": "default",\r
1359   "pango_markup": true\r
1360 }</tt></pre>\r
1361 </div></div>\r
1362 </div>\r
1363 <div class="sect2">\r
1364 <h3 id="_window_event">4.6. window event</h3>\r
1365 <div class="paragraph"><p>This event consists of a single serialized map containing a property\r
1366 <tt>change (string)</tt> which indicates the type of the change</p></div>\r
1367 <div class="ulist"><ul>\r
1368 <li>\r
1369 <p>\r
1370 <tt>new</tt> – the window has become managed by i3\r
1371 </p>\r
1372 </li>\r
1373 <li>\r
1374 <p>\r
1375 <tt>close</tt> – the window has closed\r
1376 </p>\r
1377 </li>\r
1378 <li>\r
1379 <p>\r
1380 <tt>focus</tt> – the window has received input focus\r
1381 </p>\r
1382 </li>\r
1383 <li>\r
1384 <p>\r
1385 <tt>title</tt> – the window&#8217;s title has changed\r
1386 </p>\r
1387 </li>\r
1388 <li>\r
1389 <p>\r
1390 <tt>fullscreen_mode</tt> – the window has entered or exited fullscreen mode\r
1391 </p>\r
1392 </li>\r
1393 <li>\r
1394 <p>\r
1395 <tt>move</tt> – the window has changed its position in the tree\r
1396 </p>\r
1397 </li>\r
1398 <li>\r
1399 <p>\r
1400 <tt>floating</tt> – the window has transitioned to or from floating\r
1401 </p>\r
1402 </li>\r
1403 <li>\r
1404 <p>\r
1405 <tt>urgent</tt> – the window has become urgent or lost its urgent status\r
1406 </p>\r
1407 </li>\r
1408 <li>\r
1409 <p>\r
1410 <tt>mark</tt> – a mark has been added to or removed from the window\r
1411 </p>\r
1412 </li>\r
1413 </ul></div>\r
1414 <div class="paragraph"><p>Additionally a <tt>container (object)</tt> field will be present, which consists\r
1415 of the window&#8217;s parent container. Be aware that for the "new" event, the\r
1416 container will hold the initial name of the newly reparented window (e.g.\r
1417 if you run urxvt with a shell that changes the title, you will still at\r
1418 this point get the window title as "urxvt").</p></div>\r
1419 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1420 <div class="listingblock">\r
1421 <div class="content">\r
1422 <pre><tt>{\r
1423  "change": "new",\r
1424  "container": {\r
1425   "id": 35569536,\r
1426   "type": "con",\r
1427   ...\r
1428  }\r
1429 }</tt></pre>\r
1430 </div></div>\r
1431 </div>\r
1432 <div class="sect2">\r
1433 <h3 id="_barconfig_update_event">4.7. barconfig_update event</h3>\r
1434 <div class="paragraph"><p>This event consists of a single serialized map reporting on options from the\r
1435 barconfig of the specified bar_id that were updated in i3. This event is the\r
1436 same as a <tt>GET_BAR_CONFIG</tt> reply for the bar with the given id.</p></div>\r
1437 </div>\r
1438 <div class="sect2">\r
1439 <h3 id="_binding_event">4.8. binding event</h3>\r
1440 <div class="paragraph"><p>This event consists of a single serialized map reporting on the details of a\r
1441 binding that ran a command because of user input. The <tt>change (string)</tt> field\r
1442 indicates what sort of binding event was triggered (right now it will always be\r
1443 <tt>"run"</tt> but may be expanded in the future).</p></div>\r
1444 <div class="paragraph"><p>The <tt>binding (object)</tt> field contains details about the binding that was run:</p></div>\r
1445 <div class="dlist"><dl>\r
1446 <dt class="hdlist1">\r
1447 command (string)\r
1448 </dt>\r
1449 <dd>\r
1450 <p>\r
1451         The i3 command that is configured to run for this binding.\r
1452 </p>\r
1453 </dd>\r
1454 <dt class="hdlist1">\r
1455 event_state_mask (array of strings)\r
1456 </dt>\r
1457 <dd>\r
1458 <p>\r
1459         The group and modifier keys that were configured with this binding.\r
1460 </p>\r
1461 </dd>\r
1462 <dt class="hdlist1">\r
1463 input_code (integer)\r
1464 </dt>\r
1465 <dd>\r
1466 <p>\r
1467         If the binding was configured with <tt>bindcode</tt>, this will be the key code\r
1468         that was given for the binding. If the binding is a mouse binding, it will be\r
1469         the number of the mouse button that was pressed. Otherwise it will be 0.\r
1470 </p>\r
1471 </dd>\r
1472 <dt class="hdlist1">\r
1473 symbol (string or null)\r
1474 </dt>\r
1475 <dd>\r
1476 <p>\r
1477         If this is a keyboard binding that was configured with <tt>bindsym</tt>, this\r
1478         field will contain the given symbol. Otherwise it will be <tt>null</tt>.\r
1479 </p>\r
1480 </dd>\r
1481 <dt class="hdlist1">\r
1482 input_type (string)\r
1483 </dt>\r
1484 <dd>\r
1485 <p>\r
1486         This will be <tt>"keyboard"</tt> or <tt>"mouse"</tt> depending on whether or not this was\r
1487         a keyboard or a mouse binding.\r
1488 </p>\r
1489 </dd>\r
1490 </dl></div>\r
1491 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1492 <div class="listingblock">\r
1493 <div class="content">\r
1494 <pre><tt>{\r
1495  "change": "run",\r
1496  "binding": {\r
1497   "command": "nop",\r
1498   "event_state_mask": [\r
1499     "shift",\r
1500     "ctrl"\r
1501   ],\r
1502   "input_code": 0,\r
1503   "symbol": "t",\r
1504   "input_type": "keyboard"\r
1505  }\r
1506 }</tt></pre>\r
1507 </div></div>\r
1508 </div>\r
1509 <div class="sect2">\r
1510 <h3 id="_shutdown_event">4.9. shutdown event</h3>\r
1511 <div class="paragraph"><p>This event is triggered when the connection to the ipc is about to shutdown\r
1512 because of a user action such as a <tt>restart</tt> or <tt>exit</tt> command. The <tt>change\r
1513 (string)</tt> field indicates why the ipc is shutting down. It can be either\r
1514 <tt>"restart"</tt> or <tt>"exit"</tt>.</p></div>\r
1515 <div class="paragraph"><p><strong>Example:</strong></p></div>\r
1516 <div class="listingblock">\r
1517 <div class="content">\r
1518 <pre><tt>{\r
1519  "change": "restart"\r
1520 }</tt></pre>\r
1521 </div></div>\r
1522 </div>\r
1523 </div>\r
1524 </div>\r
1525 <div class="sect1">\r
1526 <h2 id="_see_also_existing_libraries">5. See also (existing libraries)</h2>\r
1527 <div class="sectionbody">\r
1528 <div class="paragraph" id="libraries"><p>For some languages, libraries are available (so you don’t have to implement\r
1529 all this on your own). This list names some (if you wrote one, please let me\r
1530 know):</p></div>\r
1531 <div class="dlist"><dl>\r
1532 <dt class="hdlist1">\r
1533 C\r
1534 </dt>\r
1535 <dd>\r
1536 <div class="ulist"><ul>\r
1537 <li>\r
1538 <p>\r
1539 i3 includes a headerfile <tt>i3/ipc.h</tt> which provides you all constants.\r
1540 </p>\r
1541 </li>\r
1542 <li>\r
1543 <p>\r
1544 <a href="https://github.com/acrisci/i3ipc-glib">https://github.com/acrisci/i3ipc-glib</a>\r
1545 </p>\r
1546 </li>\r
1547 </ul></div>\r
1548 </dd>\r
1549 <dt class="hdlist1">\r
1550 C++\r
1551 </dt>\r
1552 <dd>\r
1553 <div class="ulist"><ul>\r
1554 <li>\r
1555 <p>\r
1556 <a href="https://github.com/drmgc/i3ipcpp">https://github.com/drmgc/i3ipcpp</a>\r
1557 </p>\r
1558 </li>\r
1559 </ul></div>\r
1560 </dd>\r
1561 <dt class="hdlist1">\r
1562 Go\r
1563 </dt>\r
1564 <dd>\r
1565 <div class="ulist"><ul>\r
1566 <li>\r
1567 <p>\r
1568 <a href="https://github.com/mdirkse/i3ipc-go">https://github.com/mdirkse/i3ipc-go</a>\r
1569 </p>\r
1570 </li>\r
1571 </ul></div>\r
1572 </dd>\r
1573 <dt class="hdlist1">\r
1574 JavaScript\r
1575 </dt>\r
1576 <dd>\r
1577 <div class="ulist"><ul>\r
1578 <li>\r
1579 <p>\r
1580 <a href="https://github.com/acrisci/i3ipc-gjs">https://github.com/acrisci/i3ipc-gjs</a>\r
1581 </p>\r
1582 </li>\r
1583 </ul></div>\r
1584 </dd>\r
1585 <dt class="hdlist1">\r
1586 Lua\r
1587 </dt>\r
1588 <dd>\r
1589 <div class="ulist"><ul>\r
1590 <li>\r
1591 <p>\r
1592 <a href="https://github.com/acrisci/i3ipc-lua">https://github.com/acrisci/i3ipc-lua</a>\r
1593 </p>\r
1594 </li>\r
1595 </ul></div>\r
1596 </dd>\r
1597 <dt class="hdlist1">\r
1598 Perl\r
1599 </dt>\r
1600 <dd>\r
1601 <div class="ulist"><ul>\r
1602 <li>\r
1603 <p>\r
1604 <a href="https://metacpan.org/module/AnyEvent::I3">https://metacpan.org/module/AnyEvent::I3</a>\r
1605 </p>\r
1606 </li>\r
1607 </ul></div>\r
1608 </dd>\r
1609 <dt class="hdlist1">\r
1610 Python\r
1611 </dt>\r
1612 <dd>\r
1613 <div class="ulist"><ul>\r
1614 <li>\r
1615 <p>\r
1616 <a href="https://github.com/acrisci/i3ipc-python">https://github.com/acrisci/i3ipc-python</a>\r
1617 </p>\r
1618 </li>\r
1619 <li>\r
1620 <p>\r
1621 <a href="https://github.com/Ceryn/i3msg-python">https://github.com/Ceryn/i3msg-python</a>\r
1622 </p>\r
1623 </li>\r
1624 <li>\r
1625 <p>\r
1626 <a href="https://github.com/whitelynx/i3ipc">https://github.com/whitelynx/i3ipc</a> (not maintained)\r
1627 </p>\r
1628 </li>\r
1629 <li>\r
1630 <p>\r
1631 <a href="https://github.com/ziberna/i3-py">https://github.com/ziberna/i3-py</a> (not maintained)\r
1632 </p>\r
1633 </li>\r
1634 </ul></div>\r
1635 </dd>\r
1636 <dt class="hdlist1">\r
1637 Ruby\r
1638 </dt>\r
1639 <dd>\r
1640 <div class="ulist"><ul>\r
1641 <li>\r
1642 <p>\r
1643 <a href="https://github.com/veelenga/i3ipc-ruby">https://github.com/veelenga/i3ipc-ruby</a>\r
1644 </p>\r
1645 </li>\r
1646 <li>\r
1647 <p>\r
1648 <a href="https://github.com/badboy/i3-ipc">https://github.com/badboy/i3-ipc</a> (not maintained)\r
1649 </p>\r
1650 </li>\r
1651 </ul></div>\r
1652 </dd>\r
1653 <dt class="hdlist1">\r
1654 Rust\r
1655 </dt>\r
1656 <dd>\r
1657 <div class="ulist"><ul>\r
1658 <li>\r
1659 <p>\r
1660 <a href="https://github.com/tmerr/i3ipc-rs">https://github.com/tmerr/i3ipc-rs</a>\r
1661 </p>\r
1662 </li>\r
1663 </ul></div>\r
1664 </dd>\r
1665 <dt class="hdlist1">\r
1666 OCaml\r
1667 </dt>\r
1668 <dd>\r
1669 <div class="ulist"><ul>\r
1670 <li>\r
1671 <p>\r
1672 <a href="https://github.com/Armael/ocaml-i3ipc">https://github.com/Armael/ocaml-i3ipc</a>\r
1673 </p>\r
1674 </li>\r
1675 </ul></div>\r
1676 </dd>\r
1677 </dl></div>\r
1678 </div>\r
1679 </div>\r
1680 <div class="sect1">\r
1681 <h2 id="_appendix_a_detecting_byte_order_in_memory_safe_languages">6. Appendix A: Detecting byte order in memory-safe languages</h2>\r
1682 <div class="sectionbody">\r
1683 <div class="paragraph"><p>Some programming languages such as Go don’t offer a way to serialize data in the\r
1684 native byte order of the machine they’re running on without resorting to tricks\r
1685 involving the <tt>unsafe</tt> package.</p></div>\r
1686 <div class="paragraph"><p>The following technique can be used (and will not be broken by changes to i3) to\r
1687 detect the byte order i3 is using:</p></div>\r
1688 <div class="olist arabic"><ol class="arabic">\r
1689 <li>\r
1690 <p>\r
1691 The byte order dependent fields of an IPC message are message type and\r
1692    payload length.\r
1693 </p>\r
1694 <div class="ulist"><ul>\r
1695 <li>\r
1696 <p>\r
1697 The message type <tt>RUN_COMMAND</tt> (0) is the same in big and little endian, so\r
1698      we can use it in either byte order to elicit a reply from i3.\r
1699 </p>\r
1700 </li>\r
1701 <li>\r
1702 <p>\r
1703 The payload length 65536 + 256 (<tt>0x00 01 01 00</tt>) is the same in big and\r
1704      little endian, and also small enough to not worry about memory allocations\r
1705      of that size. We must use payloads of length 65536 + 256 in every message\r
1706      we send, so that i3 will be able to read the entire message regardless of\r
1707      the byte order it uses.\r
1708 </p>\r
1709 </li>\r
1710 </ul></div>\r
1711 </li>\r
1712 <li>\r
1713 <p>\r
1714 Send a big endian encoded message of type <tt>SUBSCRIBE</tt> (2) with payload <tt>[]</tt>\r
1715    followed by 65536 + 256 - 2 <tt>SPACE</tt> (ASCII 0x20) bytes.\r
1716 </p>\r
1717 <div class="ulist"><ul>\r
1718 <li>\r
1719 <p>\r
1720 If i3 is running in big endian, this message is treated as a noop,\r
1721      resulting in a <tt>SUBSCRIBE</tt> reply with payload <tt>{"success":true}</tt>\r
1722      <span class="footnote"><br />[A small payload is important: that way, we circumvent dealing\r
1723      with UNIX domain socket buffer sizes, whose size depends on the\r
1724      implementation/operating system. Exhausting such a buffer results in an i3\r
1725      deadlock unless you concurrently read and write, which — depending on the\r
1726      programming language — makes the technique much more complicated.]<br /></span>.\r
1727 </p>\r
1728 </li>\r
1729 <li>\r
1730 <p>\r
1731 If i3 is running in little endian, this message is read in its entirety due\r
1732      to the byte order independent payload length, then\r
1733      <a href="https://github.com/i3/i3/blob/d726d09d496577d1c337a4b97486f2c9fbc914f1/src/ipc.c#L1188">silently\r
1734      discarded</a> due to the unknown message type.\r
1735 </p>\r
1736 </li>\r
1737 </ul></div>\r
1738 </li>\r
1739 <li>\r
1740 <p>\r
1741 Send a byte order independent message, i.e. type <tt>RUN_COMMAND</tt> (0) with\r
1742    payload <tt>nop byte order detection. padding:</tt>, padded to 65536 + 256 bytes\r
1743    with <tt>a</tt> (ASCII 0x61) bytes. i3 will reply to this message with a reply of\r
1744    type <tt>COMMAND</tt> (0).\r
1745 </p>\r
1746 <div class="ulist"><ul>\r
1747 <li>\r
1748 <p>\r
1749 The human-readable prefix is in there to not confuse readers of the i3 log.\r
1750 </p>\r
1751 </li>\r
1752 <li>\r
1753 <p>\r
1754 This messages serves as a synchronization primitive so that we know whether\r
1755      i3 discarded the <tt>SUBSCRIBE</tt> message or didn’t answer it yet.\r
1756 </p>\r
1757 </li>\r
1758 </ul></div>\r
1759 </li>\r
1760 <li>\r
1761 <p>\r
1762 Receive a message header from i3, decoding the message type as big endian.\r
1763 </p>\r
1764 <div class="ulist"><ul>\r
1765 <li>\r
1766 <p>\r
1767 If the message’s reply type is <tt>COMMAND</tt> (0), i3 is running in little\r
1768      endian (because the <tt>SUBSCRIBE</tt> message was discarded). Decode the message\r
1769      payload length as little endian, receive the message payload.\r
1770 </p>\r
1771 </li>\r
1772 <li>\r
1773 <p>\r
1774 If the message’s reply type is anything else, i3 is running in big endian\r
1775      (because our big endian encoded <tt>SUBSCRIBE</tt> message was answered). Decode\r
1776      the message payload length in big endian, receive the message\r
1777      payload. Then, receive the pending <tt>COMMAND</tt> message reply in big endian.\r
1778 </p>\r
1779 </li>\r
1780 </ul></div>\r
1781 </li>\r
1782 <li>\r
1783 <p>\r
1784 From here on out, send/receive all messages using the detected byte order.\r
1785 </p>\r
1786 </li>\r
1787 </ol></div>\r
1788 </div>\r
1789 </div>\r
1790 </div>\r
1791 <div id="footnotes"><hr /></div>\r
1792 <div id="footer" lang="de">\r
1793 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>\r
1794 </div>\r
1795 </body>\r
1796 </html>\r