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
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
13 document.addEventListener("DOMContentLoaded", function(){asciidoc.footnotes(); asciidoc.toc(2);}, false);
\r
16 <script type="text/javascript" src="/js/asciidoc-xhtml11.js"></script>
\r
18 <body class="article">
\r
21 <a href="/"><h1 id="title">i3 - improved tiling WM</h1></a>
\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
29 <br style="clear: both">
\r
32 <h1>IPC interface (interprocess communication)</h1>
\r
33 <span id="author">Michael Stapelberg</span><br />
\r
34 <span id="email"><tt><<a href="mailto:michael@i3wm.org">michael@i3wm.org</a>></tt></span><br />
\r
35 <span id="revdate">October 2014</span>
\r
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>
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
59 <div class="title">Warning</div>
\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
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->new(Peer => $path);</tt></pre>
\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="paragraph"><p>Currently implemented message types are the following:</p></div>
\r
96 <div class="dlist"><dl>
\r
97 <dt class="hdlist1">
\r
102 The payload of the message is a command for i3 (like the commands you
\r
103 can bind to keys in the configuration file) and will be executed
\r
104 directly after receiving it.
\r
107 <dt class="hdlist1">
\r
112 Gets the current workspaces. The reply will be a JSON-encoded list of
\r
113 workspaces (see the reply section).
\r
116 <dt class="hdlist1">
\r
121 Subscribes your connection to certain events. See <a href="#events">[events]</a> for a
\r
122 description of this message and the concept of events.
\r
125 <dt class="hdlist1">
\r
130 Gets the current outputs. The reply will be a JSON-encoded list of outputs
\r
131 (see the reply section).
\r
134 <dt class="hdlist1">
\r
139 Gets the layout tree. i3 uses a tree as data structure which includes
\r
140 every container. The reply will be the JSON-encoded tree (see the reply
\r
144 <dt class="hdlist1">
\r
149 Gets a list of marks (identifiers for containers to easily jump to them
\r
150 later). The reply will be a JSON-encoded list of window marks (see
\r
154 <dt class="hdlist1">
\r
159 Gets the configuration (as JSON map) of the workspace bar with the
\r
160 given ID. If no ID is provided, an array with all configured bar IDs is
\r
164 <dt class="hdlist1">
\r
169 Gets the version of i3. The reply will be a JSON-encoded dictionary
\r
170 with the major, minor, patch and human-readable version.
\r
173 <dt class="hdlist1">
\r
174 GET_BINDING_MODES (8)
\r
178 Gets a list of currently configured binding modes.
\r
182 <div class="paragraph"><p>So, a typical message could look like this:</p></div>
\r
183 <div class="listingblock">
\r
184 <div class="content">
\r
185 <pre><tt>"i3-ipc" <message length> <message type> <payload></tt></pre>
\r
187 <div class="paragraph"><p>Or, as a hexdump:</p></div>
\r
188 <div class="listingblock">
\r
189 <div class="content">
\r
190 <pre><tt>00000000 69 33 2d 69 70 63 04 00 00 00 00 00 00 00 65 78 |i3-ipc........ex|
\r
191 00000010 69 74 |it|</tt></pre>
\r
193 <div class="paragraph"><p>To generate and send such a message, you could use the following code in Perl:</p></div>
\r
194 <div class="listingblock">
\r
195 <div class="content">
\r
196 <pre><tt>sub format_ipc_command {
\r
199 # Get the real byte count (vs. amount of characters)
\r
200 { use bytes; $len = length($msg); }
\r
201 return "i3-ipc" . pack("LL", $len, 0) . $msg;
\r
204 $sock->write(format_ipc_command("exit"));</tt></pre>
\r
208 <div class="sect1">
\r
209 <h2 id="_receiving_replies_from_i3">3. Receiving replies from i3</h2>
\r
210 <div class="sectionbody">
\r
211 <div class="paragraph"><p>Replies from i3 usually consist of a simple string (the length of the string
\r
212 is the message_length, so you can consider them length-prefixed) which in turn
\r
213 contain the JSON serialization of a data structure. For example, the
\r
214 GET_WORKSPACES message returns an array of workspaces (each workspace is a map
\r
215 with certain attributes).</p></div>
\r
216 <div class="sect2">
\r
217 <h3 id="_reply_format">3.1. Reply format</h3>
\r
218 <div class="paragraph"><p>The reply format is identical to the normal message format. There also is
\r
219 the magic string, then the message length, then the message type and the
\r
221 <div class="paragraph"><p>The following reply types are implemented:</p></div>
\r
222 <div class="dlist"><dl>
\r
223 <dt class="hdlist1">
\r
228 Confirmation/Error code for the COMMAND message.
\r
231 <dt class="hdlist1">
\r
236 Reply to the GET_WORKSPACES message.
\r
239 <dt class="hdlist1">
\r
244 Confirmation/Error code for the SUBSCRIBE message.
\r
247 <dt class="hdlist1">
\r
252 Reply to the GET_OUTPUTS message.
\r
255 <dt class="hdlist1">
\r
260 Reply to the GET_TREE message.
\r
263 <dt class="hdlist1">
\r
268 Reply to the GET_MARKS message.
\r
271 <dt class="hdlist1">
\r
276 Reply to the GET_BAR_CONFIG message.
\r
279 <dt class="hdlist1">
\r
284 Reply to the GET_VERSION message.
\r
287 <dt class="hdlist1">
\r
292 Reply to the GET_BINDING_MODES message.
\r
297 <div class="sect2">
\r
298 <h3 id="_command_reply">3.2. COMMAND reply</h3>
\r
299 <div class="paragraph"><p>The reply consists of a list of serialized maps for each command that was
\r
300 parsed. Each has the property <tt>success (bool)</tt> and may also include a
\r
301 human-readable error message in the property <tt>error (string)</tt>.</p></div>
\r
302 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
303 <div class="listingblock">
\r
304 <div class="content">
\r
305 <pre><tt>[{ "success": true }]</tt></pre>
\r
308 <div class="sect2">
\r
309 <h3 id="_workspaces_reply">3.3. WORKSPACES reply</h3>
\r
310 <div class="paragraph"><p>The reply consists of a serialized list of workspaces. Each workspace has the
\r
311 following properties:</p></div>
\r
312 <div class="dlist"><dl>
\r
313 <dt class="hdlist1">
\r
318 The logical number of the workspace. Corresponds to the command
\r
319 to switch to this workspace. For named workspaces, this will be -1.
\r
322 <dt class="hdlist1">
\r
327 The name of this workspace (by default num+1), as changed by the
\r
328 user. Encoded in UTF-8.
\r
331 <dt class="hdlist1">
\r
336 Whether this workspace is currently visible on an output (multiple
\r
337 workspaces can be visible at the same time).
\r
340 <dt class="hdlist1">
\r
345 Whether this workspace currently has the focus (only one workspace
\r
346 can have the focus at the same time).
\r
349 <dt class="hdlist1">
\r
354 Whether a window on this workspace has the "urgent" flag set.
\r
357 <dt class="hdlist1">
\r
362 The rectangle of this workspace (equals the rect of the output it
\r
363 is on), consists of x, y, width, height.
\r
366 <dt class="hdlist1">
\r
371 The video output this workspace is on (LVDS1, VGA1, …).
\r
375 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
376 <div class="listingblock">
\r
377 <div class="content">
\r
410 <div class="sect2">
\r
411 <h3 id="_subscribe_reply">3.4. SUBSCRIBE reply</h3>
\r
412 <div class="paragraph"><p>The reply consists of a single serialized map. The only property is
\r
413 <tt>success (bool)</tt>, indicating whether the subscription was successful (the
\r
414 default) or whether a JSON parse error occurred.</p></div>
\r
415 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
416 <div class="listingblock">
\r
417 <div class="content">
\r
418 <pre><tt>{ "success": true }</tt></pre>
\r
421 <div class="sect2">
\r
422 <h3 id="_outputs_reply">3.5. OUTPUTS reply</h3>
\r
423 <div class="paragraph"><p>The reply consists of a serialized list of outputs. Each output has the
\r
424 following properties:</p></div>
\r
425 <div class="dlist"><dl>
\r
426 <dt class="hdlist1">
\r
431 The name of this output (as seen in <tt>xrandr(1)</tt>). Encoded in UTF-8.
\r
434 <dt class="hdlist1">
\r
439 Whether this output is currently active (has a valid mode).
\r
442 <dt class="hdlist1">
\r
443 current_workspace (string)
\r
447 The name of the current workspace that is visible on this output. <tt>null</tt> if
\r
448 the output is not active.
\r
451 <dt class="hdlist1">
\r
456 The rectangle of this output (equals the rect of the output it
\r
457 is on), consists of x, y, width, height.
\r
461 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
462 <div class="listingblock">
\r
463 <div class="content">
\r
468 "current_workspace": "4",
\r
479 "current_workspace": "1",
\r
490 <div class="sect2">
\r
491 <h3 id="_tree_reply">3.6. TREE reply</h3>
\r
492 <div class="paragraph"><p>The reply consists of a serialized tree. Each node in the tree (representing
\r
493 one container) has at least the properties listed below. While the nodes might
\r
494 have more properties, please do not use any properties which are not documented
\r
495 here. They are not yet finalized and will probably change!</p></div>
\r
496 <div class="dlist"><dl>
\r
497 <dt class="hdlist1">
\r
502 The internal ID (actually a C pointer value) of this container. Do not
\r
503 make any assumptions about it. You can use it to (re-)identify and
\r
504 address containers when talking to i3.
\r
507 <dt class="hdlist1">
\r
512 The internal name of this container. For all containers which are part
\r
513 of the tree structure down to the workspace contents, this is set to a
\r
514 nice human-readable name of the container.
\r
515 For containers that have an X11 window, the content is the title
\r
516 (_NET_WM_NAME property) of that window.
\r
517 For all other containers, the content is not defined (yet).
\r
520 <dt class="hdlist1">
\r
525 Type of this container. Can be one of "root", "output", "con",
\r
526 "floating_con", "workspace" or "dockarea".
\r
529 <dt class="hdlist1">
\r
534 Can be either "normal", "none" or "pixel", depending on the
\r
535 container’s border style.
\r
538 <dt class="hdlist1">
\r
539 current_border_width (integer)
\r
543 Number of pixels of the border width.
\r
546 <dt class="hdlist1">
\r
551 Can be either "splith", "splitv", "stacked", "tabbed", "dockarea" or
\r
553 Other values might be possible in the future, should we add new
\r
557 <dt class="hdlist1">
\r
558 orientation (string)
\r
562 Can be either "none" (for non-split containers), "horizontal" or
\r
564 THIS FIELD IS OBSOLETE. It is still present, but your code should not
\r
565 use it. Instead, rely on the layout field.
\r
568 <dt class="hdlist1">
\r
573 The percentage which this container takes in its parent. A value of
\r
574 <tt>null</tt> means that the percent property does not make sense for this
\r
575 container, for example for the root container.
\r
578 <dt class="hdlist1">
\r
583 The absolute display coordinates for this container. Display
\r
584 coordinates means that when you have two 1600x1200 monitors on a single
\r
585 X11 Display (the standard way), the coordinates of the first window on
\r
586 the second monitor are <tt>{ "x": 1600, "y": 0, "width": 1600, "height":
\r
590 <dt class="hdlist1">
\r
595 The coordinates of the <strong>actual client window</strong> inside its container.
\r
596 These coordinates are relative to the container and do not include the
\r
597 window decoration (which is actually rendered on the parent container).
\r
598 So, when using the <tt>default</tt> layout, you will have a 2 pixel border on
\r
599 each side, making the window_rect <tt>{ "x": 2, "y": 0, "width": 632,
\r
600 "height": 366 }</tt> (for example).
\r
603 <dt class="hdlist1">
\r
608 The coordinates of the <strong>window decoration</strong> inside its container. These
\r
609 coordinates are relative to the container and do not include the actual
\r
613 <dt class="hdlist1">
\r
618 The original geometry the window specified when i3 mapped it. Used when
\r
619 switching a window to floating mode, for example.
\r
622 <dt class="hdlist1">
\r
627 The X11 window ID of the <strong>actual client window</strong> inside this container.
\r
628 This field is set to null for split containers or otherwise empty
\r
629 containers. This ID corresponds to what xwininfo(1) and other
\r
630 X11-related tools display (usually in hex).
\r
633 <dt class="hdlist1">
\r
638 Whether this container (window or workspace) has the urgency hint set.
\r
641 <dt class="hdlist1">
\r
646 Whether this container is currently focused.
\r
650 <div class="paragraph"><p>Please note that in the following example, I have left out some keys/values
\r
651 which are not relevant for the type of the node. Otherwise, the example would
\r
652 be by far too long (it already is quite long, despite showing only 1 window and
\r
653 one dock window).</p></div>
\r
654 <div class="paragraph"><p>It is useful to have an overview of the structure before taking a look at the
\r
655 JSON dump:</p></div>
\r
656 <div class="ulist"><ul>
\r
661 <div class="ulist"><ul>
\r
666 <div class="ulist"><ul>
\r
676 <div class="ulist"><ul>
\r
681 <div class="ulist"><ul>
\r
695 <div class="ulist"><ul>
\r
713 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
714 <div class="listingblock">
\r
715 <div class="content">
\r
730 "layout": "output",
\r
742 "layout": "dockarea",
\r
743 "orientation": "vertical",
\r
766 "orientation": "horizontal",
\r
773 "floating_nodes": [],
\r
779 "border": "normal",
\r
797 "name": "bottomdock",
\r
798 "layout": "dockarea",
\r
799 "orientation": "vertical",
\r
828 <div class="sect2">
\r
829 <h3 id="_marks_reply">3.7. MARKS reply</h3>
\r
830 <div class="paragraph"><p>The reply consists of a single array of strings for each container that has a
\r
831 mark. A mark can only be set on one container, so the array is unique.
\r
832 The order of that array is undefined.</p></div>
\r
833 <div class="paragraph"><p>If no window has a mark the response will be the empty array [].</p></div>
\r
835 <div class="sect2">
\r
836 <h3 id="_bar_config_reply">3.8. BAR_CONFIG reply</h3>
\r
837 <div class="paragraph"><p>This can be used by third-party workspace bars (especially i3bar, but others
\r
838 are free to implement compatible alternatives) to get the <tt>bar</tt> block
\r
839 configuration from i3.</p></div>
\r
840 <div class="paragraph"><p>Depending on the input, the reply is either:</p></div>
\r
841 <div class="dlist"><dl>
\r
842 <dt class="hdlist1">
\r
847 An array of configured bar IDs
\r
850 <dt class="hdlist1">
\r
855 A JSON map containing the configuration for the specified bar.
\r
859 <div class="paragraph"><p>Each bar configuration has the following properties:</p></div>
\r
860 <div class="dlist"><dl>
\r
861 <dt class="hdlist1">
\r
866 The ID for this bar. Included in case you request multiple
\r
867 configurations and want to differentiate the different replies.
\r
870 <dt class="hdlist1">
\r
875 Either <tt>dock</tt> (the bar sets the dock window type) or <tt>hide</tt> (the bar
\r
876 does not show unless a specific key is pressed).
\r
879 <dt class="hdlist1">
\r
884 Either <tt>bottom</tt> or <tt>top</tt> at the moment.
\r
887 <dt class="hdlist1">
\r
888 status_command (string)
\r
892 Command which will be run to generate a statusline. Each line on stdout
\r
893 of this command will be displayed in the bar. At the moment, no
\r
894 formatting is supported.
\r
897 <dt class="hdlist1">
\r
902 The font to use for text on the bar.
\r
905 <dt class="hdlist1">
\r
906 workspace_buttons (boolean)
\r
910 Display workspace buttons or not? Defaults to true.
\r
913 <dt class="hdlist1">
\r
914 binding_mode_indicator (boolean)
\r
918 Display the mode indicator or not? Defaults to true.
\r
921 <dt class="hdlist1">
\r
926 Should the bar enable verbose output for debugging? Defaults to false.
\r
929 <dt class="hdlist1">
\r
934 Contains key/value pairs of colors. Each value is a color code in hex,
\r
935 formatted #rrggbb (like in HTML).
\r
939 <div class="paragraph"><p>The following colors can be configured at the moment:</p></div>
\r
940 <div class="dlist"><dl>
\r
941 <dt class="hdlist1">
\r
946 Background color of the bar.
\r
949 <dt class="hdlist1">
\r
954 Text color to be used for the statusline.
\r
957 <dt class="hdlist1">
\r
962 Text color to be used for the separator.
\r
965 <dt class="hdlist1">
\r
970 Background color of the bar on the currently focused monitor output.
\r
973 <dt class="hdlist1">
\r
978 Text color to be used for the statusline on the currently focused
\r
982 <dt class="hdlist1">
\r
987 Text color to be used for the separator on the currently focused
\r
991 <dt class="hdlist1">
\r
992 focused_workspace_text/focused_workspace_bg/focused_workspace_border
\r
996 Text/background/border color for a workspace button when the workspace
\r
1000 <dt class="hdlist1">
\r
1001 active_workspace_text/active_workspace_bg/active_workspace_border
\r
1005 Text/background/border color for a workspace button when the workspace
\r
1006 is active (visible) on some output, but the focus is on another one.
\r
1007 You can only tell this apart from the focused workspace when you are
\r
1008 using multiple monitors.
\r
1011 <dt class="hdlist1">
\r
1012 inactive_workspace_text/inactive_workspace_bg/inactive_workspace_border
\r
1016 Text/background/border color for a workspace button when the workspace
\r
1017 does not have focus and is not active (visible) on any output. This
\r
1018 will be the case for most workspaces.
\r
1021 <dt class="hdlist1">
\r
1022 urgent_workspace_text/urgent_workspace_bg/urgent_workspace_border
\r
1026 Text/background/border color for workspaces which contain at least one
\r
1027 window with the urgency hint set.
\r
1030 <dt class="hdlist1">
\r
1031 binding_mode_text/binding_mode_bg/binding_mode_border
\r
1035 Text/background/border color for the binding mode indicator.
\r
1039 <div class="paragraph"><p><strong>Example of configured bars:</strong></p></div>
\r
1040 <div class="listingblock">
\r
1041 <div class="content">
\r
1042 <pre><tt>["bar-bxuqzf"]</tt></pre>
\r
1044 <div class="paragraph"><p><strong>Example of bar configuration:</strong></p></div>
\r
1045 <div class="listingblock">
\r
1046 <div class="content">
\r
1048 "id": "bar-bxuqzf",
\r
1050 "position": "bottom",
\r
1051 "status_command": "i3status",
\r
1052 "font": "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1",
\r
1053 "workspace_buttons": true,
\r
1054 "binding_mode_indicator": true,
\r
1057 "background": "#c0c0c0",
\r
1058 "statusline": "#00ff00",
\r
1059 "focused_workspace_text": "#ffffff",
\r
1060 "focused_workspace_bg": "#000000"
\r
1065 <div class="sect2">
\r
1066 <h3 id="_version_reply">3.9. VERSION reply</h3>
\r
1067 <div class="paragraph"><p>The reply consists of a single JSON dictionary with the following keys:</p></div>
\r
1068 <div class="dlist"><dl>
\r
1069 <dt class="hdlist1">
\r
1074 The major version of i3, such as <tt>4</tt>.
\r
1077 <dt class="hdlist1">
\r
1082 The minor version of i3, such as <tt>2</tt>. Changes in the IPC interface (new
\r
1083 features) will only occur with new minor (or major) releases. However,
\r
1084 bugfixes might be introduced in patch releases, too.
\r
1087 <dt class="hdlist1">
\r
1092 The patch version of i3, such as <tt>1</tt> (when the complete version is
\r
1093 <tt>4.2.1</tt>). For versions such as <tt>4.2</tt>, patch will be set to <tt>0</tt>.
\r
1096 <dt class="hdlist1">
\r
1097 human_readable (string)
\r
1101 A human-readable version of i3 containing the precise git version,
\r
1102 build date and branch name. When you need to display the i3 version to
\r
1103 your users, use the human-readable version whenever possible (since
\r
1104 this is what <tt>i3 --version</tt> displays, too).
\r
1107 <dt class="hdlist1">
\r
1108 loaded_config_file_name (string)
\r
1112 The current config path.
\r
1116 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
1117 <div class="listingblock">
\r
1118 <div class="content">
\r
1120 "human_readable" : "4.2-169-gf80b877 (2012-08-05, branch \"next\")",
\r
1121 "loaded_config_file_name" : "/home/hwangcc23/.i3/config",
\r
1128 <div class="sect2">
\r
1129 <h3 id="_binding_modes_reply">3.10. BINDING_MODES reply</h3>
\r
1130 <div class="paragraph"><p>The reply consists of an array of all currently configured binding modes.</p></div>
\r
1131 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
1132 <div class="listingblock">
\r
1133 <div class="content">
\r
1134 <pre><tt>["default", "resize"]</tt></pre>
\r
1139 <div class="sect1">
\r
1140 <h2 id="_events">4. Events</h2>
\r
1141 <div class="sectionbody">
\r
1142 <div class="paragraph" id="events"><p>To get informed when certain things happen in i3, clients can subscribe to
\r
1143 events. Events consist of a name (like "workspace") and an event reply type
\r
1144 (like I3_IPC_EVENT_WORKSPACE). The events sent by i3 are in the same format
\r
1145 as replies to specific commands. However, the highest bit of the message type
\r
1146 is set to 1 to indicate that this is an event reply instead of a normal reply.</p></div>
\r
1147 <div class="paragraph"><p>Caveat: As soon as you subscribe to an event, it is not guaranteed any longer
\r
1148 that the requests to i3 are processed in order. This means, the following
\r
1149 situation can happen: You send a GET_WORKSPACES request but you receive a
\r
1150 "workspace" event before receiving the reply to GET_WORKSPACES. If your
\r
1151 program does not want to cope which such kinds of race conditions (an
\r
1152 event based library may not have a problem here), I suggest you create a
\r
1153 separate connection to receive events.</p></div>
\r
1154 <div class="sect2">
\r
1155 <h3 id="_subscribing_to_events">4.1. Subscribing to events</h3>
\r
1156 <div class="paragraph"><p>By sending a message of type SUBSCRIBE with a JSON-encoded array as payload
\r
1157 you can register to an event.</p></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>type: SUBSCRIBE
\r
1162 payload: [ "workspace", "output" ]</tt></pre>
\r
1165 <div class="sect2">
\r
1166 <h3 id="_available_events">4.2. Available events</h3>
\r
1167 <div class="paragraph"><p>The numbers in parenthesis is the event type (keep in mind that you need to
\r
1168 strip the highest bit first).</p></div>
\r
1169 <div class="dlist"><dl>
\r
1170 <dt class="hdlist1">
\r
1175 Sent when the user switches to a different workspace, when a new
\r
1176 workspace is initialized or when a workspace is removed (because the
\r
1177 last client vanished).
\r
1180 <dt class="hdlist1">
\r
1185 Sent when RandR issues a change notification (of either screens,
\r
1186 outputs, CRTCs or output properties).
\r
1189 <dt class="hdlist1">
\r
1194 Sent whenever i3 changes its binding mode.
\r
1197 <dt class="hdlist1">
\r
1202 Sent when a client’s window is successfully reparented (that is when i3
\r
1203 has finished fitting it into a container), when a window received input
\r
1204 focus or when certain properties of the window have changed.
\r
1207 <dt class="hdlist1">
\r
1208 barconfig_update (4)
\r
1212 Sent when the hidden_state or mode field in the barconfig of any bar
\r
1213 instance was updated and when the config is reloaded.
\r
1216 <dt class="hdlist1">
\r
1221 Sent when a configured command binding is triggered with the keyboard or
\r
1226 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
1227 <div class="listingblock">
\r
1228 <div class="content">
\r
1229 <pre><tt># the appropriate 4 bytes read from the socket are stored in $input
\r
1231 # unpack a 32-bit unsigned integer
\r
1232 my $message_type = unpack("L", $input);
\r
1234 # check if the highest bit is 1
\r
1235 my $is_event = (($message_type >> 31) == 1);
\r
1237 # use the other bits
\r
1238 my $event_type = ($message_type & 0x7F);
\r
1241 say "Received event of type $event_type";
\r
1245 <div class="sect2">
\r
1246 <h3 id="_workspace_event">4.3. workspace event</h3>
\r
1247 <div class="paragraph"><p>This event consists of a single serialized map containing a property
\r
1248 <tt>change (string)</tt> which indicates the type of the change ("focus", "init",
\r
1249 "empty", "urgent"). A <tt>current (object)</tt> property will be present with the
\r
1250 affected workspace whenever the type of event affects a workspace (otherwise,
\r
1251 it will be +null).</p></div>
\r
1252 <div class="paragraph"><p>When the change is "focus", an <tt>old (object)</tt> property will be present with the
\r
1253 previous workspace. When the first switch occurs (when i3 focuses the
\r
1254 workspace visible at the beginning) there is no previous workspace, and the
\r
1255 <tt>old</tt> property will be set to <tt>null</tt>. Also note that if the previous is empty
\r
1256 it will get destroyed when switching, but will still be present in the "old"
\r
1257 property.</p></div>
\r
1258 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
1259 <div class="listingblock">
\r
1260 <div class="content">
\r
1262 "change": "focus",
\r
1265 "type": "workspace",
\r
1270 "type": "workspace",
\r
1276 <div class="sect2">
\r
1277 <h3 id="_output_event">4.4. output event</h3>
\r
1278 <div class="paragraph"><p>This event consists of a single serialized map containing a property
\r
1279 <tt>change (string)</tt> which indicates the type of the change (currently only
\r
1280 "unspecified").</p></div>
\r
1281 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
1282 <div class="listingblock">
\r
1283 <div class="content">
\r
1284 <pre><tt>{ "change": "unspecified" }</tt></pre>
\r
1287 <div class="sect2">
\r
1288 <h3 id="_mode_event">4.5. mode event</h3>
\r
1289 <div class="paragraph"><p>This event consists of a single serialized map containing a property
\r
1290 <tt>change (string)</tt> which holds the name of current mode in use. The name
\r
1291 is the same as specified in config when creating a mode. The default
\r
1292 mode is simply named default. It contains a second property, <tt>pango_markup</tt>, which
\r
1293 defines whether pango markup shall be used for displaying this mode.</p></div>
\r
1294 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
1295 <div class="listingblock">
\r
1296 <div class="content">
\r
1298 "change": "default",
\r
1299 "pango_markup": true
\r
1303 <div class="sect2">
\r
1304 <h3 id="_window_event">4.6. window event</h3>
\r
1305 <div class="paragraph"><p>This event consists of a single serialized map containing a property
\r
1306 <tt>change (string)</tt> which indicates the type of the change</p></div>
\r
1307 <div class="ulist"><ul>
\r
1310 <tt>new</tt> – the window has become managed by i3
\r
1315 <tt>close</tt> – the window has closed
\r
1320 <tt>focus</tt> – the window has received input focus
\r
1325 <tt>title</tt> – the window’s title has changed
\r
1330 <tt>fullscreen_mode</tt> – the window has entered or exited fullscreen mode
\r
1335 <tt>move</tt> – the window has changed its position in the tree
\r
1340 <tt>floating</tt> – the window has transitioned to or from floating
\r
1345 <tt>urgent</tt> – the window has become urgent or lost its urgent status
\r
1350 <tt>mark</tt> – a mark has been added to or removed from the window
\r
1354 <div class="paragraph"><p>Additionally a <tt>container (object)</tt> field will be present, which consists
\r
1355 of the window’s parent container. Be aware that for the "new" event, the
\r
1356 container will hold the initial name of the newly reparented window (e.g.
\r
1357 if you run urxvt with a shell that changes the title, you will still at
\r
1358 this point get the window title as "urxvt").</p></div>
\r
1359 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
1360 <div class="listingblock">
\r
1361 <div class="content">
\r
1372 <div class="sect2">
\r
1373 <h3 id="_barconfig_update_event">4.7. barconfig_update event</h3>
\r
1374 <div class="paragraph"><p>This event consists of a single serialized map reporting on options from the
\r
1375 barconfig of the specified bar_id that were updated in i3. This event is the
\r
1376 same as a <tt>GET_BAR_CONFIG</tt> reply for the bar with the given id.</p></div>
\r
1378 <div class="sect2">
\r
1379 <h3 id="_binding_event">4.8. binding event</h3>
\r
1380 <div class="paragraph"><p>This event consists of a single serialized map reporting on the details of a
\r
1381 binding that ran a command because of user input. The <tt>change (sring)</tt> field
\r
1382 indicates what sort of binding event was triggered (right now it will always be
\r
1383 <tt>"run"</tt> but may be expanded in the future).</p></div>
\r
1384 <div class="paragraph"><p>The <tt>binding (object)</tt> field contains details about the binding that was run:</p></div>
\r
1385 <div class="dlist"><dl>
\r
1386 <dt class="hdlist1">
\r
1391 The i3 command that is configured to run for this binding.
\r
1394 <dt class="hdlist1">
\r
1395 event_state_mask (array of strings)
\r
1399 The group and modifier keys that were configured with this binding.
\r
1402 <dt class="hdlist1">
\r
1403 input_code (integer)
\r
1407 If the binding was configured with <tt>bindcode</tt>, this will be the key code
\r
1408 that was given for the binding. If the binding is a mouse binding, it will be
\r
1409 the number of the mouse button that was pressed. Otherwise it will be 0.
\r
1412 <dt class="hdlist1">
\r
1413 symbol (string or null)
\r
1417 If this is a keyboard binding that was configured with <tt>bindsym</tt>, this
\r
1418 field will contain the given symbol. Otherwise it will be <tt>null</tt>.
\r
1421 <dt class="hdlist1">
\r
1422 input_type (string)
\r
1426 This will be <tt>"keyboard"</tt> or <tt>"mouse"</tt> depending on whether or not this was
\r
1427 a keyboard or a mouse binding.
\r
1431 <div class="paragraph"><p><strong>Example:</strong></p></div>
\r
1432 <div class="listingblock">
\r
1433 <div class="content">
\r
1438 "event_state_mask": [
\r
1444 "input_type": "keyboard"
\r
1451 <div class="sect1">
\r
1452 <h2 id="_see_also_existing_libraries">5. See also (existing libraries)</h2>
\r
1453 <div class="sectionbody">
\r
1454 <div class="paragraph" id="libraries"><p>For some languages, libraries are available (so you don’t have to implement
\r
1455 all this on your own). This list names some (if you wrote one, please let me
\r
1457 <div class="dlist"><dl>
\r
1458 <dt class="hdlist1">
\r
1462 <div class="ulist"><ul>
\r
1465 i3 includes a headerfile <tt>i3/ipc.h</tt> which provides you all constants.
\r
1470 <a href="https://github.com/acrisci/i3ipc-glib">https://github.com/acrisci/i3ipc-glib</a>
\r
1475 <dt class="hdlist1">
\r
1479 <div class="ulist"><ul>
\r
1482 <a href="https://github.com/drmgc/i3ipcpp">https://github.com/drmgc/i3ipcpp</a>
\r
1487 <dt class="hdlist1">
\r
1491 <div class="ulist"><ul>
\r
1494 <a href="https://github.com/proxypoke/i3ipc">https://github.com/proxypoke/i3ipc</a>
\r
1499 <dt class="hdlist1">
\r
1503 <div class="ulist"><ul>
\r
1506 <a href="https://github.com/acrisci/i3ipc-gjs">https://github.com/acrisci/i3ipc-gjs</a>
\r
1511 <dt class="hdlist1">
\r
1515 <div class="ulist"><ul>
\r
1518 <a href="https://github.com/acrisci/i3ipc-lua">https://github.com/acrisci/i3ipc-lua</a>
\r
1523 <dt class="hdlist1">
\r
1527 <div class="ulist"><ul>
\r
1530 <a href="https://metacpan.org/module/AnyEvent::I3">https://metacpan.org/module/AnyEvent::I3</a>
\r
1535 <dt class="hdlist1">
\r
1539 <div class="ulist"><ul>
\r
1542 <a href="https://github.com/acrisci/i3ipc-python">https://github.com/acrisci/i3ipc-python</a>
\r
1547 <a href="https://github.com/whitelynx/i3ipc">https://github.com/whitelynx/i3ipc</a> (not maintained)
\r
1552 <a href="https://github.com/ziberna/i3-py">https://github.com/ziberna/i3-py</a> (not maintained)
\r
1557 <dt class="hdlist1">
\r
1561 <div class="ulist"><ul>
\r
1564 <a href="https://github.com/veelenga/i3ipc-ruby">https://github.com/veelenga/i3ipc-ruby</a>
\r
1569 <a href="https://github.com/badboy/i3-ipc">https://github.com/badboy/i3-ipc</a> (not maintained)
\r
1574 <dt class="hdlist1">
\r
1578 <div class="ulist"><ul>
\r
1581 <a href="https://github.com/tmerr/i3ipc-rs">https://github.com/tmerr/i3ipc-rs</a>
\r
1590 <div id="footnotes"><hr /></div>
\r
1591 <div id="footer" lang="de">
\r
1592 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>
\r