]> git.sur5r.net Git - i3/i3.github.io/blob - docs/4.3/i3bar-protocol.html
fix docs/user-contributed/swapping-workspaces.html
[i3/i3.github.io] / docs / 4.3 / i3bar-protocol.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\r
2     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\r
4 <head>\r
5 <link rel="icon" type="image/png" href="/favicon.png">\r
6 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />\r
7 <meta name="generator" content="AsciiDoc 8.6.7" />\r
8 <title>i3: i3bar input protocol</title>\r
9 <link rel="stylesheet" href="/css/style.css" type="text/css" />\r
10 <link rel="stylesheet" href="/css/xhtml11.css" type="text/css" />\r
11 <script type="text/javascript">\r
12 /*<![CDATA[*/\r
13 window.onload = function(){asciidoc.footnotes();}\r
14 /*]]>*/\r
15 </script>\r
16 <script type="text/javascript" src="/js/asciidoc-xhtml11.js"></script>\r
17 </head>\r
18 <body class="article">\r
19 \r
20         <div id="main">\r
21             <a href="/"><h1 id="title">i3 - improved tiling WM</h1></a>\r
22                         <ul id="nav">\r
23                                 <li><a style="border-bottom: 2px solid #fff" href="/docs">Docs</a></li>\r
24                                 <li><a href="/screenshots">Screens</a></li>\r
25                                 <li><a href="/contact">Contact</a></li>\r
26                                 <li><a href="http://bugs.i3wm.org/">Bugs</a></li>\r
27                         </ul>\r
28         <br style="clear: both">\r
29 <div id="content">\r
30 <div id="header">\r
31 <h1>i3bar input protocol</h1>\r
32 <span id="author">Michael Stapelberg</span><br />\r
33 <span id="email"><tt>&lt;<a href="mailto:michael@i3wm.org">michael@i3wm.org</a>&gt;</tt></span><br />\r
34 <span id="revdate">August 2012</span>\r
35 </div>\r
36 <div id="preamble">\r
37 <div class="sectionbody">\r
38 <div class="paragraph"><p>This document explains the protocol in which i3bar expects its input. It\r
39 provides support for colors, urgency, shortening and easy manipulation.</p></div>\r
40 </div>\r
41 </div>\r
42 <div class="sect1">\r
43 <h2 id="_rationale_for_chosing_json">1. Rationale for chosing JSON</h2>\r
44 <div class="sectionbody">\r
45 <div class="paragraph"><p>Before describing the protocol, let’s cover why JSON is a building block of\r
46 this protocol.</p></div>\r
47 <div class="olist arabic"><ol class="arabic">\r
48 <li>\r
49 <p>\r
50 Other bar display programs such as dzen2 or xmobar are using in-band\r
51    signaling: they recognize certain sequences (like ^fg(#330000) in your input\r
52    text). We would like to avoid that and separate information from\r
53    meta-information. By information, we mean the actual output, like the IP\r
54    address of your ethernet adapter and by meta-information, we mean in which\r
55    color it should be displayed right now.\r
56 </p>\r
57 </li>\r
58 <li>\r
59 <p>\r
60 It is easy to write a simple script which manipulates part(s) of the input.\r
61    Each block of information (like a block for the disk space indicator, a block\r
62    for the current IP address, etc.) can be identified specifically and modified\r
63    in whichever way you like.\r
64 </p>\r
65 </li>\r
66 <li>\r
67 <p>\r
68 It remains easy to write a simple script which just suffixes (or prefixes) a\r
69    status line input, because tools like i3status will output their JSON in\r
70    such a way that each line array will be terminated by a newline. Therefore,\r
71    you are not required to use a streaming JSON parser, but you can use any\r
72    JSON parser and write your script in any programming language. In fact, you\r
73    can decide to not bother with the JSON parsing at all and just inject your\r
74    output at a specific position (beginning or end).\r
75 </p>\r
76 </li>\r
77 <li>\r
78 <p>\r
79 Relying on JSON does not introduce any new dependencies. In fact, the IPC\r
80    interface of i3 also uses JSON, therefore i3bar already depends on JSON.\r
81 </p>\r
82 </li>\r
83 </ol></div>\r
84 <div class="paragraph"><p>The only point against using JSON is computational complexity. If that really\r
85 bothers you, just use the plain text input format (which i3bar will continue to\r
86 support).</p></div>\r
87 </div>\r
88 </div>\r
89 <div class="sect1">\r
90 <h2 id="_the_protocol">2. The protocol</h2>\r
91 <div class="sectionbody">\r
92 <div class="paragraph"><p>The first message of the protocol is a header block, which contains (at least)\r
93 the version of the protocol to be used. In case there are significant changes\r
94 (not only additions), the version will be incremented. i3bar will still\r
95 understand the old protocol version, but in order to use the new one, you need\r
96 to provide the correct version. The header block is terminated by a newline and\r
97 consists of a single JSON hash:</p></div>\r
98 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
99 <div class="listingblock">\r
100 <div class="content">\r
101 <pre><tt>{ "version": 1 }</tt></pre>\r
102 </div></div>\r
103 <div class="paragraph"><p>(Note that before i3 v4.3 the precise format had to be <tt>{"version":1}</tt>,\r
104 byte-for-byte.)</p></div>\r
105 <div class="paragraph"><p>What follows is an infinite array (so it should be parsed by a streaming JSON\r
106 parser, but as described above you can go for a simpler solution), whose\r
107 elements are one array per status line. A status line is one unit of\r
108 information which should be displayed at a time. i3bar will not display any\r
109 input until the status line is complete. In each status line, every block will\r
110 be represented by a JSON hash:</p></div>\r
111 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
112 <div class="listingblock">\r
113 <div class="content">\r
114 <pre><tt>[\r
115 \r
116  [\r
117   {\r
118    "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
119    "color": "#00ff00"\r
120   },\r
121   {\r
122    "full_text": "2012-01-05 20:00:01"\r
123   }\r
124  ],\r
125 \r
126  [\r
127   {\r
128    "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
129    "color": "#00ff00"\r
130   },\r
131   {\r
132    "full_text": "2012-01-05 20:00:02"\r
133   }\r
134  ],\r
135  …</tt></pre>\r
136 </div></div>\r
137 <div class="paragraph"><p>Please note that this example was pretty printed for human consumption.\r
138 i3status and others will output single statuslines in one line, separated by\r
139 \n.</p></div>\r
140 <div class="paragraph"><p>You can find an example of a shell script which can be used as your\r
141 <tt>status_command</tt> in the bar configuration at\r
142 <a href="http://code.stapelberg.de/git/i3/tree/contrib/trivial-bar-script.sh?h=next">http://code.stapelberg.de/git/i3/tree/contrib/trivial-bar-script.sh?h=next</a></p></div>\r
143 <div class="sect2">\r
144 <h3 id="_blocks_in_detail">2.1. Blocks in detail</h3>\r
145 <div class="dlist"><dl>\r
146 <dt class="hdlist1">\r
147 full_text\r
148 </dt>\r
149 <dd>\r
150 <p>\r
151         The most simple block you can think of is one which just includes the\r
152         only required key, the <tt>full_text</tt> key. i3bar will display the string\r
153         value and that’s it.\r
154 </p>\r
155 </dd>\r
156 <dt class="hdlist1">\r
157 short_text\r
158 </dt>\r
159 <dd>\r
160 <p>\r
161         Where appropriate, the <tt>short_text</tt> (string) entry should also be\r
162         provided. It will be used in case the status line needs to be shortened\r
163         because it uses more space than your screen provides. For example, when\r
164         displaying an IPv6 address, the prefix is usually (!) more relevant\r
165         than the suffix, because the latter stays constant when using autoconf,\r
166         while the prefix changes. When displaying the date, the time is more\r
167         important than the date (it is more likely that you know which day it\r
168         is than what time it is).\r
169 </p>\r
170 </dd>\r
171 <dt class="hdlist1">\r
172 color\r
173 </dt>\r
174 <dd>\r
175 <p>\r
176         To make the current state of the information easy to spot, colors can\r
177         be used. For example, the wireless block could be displayed in red\r
178         (using the <tt>color</tt> (string) entry) if the card is not associated with\r
179         any network and in green or yellow (depending on the signal strength)\r
180         when it is associated.\r
181         Colors are specified in hex (like in HTML), starting with a leading\r
182         hash sign. For example, <tt>#ff0000</tt> means red.\r
183 </p>\r
184 </dd>\r
185 <dt class="hdlist1">\r
186 name and instance\r
187 </dt>\r
188 <dd>\r
189 <p>\r
190         Every block should have a unique <tt>name</tt> (string) entry so that it can\r
191         be easily identified in scripts which process the output. i3bar\r
192         completely ignores the name and instance fields. Make sure to also\r
193         specify an <tt>instance</tt> (string) entry where appropriate. For example,\r
194         the user can have multiple disk space blocks for multiple mount points.\r
195 </p>\r
196 </dd>\r
197 <dt class="hdlist1">\r
198 urgent\r
199 </dt>\r
200 <dd>\r
201 <p>\r
202         A boolean which specifies whether the current value is urgent. Examples\r
203         are battery charge values below 1 percent or no more available disk\r
204         space (for non-root users). The presentation of urgency is up to i3bar.\r
205 </p>\r
206 </dd>\r
207 </dl></div>\r
208 <div class="paragraph"><p>If you want to put in your own entries into a block, prefix the key with an\r
209 underscore (_). i3bar will ignore all keys it doesn’t understand, and prefixing\r
210 them with an underscore makes it clear in every script that they are not part\r
211 of the i3bar protocol.</p></div>\r
212 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
213 <div class="listingblock">\r
214 <div class="content">\r
215 <pre><tt>{\r
216  "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
217  "_ethernet_vendor": "Intel"\r
218 }</tt></pre>\r
219 </div></div>\r
220 <div class="paragraph"><p>An example of a block which uses all possible entries follows:</p></div>\r
221 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
222 <div class="listingblock">\r
223 <div class="content">\r
224 <pre><tt>{\r
225  "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
226  "short_text": "10.0.0.1",\r
227  "color": "#00ff00",\r
228  "urgent": false,\r
229  "name": "ethernet",\r
230  "instance": "eth0"\r
231 }</tt></pre>\r
232 </div></div>\r
233 </div>\r
234 </div>\r
235 </div>\r
236 </div>\r
237 <div id="footnotes"><hr /></div>\r
238 <div id="footer" lang="de">\r
239 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>\r
240 </div>\r
241 </body>\r
242 </html>\r