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.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
13 window.onload = function(){asciidoc.footnotes();}
\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 }</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
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
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
194 <dt class="hdlist1">
\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
209 <dt class="hdlist1">
\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
223 <dt class="hdlist1">
\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
235 <dt class="hdlist1">
\r
240 Align text on the <tt>center</tt> (default), <tt>right</tt> or <tt>left</tt> of the block, when
\r
241 the minimum width of the latter, specified by the <tt>min_width</tt> key, is not
\r
245 <dt class="hdlist1">
\r
250 Every block should have a unique <tt>name</tt> (string) entry so that it can
\r
251 be easily identified in scripts which process the output. i3bar
\r
252 completely ignores the name and instance fields. Make sure to also
\r
253 specify an <tt>instance</tt> (string) entry where appropriate. For example,
\r
254 the user can have multiple disk space blocks for multiple mount points.
\r
257 <dt class="hdlist1">
\r
262 A boolean which specifies whether the current value is urgent. Examples
\r
263 are battery charge values below 1 percent or no more available disk
\r
264 space (for non-root users). The presentation of urgency is up to i3bar.
\r
268 <div class="paragraph"><p>If you want to put in your own entries into a block, prefix the key with an
\r
269 underscore (_). i3bar will ignore all keys it doesn’t understand, and prefixing
\r
270 them with an underscore makes it clear in every script that they are not part
\r
271 of the i3bar protocol.</p></div>
\r
272 <div class="paragraph"><p><strong>Example</strong>:</p></div>
\r
273 <div class="listingblock">
\r
274 <div class="content">
\r
276 "full_text": "E: 10.0.0.1 (1000 Mbit/s)",
\r
277 "_ethernet_vendor": "Intel"
\r
280 <div class="paragraph"><p>An example of a block which uses all possible entries follows:</p></div>
\r
281 <div class="paragraph"><p><strong>Example</strong>:</p></div>
\r
282 <div class="listingblock">
\r
283 <div class="content">
\r
285 "full_text": "E: 10.0.0.1 (1000 Mbit/s)",
\r
286 "short_text": "10.0.0.1",
\r
287 "color": "#00ff00",
\r
291 "name": "ethernet",
\r
299 <div id="footnotes"><hr /></div>
\r
300 <div id="footer" lang="de">
\r
301 © 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>
\r