diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2012-02-16 23:29:29 +0000 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2012-02-16 23:30:54 +0000 |
commit | d5b4c8e368050cf1b84b03c1379bbbc3c817a713 (patch) | |
tree | 2f918d4c5b95a05ebec68bceec35f7d4fa9a0c4e /i3status.c | |
parent | 7149f6f78e0d105f02d54e1db60db8b191a98acb (diff) |
Implement the i3bar JSON protocol
This hardcodes all the JSON parts. Strings are not properly escaped currently.
The best/easiest way to fix this is by actually using libyajl.
Diffstat (limited to 'i3status.c')
-rw-r--r-- | i3status.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -331,6 +331,8 @@ int main(int argc, char *argv[]) { output_format = O_DZEN2; else if (strcasecmp(output_str, "xmobar") == 0) output_format = O_XMOBAR; + else if (strcasecmp(output_str, "i3bar") == 0) + output_format = O_I3BAR; else if (strcasecmp(output_str, "none") == 0) output_format = O_NONE; else die("Unknown output format: \"%s\"\n", output_str); @@ -341,6 +343,12 @@ int main(int argc, char *argv[]) { || !valid_color(cfg_getstr(cfg_general, "color_separator"))) die("Bad color format"); + if (output_format == O_I3BAR) { + /* Initialize the i3bar protocol. See i3/docs/i3bar-protocol + * for details. */ + printf("{\"version\":1}\n[\n"); + } + if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) die("Could not create socket\n"); @@ -356,6 +364,8 @@ int main(int argc, char *argv[]) { localtime_r(¤t_time, &tm); current_tm = &tm; } + if (output_format == O_I3BAR) + printf("["); for (j = 0; j < cfg_size(cfg, "order"); j++) { if (j > 0) print_seperator(); @@ -401,6 +411,8 @@ int main(int argc, char *argv[]) { CASE_SEC("cpu_usage") print_cpu_usage(cfg_getstr(sec, "format")); } + if (output_format == O_I3BAR) + printf("],"); printf("\n"); fflush(stdout); |