+ ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_MARKS, payload);
+ y(free);
+}
+
+/*
+ * Returns the version of i3
+ *
+ */
+IPC_HANDLER(get_version) {
+#if YAJL_MAJOR >= 2
+ yajl_gen gen = yajl_gen_alloc(NULL);
+#else
+ yajl_gen gen = yajl_gen_alloc(NULL, NULL);
+#endif
+ y(map_open);
+
+ ystr("major");
+ y(integer, MAJOR_VERSION);
+
+ ystr("minor");
+ y(integer, MINOR_VERSION);
+
+ ystr("patch");
+ y(integer, PATCH_VERSION);
+
+ ystr("human_readable");
+ ystr(I3_VERSION);
+
+ y(map_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_VERSION, payload);
+ y(free);
+}
+
+/*
+ * Formats the reply message for a GET_BAR_CONFIG request and sends it to the
+ * client.
+ *
+ */
+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);
+ strncpy(bar_id, (const char*)message, message_size);
+ LOG("IPC: looking for config for bar ID \"%s\"\n", bar_id);
+ Barconfig *current, *config = NULL;
+ TAILQ_FOREACH(current, &barconfigs, configs) {
+ if (strcmp(current->id, bar_id) != 0)
+ continue;
+
+ config = current;
+ break;
+ }
+
+ y(map_open);
+
+ if (!config) {
+ /* If we did not find a config for the given ID, the reply will contain
+ * a null 'id' field. */
+ ystr("id");
+ y(null);
+ } else {
+ ystr("id");
+ ystr(config->id);
+
+ if (config->num_outputs > 0) {
+ ystr("outputs");
+ y(array_open);
+ for (int c = 0; c < config->num_outputs; c++)
+ ystr(config->outputs[c]);
+ y(array_close);
+ }
+
+#define YSTR_IF_SET(name) \
+ do { \
+ if (config->name) { \
+ ystr( # name); \
+ ystr(config->name); \
+ } \
+ } while (0)
+
+ YSTR_IF_SET(tray_output);
+ YSTR_IF_SET(socket_path);
+
+ ystr("mode");
+ if (config->mode == M_HIDE)
+ ystr("hide");
+ else ystr("dock");
+
+ ystr("modifier");
+ switch (config->modifier) {
+ case M_CONTROL:
+ ystr("ctrl");
+ break;
+ case M_SHIFT:
+ ystr("shift");
+ break;
+ case M_MOD1:
+ ystr("Mod1");
+ break;
+ case M_MOD2:
+ ystr("Mod2");
+ break;
+ case M_MOD3:
+ ystr("Mod3");
+ break;
+ /*
+ case M_MOD4:
+ ystr("Mod4");
+ break;
+ */
+ case M_MOD5:
+ ystr("Mod5");
+ break;
+ default:
+ ystr("Mod4");
+ break;
+ }
+
+ ystr("position");
+ if (config->position == P_BOTTOM)
+ ystr("bottom");
+ else ystr("top");
+
+ YSTR_IF_SET(status_command);
+ YSTR_IF_SET(font);
+
+ ystr("workspace_buttons");
+ y(bool, !config->hide_workspace_buttons);
+
+ ystr("verbose");
+ y(bool, config->verbose);
+
+#undef YSTR_IF_SET
+#define YSTR_IF_SET(name) \
+ do { \
+ if (config->colors.name) { \
+ ystr( # name); \
+ ystr(config->colors.name); \
+ } \
+ } while (0)
+
+ ystr("colors");
+ y(map_open);
+ YSTR_IF_SET(background);
+ YSTR_IF_SET(statusline);
+ YSTR_IF_SET(focused_workspace_border);
+ YSTR_IF_SET(focused_workspace_bg);
+ YSTR_IF_SET(focused_workspace_text);
+ YSTR_IF_SET(active_workspace_border);
+ YSTR_IF_SET(active_workspace_bg);
+ YSTR_IF_SET(active_workspace_text);
+ YSTR_IF_SET(inactive_workspace_border);
+ YSTR_IF_SET(inactive_workspace_bg);
+ YSTR_IF_SET(inactive_workspace_text);
+ YSTR_IF_SET(urgent_workspace_border);
+ YSTR_IF_SET(urgent_workspace_bg);
+ YSTR_IF_SET(urgent_workspace_text);
+ y(map_close);
+
+#undef YSTR_IF_SET
+ }
+
+ y(map_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);