From: Michael Stapelberg Date: Tue, 18 Oct 2011 21:12:46 +0000 (+0100) Subject: ipc: when requesting the bar config without a payload, return an array of available... X-Git-Tag: 4.1~92^2~39 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=149b05aacfab6d94d79081b0a2ffa8f44f5720cd;p=i3%2Fi3 ipc: when requesting the bar config without a payload, return an array of available bar IDs --- diff --git a/src/ipc.c b/src/ipc.c index 1660096b..97937c05 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -481,6 +481,34 @@ IPC_HANDLER(get_marks) { * */ IPC_HANDLER(get_bar_config) { +#if YAJL_MAJOR >= 2 + yajl_gen gen = yajl_gen_alloc(NULL); +#else + yajl_gen gen = yajl_gen_alloc(NULL, NULL); +#endif + + /* If no ID was passed, we return a JSON array with all IDs */ + if (message_size == 0) { + y(array_open); + Barconfig *current; + TAILQ_FOREACH(current, &barconfigs, configs) { + ystr(current->id); + } + y(array_close); + + const unsigned char *payload; +#if YAJL_MAJOR >= 2 + size_t length; +#else + unsigned int length; +#endif + y(get_buf, &payload, &length); + + ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_BAR_CONFIG, payload); + y(free); + return; + } + /* To get a properly terminated buffer, we copy * message_size bytes out of the buffer */ char *bar_id = scalloc(message_size + 1); @@ -495,12 +523,6 @@ IPC_HANDLER(get_bar_config) { break; } -#if YAJL_MAJOR >= 2 - yajl_gen gen = yajl_gen_alloc(NULL); -#else - yajl_gen gen = yajl_gen_alloc(NULL, NULL); -#endif - y(map_open); if (!config) {