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/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.9" />
\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
13 document.addEventListener("DOMContentLoaded", function(){asciidoc.footnotes();}, 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="/contact">Contact</a></li>
\r
26 <li><a href="http://bugs.i3wm.org/">Bugs</a></li>
\r
28 <br style="clear: both">
\r
31 <h1>i3bar input protocol</h1>
\r
32 <span id="author">Michael Stapelberg</span><br />
\r
33 <span id="email"><tt><<a href="mailto:michael@i3wm.org">michael@i3wm.org</a>></tt></span><br />
\r
34 <span id="revdate">August 2012</span>
\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
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
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
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
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
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
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
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
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
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
123 "full_text": "E: 10.0.0.1 (1000 Mbit/s)",
\r
127 "full_text": "2012-01-05 20:00:01"
\r
133 "full_text": "E: 10.0.0.1 (1000 Mbit/s)",
\r
137 "full_text": "2012-01-05 20:00:02"
\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
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
156 The version number (as an integer) of the i3bar protocol you will use.
\r
159 <dt class="hdlist1">
\r
164 Specify to i3bar the signal (as an integer) to send to stop your
\r
166 The default value (if none is specified) is SIGSTOP.
\r
169 <dt class="hdlist1">
\r
174 Specify to i3bar the signal (as an integer)to send to continue your
\r
176 The default value (if none is specified) is SIGCONT.
\r
179 <dt class="hdlist1">
\r
184 If specified and true i3bar will write a infinite array (same as above)
\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
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 and that’s it.
\r
203 <dt class="hdlist1">
\r
208 Where appropriate, the <tt>short_text</tt> (string) entry should also be
\r
209 provided. It will be used in case the status line needs to be shortened
\r
210 because it uses more space than your screen provides. For example, when
\r
211 displaying an IPv6 address, the prefix is usually (!) more relevant
\r
212 than the suffix, because the latter stays constant when using autoconf,
\r
213 while the prefix changes. When displaying the date, the time is more
\r
214 important than the date (it is more likely that you know which day it
\r
215 is than what time it is).
\r
218 <dt class="hdlist1">
\r
223 To make the current state of the information easy to spot, colors can
\r
224 be used. For example, the wireless block could be displayed in red
\r
225 (using the <tt>color</tt> (string) entry) if the card is not associated with
\r
226 any network and in green or yellow (depending on the signal strength)
\r
227 when it is associated.
\r
228 Colors are specified in hex (like in HTML), starting with a leading
\r
229 hash sign. For example, <tt>#ff0000</tt> means red.
\r
232 <dt class="hdlist1">
\r
237 The minimum width (in pixels) of the block. If the content of the
\r
238 <tt>full_text</tt> key take less space than the specified min_width, the block
\r
239 will be padded to the left and/or the right side, according to the <tt>align</tt>
\r
240 key. This is useful when you want to prevent the whole status line to shift
\r
241 when value take more or less space between each iteration.
\r
242 The value can also be a string. In this case, the width of the text given
\r
243 by <tt>min_width</tt> determines the minimum width of the block. This is useful
\r
244 when you want to set a sensible minimum width regardless of which font you
\r
245 are using, and at what particular size.
\r
248 <dt class="hdlist1">
\r
253 Align text on the <tt>center</tt> (default), <tt>right</tt> or <tt>left</tt> of the block, when
\r
254 the minimum width of the latter, specified by the <tt>min_width</tt> key, is not
\r
258 <dt class="hdlist1">
\r
263 Every block should have a unique <tt>name</tt> (string) entry so that it can
\r
264 be easily identified in scripts which process the output. i3bar
\r
265 completely ignores the name and instance fields. Make sure to also
\r
266 specify an <tt>instance</tt> (string) entry where appropriate. For example,
\r
267 the user can have multiple disk space blocks for multiple mount points.
\r
270 <dt class="hdlist1">
\r
275 A boolean which specifies whether the current value is urgent. Examples
\r
276 are battery charge values below 1 percent or no more available disk
\r
277 space (for non-root users). The presentation of urgency is up to i3bar.
\r
280 <dt class="hdlist1">
\r
285 A boolean which specifies whether a separator line should be drawn
\r
286 after this block. The default is true, meaning the separator line will
\r
287 be drawn. Note that if you disable the separator line, there will still
\r
288 be a gap after the block, unless you also use <tt>separator_block_width</tt>.
\r
291 <dt class="hdlist1">
\r
292 separator_block_width
\r
296 The amount of pixels to leave blank after the block. In the middle of
\r
297 this gap, a separator line will be drawn unless <tt>separator</tt> is
\r
298 disabled. Normally, you want to set this to an odd value (the default
\r
299 is 9 pixels), since the separator line is drawn in the middle.
\r
303 <div class="paragraph"><p>If you want to put in your own entries into a block, prefix the key with an
\r
304 underscore (_). i3bar will ignore all keys it doesn’t understand, and prefixing
\r
305 them with an underscore makes it clear in every script that they are not part
\r
306 of the i3bar protocol.</p></div>
\r
307 <div class="paragraph"><p><strong>Example</strong>:</p></div>
\r
308 <div class="listingblock">
\r
309 <div class="content">
\r
311 "full_text": "E: 10.0.0.1 (1000 Mbit/s)",
\r
312 "_ethernet_vendor": "Intel"
\r
315 <div class="paragraph"><p>In the following example, the longest (widest) possible value of the block is
\r
316 used to set the minimum width:</p></div>
\r
317 <div class="listingblock">
\r
318 <div class="content">
\r
320 "full_text": "CPU 4%",
\r
321 "min_width": "CPU 100%",
\r
325 <div class="paragraph"><p>An example of a block which uses all possible entries follows:</p></div>
\r
326 <div class="paragraph"><p><strong>Example</strong>:</p></div>
\r
327 <div class="listingblock">
\r
328 <div class="content">
\r
330 "full_text": "E: 10.0.0.1 (1000 Mbit/s)",
\r
331 "short_text": "10.0.0.1",
\r
332 "color": "#00ff00",
\r
336 "name": "ethernet",
\r
337 "instance": "eth0",
\r
339 "separator_block_width": 9
\r
343 <div class="sect2">
\r
344 <h3 id="_click_events">2.3. Click events</h3>
\r
345 <div class="paragraph"><p>If enabled i3bar will send you notifications if the user clicks on a block and
\r
346 looks like this:</p></div>
\r
347 <div class="dlist"><dl>
\r
348 <dt class="hdlist1">
\r
353 Name of the block, if set
\r
356 <dt class="hdlist1">
\r
361 Instance of the block, if set
\r
364 <dt class="hdlist1">
\r
369 X11 root window coordinates where the click occured
\r
372 <dt class="hdlist1">
\r
377 X11 button ID (for example 1 to 3 for left/middle/right mouse button)
\r
381 <div class="paragraph"><p><strong>Example</strong>:</p></div>
\r
382 <div class="listingblock">
\r
383 <div class="content">
\r
385 "name": "ethernet",
\r
386 "instance": "eth0",
\r
396 <div id="footnotes"><hr /></div>
\r
397 <div id="footer" lang="de">
\r
398 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>
\r