]> git.sur5r.net Git - i3/i3/commitdiff
ipc: when requesting the bar config without a payload, return an array of available...
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 18 Oct 2011 21:12:46 +0000 (22:12 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 18 Oct 2011 21:12:46 +0000 (22:12 +0100)
src/ipc.c

index 1660096be255bc25a6fe6a7b054ed0a7e56e4f63..97937c058538738ef3a68f083b5c34d3ff5271cd 100644 (file)
--- 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) {