From d5b4c8e368050cf1b84b03c1379bbbc3c817a713 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 16 Feb 2012 23:29:29 +0000 Subject: 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. --- i3status.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'i3status.c') diff --git a/i3status.c b/i3status.c index 9f04850..dd7d1e6 100644 --- a/i3status.c +++ b/i3status.c @@ -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); -- cgit v1.2.3