]> git.sur5r.net Git - i3/i3.github.io/blob - docs/i3bar-protocol.html
2bed449e7caf919a6aef74158c5390623b257b14
[i3/i3.github.io] / docs / 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/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.8" />\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 document.addEventListener("DOMContentLoaded", function(){asciidoc.footnotes();}, 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="/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>Minimal 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><strong>All features example</strong>:</p></div>\r
104 <div class="listingblock">\r
105 <div class="content">\r
106 <pre><tt>{ "version": 1, "stop_signal": 10, "cont_signal": 12, "click_events": true }</tt></pre>\r
107 </div></div>\r
108 <div class="paragraph"><p>(Note that before i3 v4.3 the precise format had to be <tt>{"version":1}</tt>,\r
109 byte-for-byte.)</p></div>\r
110 <div class="paragraph"><p>What follows is an infinite array (so it should be parsed by a streaming JSON\r
111 parser, but as described above you can go for a simpler solution), whose\r
112 elements are one array per status line. A status line is one unit of\r
113 information which should be displayed at a time. i3bar will not display any\r
114 input until the status line is complete. In each status line, every block will\r
115 be represented by a JSON hash:</p></div>\r
116 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
117 <div class="listingblock">\r
118 <div class="content">\r
119 <pre><tt>[\r
120 \r
121  [\r
122   {\r
123    "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
124    "color": "#00ff00"\r
125   },\r
126   {\r
127    "full_text": "2012-01-05 20:00:01"\r
128   }\r
129  ],\r
130 \r
131  [\r
132   {\r
133    "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
134    "color": "#00ff00"\r
135   },\r
136   {\r
137    "full_text": "2012-01-05 20:00:02"\r
138   }\r
139  ],\r
140  …</tt></pre>\r
141 </div></div>\r
142 <div class="paragraph"><p>Please note that this example was pretty printed for human consumption.\r
143 i3status and others will output single statuslines in one line, separated by\r
144 \n.</p></div>\r
145 <div class="paragraph"><p>You can find an example of a shell script which can be used as your\r
146 <tt>status_command</tt> in the bar configuration at\r
147 <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
148 <div class="sect2">\r
149 <h3 id="_header_in_detail">2.1. Header in detail</h3>\r
150 <div class="dlist"><dl>\r
151 <dt class="hdlist1">\r
152 version\r
153 </dt>\r
154 <dd>\r
155 <p>\r
156         The version number (as an integer) of the i3bar protocol you will use.\r
157 </p>\r
158 </dd>\r
159 <dt class="hdlist1">\r
160 stop_signal\r
161 </dt>\r
162 <dd>\r
163 <p>\r
164         Specify to i3bar the signal (as an integer) to send to stop your\r
165         processing.\r
166         The default value (if none is specified) is SIGSTOP.\r
167 </p>\r
168 </dd>\r
169 <dt class="hdlist1">\r
170 cont_signal\r
171 </dt>\r
172 <dd>\r
173 <p>\r
174         Specify to i3bar the signal (as an integer)to send to continue your\r
175         processing.\r
176         The default value (if none is specified) is SIGCONT.\r
177 </p>\r
178 </dd>\r
179 <dt class="hdlist1">\r
180 click_events\r
181 </dt>\r
182 <dd>\r
183 <p>\r
184         If specified and true i3bar will write a infinite array (same as above)\r
185         to your stdin.\r
186 </p>\r
187 </dd>\r
188 </dl></div>\r
189 </div>\r
190 <div class="sect2">\r
191 <h3 id="_blocks_in_detail">2.2. Blocks in detail</h3>\r
192 <div class="dlist"><dl>\r
193 <dt class="hdlist1">\r
194 full_text\r
195 </dt>\r
196 <dd>\r
197 <p>\r
198         The most simple block you can think of is one which just includes the\r
199         only required key, the <tt>full_text</tt> key. i3bar will display the string\r
200         value parsed as\r
201         <a href="https://developer.gnome.org/pango/stable/PangoMarkupFormat.html">Pango markup</a>.\r
202 </p>\r
203 </dd>\r
204 <dt class="hdlist1">\r
205 short_text\r
206 </dt>\r
207 <dd>\r
208 <p>\r
209         Where appropriate, the <tt>short_text</tt> (string) entry should also be\r
210         provided. It will be used in case the status line needs to be shortened\r
211         because it uses more space than your screen provides. For example, when\r
212         displaying an IPv6 address, the prefix is usually (!) more relevant\r
213         than the suffix, because the latter stays constant when using autoconf,\r
214         while the prefix changes. When displaying the date, the time is more\r
215         important than the date (it is more likely that you know which day it\r
216         is than what time it is).\r
217 </p>\r
218 </dd>\r
219 <dt class="hdlist1">\r
220 color\r
221 </dt>\r
222 <dd>\r
223 <p>\r
224         To make the current state of the information easy to spot, colors can\r
225         be used. For example, the wireless block could be displayed in red\r
226         (using the <tt>color</tt> (string) entry) if the card is not associated with\r
227         any network and in green or yellow (depending on the signal strength)\r
228         when it is associated.\r
229         Colors are specified in hex (like in HTML), starting with a leading\r
230         hash sign. For example, <tt>#ff0000</tt> means red.\r
231 </p>\r
232 </dd>\r
233 <dt class="hdlist1">\r
234 min_width\r
235 </dt>\r
236 <dd>\r
237 <p>\r
238         The minimum width (in pixels) of the block. If the content of the\r
239         <tt>full_text</tt> key take less space than the specified min_width, the block\r
240         will be padded to the left and/or the right side, according to the <tt>align</tt>\r
241         key. This is useful when you want to prevent the whole status line to shift\r
242         when value take more or less space between each iteration.\r
243         The value can also be a string. In this case, the width of the text given\r
244         by <tt>min_width</tt> determines the minimum width of the block. This is useful\r
245         when you want to set a sensible minimum width regardless of which font you\r
246         are using, and at what particular size.\r
247 </p>\r
248 </dd>\r
249 <dt class="hdlist1">\r
250 align\r
251 </dt>\r
252 <dd>\r
253 <p>\r
254         Align text on the <tt>center</tt>, <tt>right</tt> or <tt>left</tt> (default) of the block, when\r
255         the minimum width of the latter, specified by the <tt>min_width</tt> key, is not\r
256         reached.\r
257 </p>\r
258 </dd>\r
259 <dt class="hdlist1">\r
260 name and instance\r
261 </dt>\r
262 <dd>\r
263 <p>\r
264         Every block should have a unique <tt>name</tt> (string) entry so that it can\r
265         be easily identified in scripts which process the output. i3bar\r
266         completely ignores the name and instance fields. Make sure to also\r
267         specify an <tt>instance</tt> (string) entry where appropriate. For example,\r
268         the user can have multiple disk space blocks for multiple mount points.\r
269 </p>\r
270 </dd>\r
271 <dt class="hdlist1">\r
272 urgent\r
273 </dt>\r
274 <dd>\r
275 <p>\r
276         A boolean which specifies whether the current value is urgent. Examples\r
277         are battery charge values below 1 percent or no more available disk\r
278         space (for non-root users). The presentation of urgency is up to i3bar.\r
279 </p>\r
280 </dd>\r
281 <dt class="hdlist1">\r
282 separator\r
283 </dt>\r
284 <dd>\r
285 <p>\r
286         A boolean which specifies whether a separator line should be drawn\r
287         after this block. The default is true, meaning the separator line will\r
288         be drawn. Note that if you disable the separator line, there will still\r
289         be a gap after the block, unless you also use <tt>separator_block_width</tt>.\r
290 </p>\r
291 </dd>\r
292 <dt class="hdlist1">\r
293 separator_block_width\r
294 </dt>\r
295 <dd>\r
296 <p>\r
297         The amount of pixels to leave blank after the block. In the middle of\r
298         this gap, a separator line will be drawn unless <tt>separator</tt> is\r
299         disabled. Normally, you want to set this to an odd value (the default\r
300         is 9 pixels), since the separator line is drawn in the middle.\r
301 </p>\r
302 </dd>\r
303 </dl></div>\r
304 <div class="paragraph"><p>If you want to put in your own entries into a block, prefix the key with an\r
305 underscore (_). i3bar will ignore all keys it doesn’t understand, and prefixing\r
306 them with an underscore makes it clear in every script that they are not part\r
307 of the i3bar protocol.</p></div>\r
308 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
309 <div class="listingblock">\r
310 <div class="content">\r
311 <pre><tt>{\r
312  "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
313  "_ethernet_vendor": "Intel"\r
314 }</tt></pre>\r
315 </div></div>\r
316 <div class="paragraph"><p>In the following example, the longest (widest) possible value of the block is\r
317 used to set the minimum width:</p></div>\r
318 <div class="listingblock">\r
319 <div class="content">\r
320 <pre><tt>{\r
321  "full_text": "CPU 4%",\r
322  "min_width": "CPU 100%",\r
323  "align": "left"\r
324 }</tt></pre>\r
325 </div></div>\r
326 <div class="paragraph"><p>An example of a block which uses all possible entries follows:</p></div>\r
327 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
328 <div class="listingblock">\r
329 <div class="content">\r
330 <pre><tt>{\r
331  "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
332  "short_text": "10.0.0.1",\r
333  "color": "#00ff00",\r
334  "min_width": 300,\r
335  "align": "right",\r
336  "urgent": false,\r
337  "name": "ethernet",\r
338  "instance": "eth0",\r
339  "separator": true,\r
340  "separator_block_width": 9\r
341 }</tt></pre>\r
342 </div></div>\r
343 </div>\r
344 <div class="sect2">\r
345 <h3 id="_click_events">2.3. Click events</h3>\r
346 <div class="paragraph"><p>If enabled i3bar will send you notifications if the user clicks on a block and\r
347 looks like this:</p></div>\r
348 <div class="dlist"><dl>\r
349 <dt class="hdlist1">\r
350 name\r
351 </dt>\r
352 <dd>\r
353 <p>\r
354         Name of the block, if set\r
355 </p>\r
356 </dd>\r
357 <dt class="hdlist1">\r
358 instance\r
359 </dt>\r
360 <dd>\r
361 <p>\r
362         Instance of the block, if set\r
363 </p>\r
364 </dd>\r
365 <dt class="hdlist1">\r
366 x, y\r
367 </dt>\r
368 <dd>\r
369 <p>\r
370         X11 root window coordinates where the click occured\r
371 </p>\r
372 </dd>\r
373 <dt class="hdlist1">\r
374 button\r
375 </dt>\r
376 <dd>\r
377 <p>\r
378         X11 button ID (for example 1 to 3 for left/middle/right mouse button)\r
379 </p>\r
380 </dd>\r
381 </dl></div>\r
382 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
383 <div class="listingblock">\r
384 <div class="content">\r
385 <pre><tt>{\r
386  "name": "ethernet",\r
387  "instance": "eth0",\r
388  "button": 1,\r
389  "x": 1320,\r
390  "y": 1400\r
391 }</tt></pre>\r
392 </div></div>\r
393 </div>\r
394 </div>\r
395 </div>\r
396 </div>\r
397 <div id="footnotes"><hr /></div>\r
398 <div id="footer" lang="de">\r
399 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>\r
400 </div>\r
401 </body>\r
402 </html>\r