]> git.sur5r.net Git - i3/i3.github.io/blob - docs/i3bar-protocol.html
add i3 v4.5
[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/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>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 }</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 </dl></div>\r
180 </div>\r
181 <div class="sect2">\r
182 <h3 id="_blocks_in_detail">2.2. Blocks in detail</h3>\r
183 <div class="dlist"><dl>\r
184 <dt class="hdlist1">\r
185 full_text\r
186 </dt>\r
187 <dd>\r
188 <p>\r
189         The most simple block you can think of is one which just includes the\r
190         only required key, the <tt>full_text</tt> key. i3bar will display the string\r
191         value and that’s it.\r
192 </p>\r
193 </dd>\r
194 <dt class="hdlist1">\r
195 short_text\r
196 </dt>\r
197 <dd>\r
198 <p>\r
199         Where appropriate, the <tt>short_text</tt> (string) entry should also be\r
200         provided. It will be used in case the status line needs to be shortened\r
201         because it uses more space than your screen provides. For example, when\r
202         displaying an IPv6 address, the prefix is usually (!) more relevant\r
203         than the suffix, because the latter stays constant when using autoconf,\r
204         while the prefix changes. When displaying the date, the time is more\r
205         important than the date (it is more likely that you know which day it\r
206         is than what time it is).\r
207 </p>\r
208 </dd>\r
209 <dt class="hdlist1">\r
210 color\r
211 </dt>\r
212 <dd>\r
213 <p>\r
214         To make the current state of the information easy to spot, colors can\r
215         be used. For example, the wireless block could be displayed in red\r
216         (using the <tt>color</tt> (string) entry) if the card is not associated with\r
217         any network and in green or yellow (depending on the signal strength)\r
218         when it is associated.\r
219         Colors are specified in hex (like in HTML), starting with a leading\r
220         hash sign. For example, <tt>#ff0000</tt> means red.\r
221 </p>\r
222 </dd>\r
223 <dt class="hdlist1">\r
224 min_width\r
225 </dt>\r
226 <dd>\r
227 <p>\r
228         The minimum width (in pixels) of the block. If the content of the\r
229         <tt>full_text</tt> key take less space than the specified min_width, the block\r
230         will be padded to the left and/or the right side, according to the <tt>align</tt>\r
231         key. This is useful when you want to prevent the whole status line to shift\r
232         when value take more or less space between each iteration.\r
233         The value can also be a string. In this case, the width of the text given\r
234         by <tt>min_width</tt> determines the minimum width of the block. This is useful\r
235         when you want to set a sensible minimum width regardless of which font you\r
236         are using, and at what particular size.\r
237 </p>\r
238 </dd>\r
239 <dt class="hdlist1">\r
240 align\r
241 </dt>\r
242 <dd>\r
243 <p>\r
244         Align text on the <tt>center</tt> (default), <tt>right</tt> or <tt>left</tt> of the block, when\r
245         the minimum width of the latter, specified by the <tt>min_width</tt> key, is not\r
246         reached.\r
247 </p>\r
248 </dd>\r
249 <dt class="hdlist1">\r
250 name and instance\r
251 </dt>\r
252 <dd>\r
253 <p>\r
254         Every block should have a unique <tt>name</tt> (string) entry so that it can\r
255         be easily identified in scripts which process the output. i3bar\r
256         completely ignores the name and instance fields. Make sure to also\r
257         specify an <tt>instance</tt> (string) entry where appropriate. For example,\r
258         the user can have multiple disk space blocks for multiple mount points.\r
259 </p>\r
260 </dd>\r
261 <dt class="hdlist1">\r
262 urgent\r
263 </dt>\r
264 <dd>\r
265 <p>\r
266         A boolean which specifies whether the current value is urgent. Examples\r
267         are battery charge values below 1 percent or no more available disk\r
268         space (for non-root users). The presentation of urgency is up to i3bar.\r
269 </p>\r
270 </dd>\r
271 <dt class="hdlist1">\r
272 separator\r
273 </dt>\r
274 <dd>\r
275 <p>\r
276         A boolean which specifies whether a separator line should be drawn\r
277         after this block. The default is true, meaning the separator line will\r
278         be drawn. Note that if you disable the separator line, there will still\r
279         be a gap after the block, unless you also use <tt>separator_block_width</tt>.\r
280 </p>\r
281 </dd>\r
282 <dt class="hdlist1">\r
283 separator_block_width\r
284 </dt>\r
285 <dd>\r
286 <p>\r
287         The amount of pixels to leave blank after the block. In the middle of\r
288         this gap, a separator line will be drawn unless <tt>separator</tt> is\r
289         disabled. Normally, you want to set this to an odd value (the default\r
290         is 9 pixels), since the separator line is drawn in the middle.\r
291 </p>\r
292 </dd>\r
293 </dl></div>\r
294 <div class="paragraph"><p>If you want to put in your own entries into a block, prefix the key with an\r
295 underscore (_). i3bar will ignore all keys it doesn’t understand, and prefixing\r
296 them with an underscore makes it clear in every script that they are not part\r
297 of the i3bar protocol.</p></div>\r
298 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
299 <div class="listingblock">\r
300 <div class="content">\r
301 <pre><tt>{\r
302  "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
303  "_ethernet_vendor": "Intel"\r
304 }</tt></pre>\r
305 </div></div>\r
306 <div class="paragraph"><p>In the following example, the longest (widest) possible value of the block is\r
307 used to set the minimum width:</p></div>\r
308 <div class="listingblock">\r
309 <div class="content">\r
310 <pre><tt>{\r
311  "full_text": "CPU 4%",\r
312  "min_width": "CPU 100%",\r
313  "align": "left"\r
314 }</tt></pre>\r
315 </div></div>\r
316 <div class="paragraph"><p>An example of a block which uses all possible entries follows:</p></div>\r
317 <div class="paragraph"><p><strong>Example</strong>:</p></div>\r
318 <div class="listingblock">\r
319 <div class="content">\r
320 <pre><tt>{\r
321  "full_text": "E: 10.0.0.1 (1000 Mbit/s)",\r
322  "short_text": "10.0.0.1",\r
323  "color": "#00ff00",\r
324  "min_width": 300,\r
325  "align": "right",\r
326  "urgent": false,\r
327  "name": "ethernet",\r
328  "instance": "eth0",\r
329  "separator": true,\r
330  "separator_block_width": 9\r
331 }</tt></pre>\r
332 </div></div>\r
333 </div>\r
334 </div>\r
335 </div>\r
336 </div>\r
337 <div id="footnotes"><hr /></div>\r
338 <div id="footer" lang="de">\r
339 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>\r
340 </div>\r
341 </body>\r
342 </html>\r