]> git.sur5r.net Git - i3/i3/blob - docs/ipc
Merge pull request #3144 from DebianWall/guaketilda
[i3/i3] / docs / ipc
1 IPC interface (interprocess communication)
2 ==========================================
3 Michael Stapelberg <michael@i3wm.org>
4 September 2017
5
6 This document describes how to interface with i3 from a separate process. This
7 is useful for example to remote-control i3 (to write test cases for example) or
8 to get various information like the current workspaces to implement an external
9 workspace bar.
10
11 The method of choice for IPC in our case is a unix socket because it has very
12 little overhead on both sides and is usually available without headaches in
13 most languages. In the default configuration file, the ipc-socket gets created
14 in +/tmp/i3-%u.XXXXXX/ipc-socket.%p+ where +%u+ is your UNIX username, +%p+ is
15 the PID of i3 and XXXXXX is a string of random characters from the portable
16 filename character set (see mkdtemp(3)). You can get the socketpath from i3 by
17 calling +i3 --get-socketpath+.
18
19 All i3 utilities, like +i3-msg+ and +i3-input+ will read the +I3_SOCKET_PATH+
20 X11 property, stored on the X11 root window.
21
22 [WARNING]
23 .Use an existing library!
24 There are existing libraries for many languages. You can have a look at
25 <<libraries>> or search the web if your language of choice is not mentioned.
26 Usually, it is not necessary to implement low-level communication with i3
27 directly.
28
29 == Establishing a connection
30
31 To establish a connection, simply open the IPC socket. The following code
32 snippet illustrates this in Perl:
33
34 -------------------------------------------------------------
35 use IO::Socket::UNIX;
36 chomp(my $path = qx(i3 --get-socketpath));
37 my $sock = IO::Socket::UNIX->new(Peer => $path);
38 -------------------------------------------------------------
39
40 == Sending messages to i3
41
42 To send a message to i3, you have to format in the binary message format which
43 i3 expects. This format specifies a magic string in the beginning to ensure
44 the integrity of messages (to prevent follow-up errors). Following the magic
45 string comes the length of the payload of the message as 32-bit integer, and
46 the type of the message as 32-bit integer (the integers are not converted, so
47 they are in native byte order).
48
49 The magic string currently is "i3-ipc" and will only be changed when a change
50 in the IPC API is done which breaks compatibility (we hope that we don’t need
51 to do that).
52
53 .Currently implemented message types
54 [options="header",cols="^10%,^20%,^20%,^50%"]
55 |======================================================
56 | Type (numeric) | Type (name) | Reply type | Purpose
57 | 0 | +RUN_COMMAND+ | <<_command_reply,COMMAND>> | Run the payload as an i3 command (like the commands you can bind to keys).
58 | 1 | +GET_WORKSPACES+ | <<_workspaces_reply,WORKSPACES>> | Get the list of current workspaces.
59 | 2 | +SUBSCRIBE+ | <<_subscribe_reply,SUBSCRIBE>> | Subscribe this IPC connection to the event types specified in the message payload. See <<events>>.
60 | 3 | +GET_OUTPUTS+ | <<_outputs_reply,OUTPUTS>> | Get the list of current outputs.
61 | 4 | +GET_TREE+ | <<_tree_reply,TREE>> | Get the i3 layout tree.
62 | 5 | +GET_MARKS+ | <<_marks_reply,MARKS>> | Gets the names of all currently set marks.
63 | 6 | +GET_BAR_CONFIG+ | <<_bar_config_reply,BAR_CONFIG>> | Gets the specified bar configuration or the names of all bar configurations if payload is empty.
64 | 7 | +GET_VERSION+ | <<_version_reply,VERSION>> | Gets the i3 version.
65 | 8 | +GET_BINDING_MODES+ | <<_binding_modes_reply,BINDING_MODES>> | Gets the names of all currently configured binding modes.
66 | 9 | +GET_CONFIG+ | <<_config_reply,CONFIG>> | Returns the last loaded i3 config.
67 | 10 | +SEND_TICK+ | <<_tick_reply,TICK>> | Sends a tick event with the specified payload.
68 |======================================================
69
70 So, a typical message could look like this:
71 --------------------------------------------------
72 "i3-ipc" <message length> <message type> <payload>
73 --------------------------------------------------
74
75 Or, as a hexdump:
76 ------------------------------------------------------------------------------
77 00000000  69 33 2d 69 70 63 04 00  00 00 00 00 00 00 65 78  |i3-ipc........ex|
78 00000010  69 74                                             |it|
79 ------------------------------------------------------------------------------
80
81 To generate and send such a message, you could use the following code in Perl:
82 ------------------------------------------------------------
83 sub format_ipc_command {
84     my ($msg) = @_;
85     my $len;
86     # Get the real byte count (vs. amount of characters)
87     { use bytes; $len = length($msg); }
88     return "i3-ipc" . pack("LL", $len, 0) . $msg;
89 }
90
91 $sock->write(format_ipc_command("exit"));
92 ------------------------------------------------------------------------------
93
94 == Receiving replies from i3
95
96 Replies from i3 usually consist of a simple string (the length of the string
97 is the message_length, so you can consider them length-prefixed) which in turn
98 contain the JSON serialization of a data structure. For example, the
99 GET_WORKSPACES message returns an array of workspaces (each workspace is a map
100 with certain attributes).
101
102 === Reply format
103
104 The reply format is identical to the normal message format. There also is
105 the magic string, then the message length, then the message type and the
106 payload.
107
108 The following reply types are implemented:
109
110 COMMAND (0)::
111         Confirmation/Error code for the RUN_COMMAND message.
112 WORKSPACES (1)::
113         Reply to the GET_WORKSPACES message.
114 SUBSCRIBE (2)::
115         Confirmation/Error code for the SUBSCRIBE message.
116 OUTPUTS (3)::
117         Reply to the GET_OUTPUTS message.
118 TREE (4)::
119         Reply to the GET_TREE message.
120 MARKS (5)::
121         Reply to the GET_MARKS message.
122 BAR_CONFIG (6)::
123         Reply to the GET_BAR_CONFIG message.
124 VERSION (7)::
125         Reply to the GET_VERSION message.
126 BINDING_MODES (8)::
127         Reply to the GET_BINDING_MODES message.
128 GET_CONFIG (9)::
129         Reply to the GET_CONFIG message.
130 TICK (10)::
131         Reply to the SEND_TICK message.
132
133 [[_command_reply]]
134 === COMMAND reply
135
136 The reply consists of a list of serialized maps for each command that was
137 parsed. Each has the property +success (bool)+ and may also include a
138 human-readable error message in the property +error (string)+.
139
140 *Example:*
141 -------------------
142 [{ "success": true }]
143 -------------------
144
145 [[_workspaces_reply]]
146 === WORKSPACES reply
147
148 The reply consists of a serialized list of workspaces. Each workspace has the
149 following properties:
150
151 num (integer)::
152         The logical number of the workspace. Corresponds to the command
153         to switch to this workspace. For named workspaces, this will be -1.
154 name (string)::
155         The name of this workspace (by default num+1), as changed by the
156         user. Encoded in UTF-8.
157 visible (boolean)::
158         Whether this workspace is currently visible on an output (multiple
159         workspaces can be visible at the same time).
160 focused (boolean)::
161         Whether this workspace currently has the focus (only one workspace
162         can have the focus at the same time).
163 urgent (boolean)::
164         Whether a window on this workspace has the "urgent" flag set.
165 rect (map)::
166         The rectangle of this workspace (equals the rect of the output it
167         is on), consists of x, y, width, height.
168 output (string)::
169         The video output this workspace is on (LVDS1, VGA1, …).
170
171 *Example:*
172 -------------------
173 [
174  {
175   "num": 0,
176   "name": "1",
177   "visible": true,
178   "focused": true,
179   "urgent": false,
180   "rect": {
181    "x": 0,
182    "y": 0,
183    "width": 1280,
184    "height": 800
185   },
186   "output": "LVDS1"
187  },
188  {
189   "num": 1,
190   "name": "2",
191   "visible": false,
192   "focused": false,
193   "urgent": false,
194   "rect": {
195    "x": 0,
196    "y": 0,
197    "width": 1280,
198    "height": 800
199   },
200   "output": "LVDS1"
201  }
202 ]
203 -------------------
204
205 [[_subscribe_reply]]
206 === SUBSCRIBE reply
207
208 The reply consists of a single serialized map. The only property is
209 +success (bool)+, indicating whether the subscription was successful (the
210 default) or whether a JSON parse error occurred.
211
212 *Example:*
213 -------------------
214 { "success": true }
215 -------------------
216
217 [[_outputs_reply]]
218 === OUTPUTS reply
219
220 The reply consists of a serialized list of outputs. Each output has the
221 following properties:
222
223 name (string)::
224         The name of this output (as seen in +xrandr(1)+). Encoded in UTF-8.
225 active (boolean)::
226         Whether this output is currently active (has a valid mode).
227 primary (boolean)::
228         Whether this output is currently the primary output.
229 current_workspace (string)::
230         The name of the current workspace that is visible on this output. +null+ if
231         the output is not active.
232 rect (map)::
233         The rectangle of this output (equals the rect of the output it
234         is on), consists of x, y, width, height.
235
236 *Example:*
237 -------------------
238 [
239  {
240   "name": "LVDS1",
241   "active": true,
242   "current_workspace": "4",
243   "rect": {
244    "x": 0,
245    "y": 0,
246    "width": 1280,
247    "height": 800
248   }
249  },
250  {
251   "name": "VGA1",
252   "active": true,
253   "current_workspace": "1",
254   "rect": {
255    "x": 1280,
256    "y": 0,
257    "width": 1280,
258    "height": 1024
259   }
260  }
261 ]
262 -------------------
263
264 [[_tree_reply]]
265 === TREE reply
266
267 The reply consists of a serialized tree. Each node in the tree (representing
268 one container) has at least the properties listed below. While the nodes might
269 have more properties, please do not use any properties which are not documented
270 here. They are not yet finalized and will probably change!
271
272 id (integer)::
273         The internal ID (actually a C pointer value) of this container. Do not
274         make any assumptions about it. You can use it to (re-)identify and
275         address containers when talking to i3.
276 name (string)::
277         The internal name of this container. For all containers which are part
278         of the tree structure down to the workspace contents, this is set to a
279         nice human-readable name of the container.
280         For containers that have an X11 window, the content is the title
281         (_NET_WM_NAME property) of that window.
282         For all other containers, the content is not defined (yet).
283 type (string)::
284         Type of this container. Can be one of "root", "output", "con",
285         "floating_con", "workspace" or "dockarea".
286 border (string)::
287         Can be either "normal", "none" or "pixel", depending on the
288         container’s border style.
289 current_border_width (integer)::
290         Number of pixels of the border width.
291 layout (string)::
292         Can be either "splith", "splitv", "stacked", "tabbed", "dockarea" or
293         "output".
294         Other values might be possible in the future, should we add new
295         layouts.
296 orientation (string)::
297         Can be either "none" (for non-split containers), "horizontal" or
298         "vertical".
299         THIS FIELD IS OBSOLETE. It is still present, but your code should not
300         use it. Instead, rely on the layout field.
301 percent (float)::
302         The percentage which this container takes in its parent. A value of
303         +null+ means that the percent property does not make sense for this
304         container, for example for the root container.
305 rect (map)::
306         The absolute display coordinates for this container. Display
307         coordinates means that when you have two 1600x1200 monitors on a single
308         X11 Display (the standard way), the coordinates of the first window on
309         the second monitor are +{ "x": 1600, "y": 0, "width": 1600, "height":
310         1200 }+.
311 window_rect (map)::
312         The coordinates of the *actual client window* inside its container.
313         These coordinates are relative to the container and do not include the
314         window decoration (which is actually rendered on the parent container).
315         So, when using the +default+ layout, you will have a 2 pixel border on
316         each side, making the window_rect +{ "x": 2, "y": 0, "width": 632,
317         "height": 366 }+ (for example).
318 deco_rect (map)::
319         The coordinates of the *window decoration* inside its container. These
320         coordinates are relative to the container and do not include the actual
321         client window.
322 geometry (map)::
323         The original geometry the window specified when i3 mapped it. Used when
324         switching a window to floating mode, for example.
325 window (integer)::
326         The X11 window ID of the *actual client window* inside this container.
327         This field is set to null for split containers or otherwise empty
328         containers. This ID corresponds to what xwininfo(1) and other
329         X11-related tools display (usually in hex).
330 urgent (bool)::
331         Whether this container (window, split container, floating container or
332         workspace) has the urgency hint set, directly or indirectly. All parent
333         containers up until the workspace container will be marked urgent if they
334         have at least one urgent child.
335 focused (bool)::
336         Whether this container is currently focused.
337 focus (array of integer)::
338         List of child node IDs (see +nodes+, +floating_nodes+ and +id+) in focus
339         order. Traversing the tree by following the first entry in this array
340         will result in eventually reaching the one node with +focused+ set to
341         true.
342 nodes (array of node)::
343         The tiling (i.e. non-floating) child containers of this node.
344 floating_nodes (array of node)::
345         The floating child containers of this node. Only non-empty on nodes with
346         type +workspace+.
347
348 Please note that in the following example, I have left out some keys/values
349 which are not relevant for the type of the node. Otherwise, the example would
350 be by far too long (it already is quite long, despite showing only 1 window and
351 one dock window).
352
353 It is useful to have an overview of the structure before taking a look at the
354 JSON dump:
355
356 * root
357 ** LVDS1
358 *** topdock
359 *** content
360 **** workspace 1
361 ***** window 1
362 *** bottomdock
363 **** dock window 1
364 ** VGA1
365
366 *Example:*
367 -----------------------
368 {
369  "id": 6875648,
370  "name": "root",
371  "rect": {
372    "x": 0,
373    "y": 0,
374    "width": 1280,
375    "height": 800
376  },
377  "nodes": [
378
379    {
380     "id": 6878320,
381     "name": "LVDS1",
382     "layout": "output",
383     "rect": {
384       "x": 0,
385       "y": 0,
386       "width": 1280,
387       "height": 800
388     },
389     "nodes": [
390
391       {
392        "id": 6878784,
393        "name": "topdock",
394        "layout": "dockarea",
395        "orientation": "vertical",
396        "rect": {
397          "x": 0,
398          "y": 0,
399          "width": 1280,
400          "height": 0
401        }
402       },
403
404       {
405        "id": 6879344,
406        "name": "content",
407        "rect": {
408          "x": 0,
409          "y": 0,
410          "width": 1280,
411          "height": 782
412        },
413        "nodes": [
414
415          {
416           "id": 6880464,
417           "name": "1",
418           "orientation": "horizontal",
419           "rect": {
420             "x": 0,
421             "y": 0,
422             "width": 1280,
423             "height": 782
424           },
425           "floating_nodes": [],
426           "nodes": [
427
428             {
429              "id": 6929968,
430              "name": "#aa0000",
431              "border": "normal",
432              "percent": 1,
433              "rect": {
434                "x": 0,
435                "y": 18,
436                "width": 1280,
437                "height": 782
438              }
439             }
440
441           ]
442          }
443
444        ]
445       },
446
447       {
448        "id": 6880208,
449        "name": "bottomdock",
450        "layout": "dockarea",
451        "orientation": "vertical",
452        "rect": {
453          "x": 0,
454          "y": 782,
455          "width": 1280,
456          "height": 18
457        },
458        "nodes": [
459
460          {
461           "id": 6931312,
462           "name": "#00aa00",
463           "percent": 1,
464           "rect": {
465             "x": 0,
466             "y": 782,
467             "width": 1280,
468             "height": 18
469           }
470          }
471
472        ]
473       }
474     ]
475    }
476  ]
477 }
478 ------------------------
479
480 [[_marks_reply]]
481 === MARKS reply
482
483 The reply consists of a single array of strings for each container that has a
484 mark. A mark can only be set on one container, so the array is unique.
485 The order of that array is undefined.
486
487 If no window has a mark the response will be the empty array [].
488
489 [[_bar_config_reply]]
490 === BAR_CONFIG reply
491
492 This can be used by third-party workspace bars (especially i3bar, but others
493 are free to implement compatible alternatives) to get the +bar+ block
494 configuration from i3.
495
496 Depending on the input, the reply is either:
497
498 empty input::
499         An array of configured bar IDs
500 Bar ID::
501         A JSON map containing the configuration for the specified bar.
502
503 Each bar configuration has the following properties:
504
505 id (string)::
506         The ID for this bar. Included in case you request multiple
507         configurations and want to differentiate the different replies.
508 mode (string)::
509         Either +dock+ (the bar sets the dock window type) or +hide+ (the bar
510         does not show unless a specific key is pressed).
511 position (string)::
512         Either +bottom+ or +top+ at the moment.
513 status_command (string)::
514         Command which will be run to generate a statusline. Each line on stdout
515         of this command will be displayed in the bar. At the moment, no
516         formatting is supported.
517 font (string)::
518         The font to use for text on the bar.
519 workspace_buttons (boolean)::
520         Display workspace buttons or not? Defaults to true.
521 binding_mode_indicator (boolean)::
522         Display the mode indicator or not? Defaults to true.
523 verbose (boolean)::
524         Should the bar enable verbose output for debugging? Defaults to false.
525 colors (map)::
526         Contains key/value pairs of colors. Each value is a color code in hex,
527         formatted #rrggbb (like in HTML).
528
529 The following colors can be configured at the moment:
530
531 background::
532         Background color of the bar.
533 statusline::
534         Text color to be used for the statusline.
535 separator::
536         Text color to be used for the separator.
537 focused_background::
538         Background color of the bar on the currently focused monitor output.
539 focused_statusline::
540         Text color to be used for the statusline on the currently focused
541         monitor output.
542 focused_separator::
543         Text color to be used for the separator on the currently focused
544         monitor output.
545 focused_workspace_text/focused_workspace_bg/focused_workspace_border::
546         Text/background/border color for a workspace button when the workspace
547         has focus.
548 active_workspace_text/active_workspace_bg/active_workspace_border::
549         Text/background/border color for a workspace button when the workspace
550         is active (visible) on some output, but the focus is on another one.
551         You can only tell this apart from the focused workspace when you are
552         using multiple monitors.
553 inactive_workspace_text/inactive_workspace_bg/inactive_workspace_border::
554         Text/background/border color for a workspace button when the workspace
555         does not have focus and is not active (visible) on any output. This
556         will be the case for most workspaces.
557 urgent_workspace_text/urgent_workspace_bg/urgent_workspace_border::
558         Text/background/border color for workspaces which contain at least one
559         window with the urgency hint set.
560 binding_mode_text/binding_mode_bg/binding_mode_border::
561         Text/background/border color for the binding mode indicator.
562
563
564 *Example of configured bars:*
565 --------------
566 ["bar-bxuqzf"]
567 --------------
568
569 *Example of bar configuration:*
570 --------------
571 {
572  "id": "bar-bxuqzf",
573  "mode": "dock",
574  "position": "bottom",
575  "status_command": "i3status",
576  "font": "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1",
577  "workspace_buttons": true,
578  "binding_mode_indicator": true,
579  "verbose": false,
580  "colors": {
581    "background": "#c0c0c0",
582    "statusline": "#00ff00",
583    "focused_workspace_text": "#ffffff",
584    "focused_workspace_bg": "#000000"
585  }
586 }
587 --------------
588
589 [[_version_reply]]
590 === VERSION reply
591
592 The reply consists of a single JSON dictionary with the following keys:
593
594 major (integer)::
595         The major version of i3, such as +4+.
596 minor (integer)::
597         The minor version of i3, such as +2+. Changes in the IPC interface (new
598         features) will only occur with new minor (or major) releases. However,
599         bugfixes might be introduced in patch releases, too.
600 patch (integer)::
601         The patch version of i3, such as +1+ (when the complete version is
602         +4.2.1+). For versions such as +4.2+, patch will be set to +0+.
603 human_readable (string)::
604         A human-readable version of i3 containing the precise git version,
605         build date and branch name. When you need to display the i3 version to
606         your users, use the human-readable version whenever possible (since
607         this is what +i3 --version+ displays, too).
608 loaded_config_file_name (string)::
609         The current config path.
610
611 *Example:*
612 -------------------
613 {
614    "human_readable" : "4.2-169-gf80b877 (2012-08-05, branch \"next\")",
615    "loaded_config_file_name" : "/home/hwangcc23/.i3/config",
616    "minor" : 2,
617    "patch" : 0,
618    "major" : 4
619 }
620 -------------------
621
622 [[_binding_modes_reply]]
623 === BINDING_MODES reply
624
625 The reply consists of an array of all currently configured binding modes.
626
627 *Example:*
628 ---------------------
629 ["default", "resize"]
630 ---------------------
631
632 [[_config_reply]]
633 === CONFIG reply
634
635 The config reply is a map which currently only contains the "config" member,
636 which is a string containing the config file as loaded by i3 most recently.
637
638 *Example:*
639 -------------------
640 { "config": "font pango:monospace 8\nbindsym Mod4+q exit\n" }
641 -------------------
642
643 [[_tick_reply]]
644 === TICK reply
645
646 The reply is a map containing the "success" member. After the reply was
647 received, the tick event has been written to all IPC connections which subscribe
648 to tick events. UNIX sockets are usually buffered, but you can be certain that
649 once you receive the tick event you just triggered, you must have received all
650 events generated prior to the +SEND_TICK+ message (happened-before relation).
651
652 *Example:*
653 -------------------
654 { "success": true }
655 -------------------
656
657 == Events
658
659 [[events]]
660
661 To get informed when certain things happen in i3, clients can subscribe to
662 events. Events consist of a name (like "workspace") and an event reply type
663 (like I3_IPC_EVENT_WORKSPACE). The events sent by i3 are in the same format
664 as replies to specific commands. However, the highest bit of the message type
665 is set to 1 to indicate that this is an event reply instead of a normal reply.
666
667 Caveat: As soon as you subscribe to an event, it is not guaranteed any longer
668 that the requests to i3 are processed in order. This means, the following
669 situation can happen: You send a GET_WORKSPACES request but you receive a
670 "workspace" event before receiving the reply to GET_WORKSPACES. If your
671 program does not want to cope which such kinds of race conditions (an
672 event based library may not have a problem here), I suggest you create a
673 separate connection to receive events.
674
675 === Subscribing to events
676
677 By sending a message of type SUBSCRIBE with a JSON-encoded array as payload
678 you can register to an event.
679
680 *Example:*
681 ---------------------------------
682 type: SUBSCRIBE
683 payload: [ "workspace", "output" ]
684 ---------------------------------
685
686
687 === Available events
688
689 The numbers in parenthesis is the event type (keep in mind that you need to
690 strip the highest bit first).
691
692 workspace (0)::
693         Sent when the user switches to a different workspace, when a new
694         workspace is initialized or when a workspace is removed (because the
695         last client vanished).
696 output (1)::
697         Sent when RandR issues a change notification (of either screens,
698         outputs, CRTCs or output properties).
699 mode (2)::
700         Sent whenever i3 changes its binding mode.
701 window (3)::
702         Sent when a client's window is successfully reparented (that is when i3
703         has finished fitting it into a container), when a window received input
704         focus or when certain properties of the window have changed.
705 barconfig_update (4)::
706     Sent when the hidden_state or mode field in the barconfig of any bar
707     instance was updated and when the config is reloaded.
708 binding (5)::
709         Sent when a configured command binding is triggered with the keyboard or
710         mouse
711 shutdown (6)::
712         Sent when the ipc shuts down because of a restart or exit by user command
713 tick (7)::
714         Sent when the ipc client subscribes to the tick event (with +"first":
715         true+) or when any ipc client sends a SEND_TICK message (with +"first":
716         false+).
717
718 *Example:*
719 --------------------------------------------------------------------
720 # the appropriate 4 bytes read from the socket are stored in $input
721
722 # unpack a 32-bit unsigned integer
723 my $message_type = unpack("L", $input);
724
725 # check if the highest bit is 1
726 my $is_event = (($message_type >> 31) == 1);
727
728 # use the other bits
729 my $event_type = ($message_type & 0x7F);
730
731 if ($is_event) {
732   say "Received event of type $event_type";
733 }
734 --------------------------------------------------------------------
735
736 === workspace event
737
738 This event consists of a single serialized map containing a property
739 +change (string)+ which indicates the type of the change ("focus", "init",
740 "empty", "urgent", "reload", "rename", "restored", "move"). A
741 +current (object)+ property will be present with the affected workspace
742 whenever the type of event affects a workspace (otherwise, it will be +null).
743
744 When the change is "focus", an +old (object)+ property will be present with the
745 previous workspace.  When the first switch occurs (when i3 focuses the
746 workspace visible at the beginning) there is no previous workspace, and the
747 +old+ property will be set to +null+.  Also note that if the previous is empty
748 it will get destroyed when switching, but will still be present in the "old"
749 property.
750
751 *Example:*
752 ---------------------
753 {
754  "change": "focus",
755  "current": {
756   "id": 28489712,
757   "type": "workspace",
758   ...
759  }
760  "old": {
761   "id": 28489715,
762   "type": "workspace",
763   ...
764  }
765 }
766 ---------------------
767
768 === output event
769
770 This event consists of a single serialized map containing a property
771 +change (string)+ which indicates the type of the change (currently only
772 "unspecified").
773
774 *Example:*
775 ---------------------------
776 { "change": "unspecified" }
777 ---------------------------
778
779 === mode event
780
781 This event consists of a single serialized map containing a property
782 +change (string)+ which holds the name of current mode in use. The name
783 is the same as specified in config when creating a mode. The default
784 mode is simply named default. It contains a second property, +pango_markup+, which
785 defines whether pango markup shall be used for displaying this mode.
786
787 *Example:*
788 ---------------------------
789 {
790   "change": "default",
791   "pango_markup": true
792 }
793 ---------------------------
794
795 === window event
796
797 This event consists of a single serialized map containing a property
798 +change (string)+ which indicates the type of the change
799
800 * +new+ – the window has become managed by i3
801 * +close+ – the window has closed
802 * +focus+ – the window has received input focus
803 * +title+ – the window's title has changed
804 * +fullscreen_mode+ – the window has entered or exited fullscreen mode
805 * +move+ – the window has changed its position in the tree
806 * +floating+ – the window has transitioned to or from floating
807 * +urgent+ – the window has become urgent or lost its urgent status
808 * +mark+ – a mark has been added to or removed from the window
809
810 Additionally a +container (object)+ field will be present, which consists
811 of the window's parent container. Be aware that for the "new" event, the
812 container will hold the initial name of the newly reparented window (e.g.
813 if you run urxvt with a shell that changes the title, you will still at
814 this point get the window title as "urxvt").
815
816 *Example:*
817 ---------------------------
818 {
819  "change": "new",
820  "container": {
821   "id": 35569536,
822   "type": "con",
823   ...
824  }
825 }
826 ---------------------------
827
828 === barconfig_update event
829
830 This event consists of a single serialized map reporting on options from the
831 barconfig of the specified bar_id that were updated in i3. This event is the
832 same as a +GET_BAR_CONFIG+ reply for the bar with the given id.
833
834 === binding event
835
836 This event consists of a single serialized map reporting on the details of a
837 binding that ran a command because of user input. The +change (string)+ field
838 indicates what sort of binding event was triggered (right now it will always be
839 +"run"+ but may be expanded in the future).
840
841 The +binding (object)+ field contains details about the binding that was run:
842
843 command (string)::
844         The i3 command that is configured to run for this binding.
845 event_state_mask (array of strings)::
846         The group and modifier keys that were configured with this binding.
847 input_code (integer)::
848         If the binding was configured with +bindcode+, this will be the key code
849         that was given for the binding. If the binding is a mouse binding, it will be
850         the number of the mouse button that was pressed. Otherwise it will be 0.
851 symbol (string or null)::
852         If this is a keyboard binding that was configured with +bindsym+, this
853         field will contain the given symbol. Otherwise it will be +null+.
854 input_type (string)::
855         This will be +"keyboard"+ or +"mouse"+ depending on whether or not this was
856         a keyboard or a mouse binding.
857
858 *Example:*
859 ---------------------------
860 {
861  "change": "run",
862  "binding": {
863   "command": "nop",
864   "event_state_mask": [
865     "shift",
866     "ctrl"
867   ],
868   "input_code": 0,
869   "symbol": "t",
870   "input_type": "keyboard"
871  }
872 }
873 ---------------------------
874
875 === shutdown event
876
877 This event is triggered when the connection to the ipc is about to shutdown
878 because of a user action such as a +restart+ or +exit+ command. The +change
879 (string)+ field indicates why the ipc is shutting down. It can be either
880 +"restart"+ or +"exit"+.
881
882 *Example:*
883 ---------------------------
884 {
885  "change": "restart"
886 }
887 ---------------------------
888
889 === tick event
890
891 This event is triggered by a subscription to tick events or by a +SEND_TICK+
892 message.
893
894 *Example (upon subscription):*
895 --------------------------------------------------------------------------------
896 {
897  "first": true,
898  "payload": ""
899 }
900 --------------------------------------------------------------------------------
901
902 *Example (upon +SEND_TICK+ with a payload of +arbitrary string+):*
903 --------------------------------------------------------------------------------
904 {
905  "first": false,
906  "payload": "arbitrary string"
907 }
908 --------------------------------------------------------------------------------
909
910 == See also (existing libraries)
911
912 [[libraries]]
913
914 For some languages, libraries are available (so you don’t have to implement
915 all this on your own). This list names some (if you wrote one, please let me
916 know):
917
918 C::
919         * i3 includes a headerfile +i3/ipc.h+ which provides you all constants.
920         * https://github.com/acrisci/i3ipc-glib
921 C++::
922         * https://github.com/drmgc/i3ipcpp
923 Go::
924         * https://github.com/mdirkse/i3ipc-go
925         * https://github.com/i3/go-i3
926 JavaScript::
927         * https://github.com/acrisci/i3ipc-gjs
928 Lua::
929         * https://github.com/acrisci/i3ipc-lua
930 Perl::
931         * https://metacpan.org/module/AnyEvent::I3
932 Python::
933         * https://github.com/acrisci/i3ipc-python
934         * https://github.com/whitelynx/i3ipc (not maintained)
935         * https://github.com/ziberna/i3-py (not maintained)
936 Ruby::
937         * https://github.com/veelenga/i3ipc-ruby
938         * https://github.com/badboy/i3-ipc (not maintained)
939 Rust::
940         * https://github.com/tmerr/i3ipc-rs
941 OCaml::
942         * https://github.com/Armael/ocaml-i3ipc
943
944 == Appendix A: Detecting byte order in memory-safe languages
945
946 Some programming languages such as Go don’t offer a way to serialize data in the
947 native byte order of the machine they’re running on without resorting to tricks
948 involving the +unsafe+ package.
949
950 The following technique can be used (and will not be broken by changes to i3) to
951 detect the byte order i3 is using:
952
953 1. The byte order dependent fields of an IPC message are message type and
954    payload length.
955
956    * The message type +RUN_COMMAND+ (0) is the same in big and little endian, so
957      we can use it in either byte order to elicit a reply from i3.
958
959    * The payload length 65536 + 256 (+0x00 01 01 00+) is the same in big and
960      little endian, and also small enough to not worry about memory allocations
961      of that size. We must use payloads of length 65536 + 256 in every message
962      we send, so that i3 will be able to read the entire message regardless of
963      the byte order it uses.
964
965 2. Send a big endian encoded message of type +SUBSCRIBE+ (2) with payload `[]`
966    followed by 65536 + 256 - 2 +SPACE+ (ASCII 0x20) bytes.
967
968    * If i3 is running in big endian, this message is treated as a noop,
969      resulting in a +SUBSCRIBE+ reply with payload `{"success":true}`
970      footnote:[A small payload is important: that way, we circumvent dealing
971      with UNIX domain socket buffer sizes, whose size depends on the
972      implementation/operating system. Exhausting such a buffer results in an i3
973      deadlock unless you concurrently read and write, which — depending on the
974      programming language — makes the technique much more complicated.].
975
976    * If i3 is running in little endian, this message is read in its entirety due
977      to the byte order independent payload length, then
978      https://github.com/i3/i3/blob/d726d09d496577d1c337a4b97486f2c9fbc914f1/src/ipc.c#L1188[silently
979      discarded] due to the unknown message type.
980
981 3. Send a byte order independent message, i.e. type +RUN_COMMAND+ (0) with
982    payload +nop byte order detection. padding:+, padded to 65536 + 256 bytes
983    with +a+ (ASCII 0x61) bytes. i3 will reply to this message with a reply of
984    type +COMMAND+ (0).
985
986    * The human-readable prefix is in there to not confuse readers of the i3 log.
987
988    * This messages serves as a synchronization primitive so that we know whether
989      i3 discarded the +SUBSCRIBE+ message or didn’t answer it yet.
990
991 4. Receive a message header from i3, decoding the message type as big endian.
992
993    * If the message’s reply type is +COMMAND+ (0), i3 is running in little
994      endian (because the +SUBSCRIBE+ message was discarded). Decode the message
995      payload length as little endian, receive the message payload.
996
997    * If the message’s reply type is anything else, i3 is running in big endian
998      (because our big endian encoded +SUBSCRIBE+ message was answered). Decode
999      the message payload length in big endian, receive the message
1000      payload. Then, receive the pending +COMMAND+ message reply in big endian.
1001
1002 5. From here on out, send/receive all messages using the detected byte order.
1003
1004 Find an example implementation of this technique in
1005 https://github.com/i3/go-i3/blob/master/byteorder.go