* when exiting or restarting only!
*
*/
-void ipc_shutdown() {
+void ipc_shutdown(void) {
ipc_client *current;
while (!TAILQ_EMPTY(&all_clients)) {
current = TAILQ_FIRST(&all_clients);
char *command = scalloc(message_size + 1);
strncpy(command, (const char*)message, message_size);
LOG("IPC: received: *%s*\n", command);
- char *reply = parse_command((const char*)command);
- char *save_reply = reply;
+ struct CommandResult *command_output = parse_command((const char*)command);
free(command);
- /* If no reply was provided, we just use the default success message */
- if (reply == NULL)
- reply = "{\"success\":true}";
- ipc_send_message(fd, strlen(reply), I3_IPC_REPLY_TYPE_COMMAND, (const uint8_t*)reply);
+ if (command_output->needs_tree_render)
+ tree_render();
- FREE(save_reply);
+ const unsigned char *reply;
+#if YAJL_MAJOR >= 2
+ size_t length;
+#else
+ unsigned int length;
+#endif
+ yajl_gen_get_buf(command_output->json_gen, &reply, &length);
+
+ ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_COMMAND,
+ (const uint8_t*)reply);
+
+ yajl_gen_free(command_output->json_gen);
}
static void dump_rect(yajl_gen gen, const char *name, Rect r) {
ystr("type");
y(integer, con->type);
+ /* provided for backwards compatibility only. */
ystr("orientation");
- switch (con->orientation) {
- case NO_ORIENTATION:
- ystr("none");
- break;
- case HORIZ:
+ if (!con->split)
+ ystr("none");
+ else {
+ if (con_orientation(con) == HORIZ)
ystr("horizontal");
- break;
- case VERT:
- ystr("vertical");
- break;
+ else ystr("vertical");
}
ystr("scratchpad_state");
ystr("focused");
y(bool, (con == focused));
+ ystr("split");
+ y(bool, con->split);
+
ystr("layout");
switch (con->layout) {
case L_DEFAULT:
- ystr("default");
+ DLOG("About to dump layout=default, this is a bug in the code.\n");
+ assert(false);
+ break;
+ case L_SPLITV:
+ ystr("splitv");
+ break;
+ case L_SPLITH:
+ ystr("splith");
break;
case L_STACKED:
ystr("stacked");
break;
}
+ ystr("last_split_layout");
+ switch (con->layout) {
+ case L_SPLITV:
+ ystr("splitv");
+ break;
+ default:
+ ystr("splith");
+ break;
+ }
+
ystr("border");
switch (con->border_style) {
case BS_NORMAL:
ystr("active");
y(bool, output->active);
+ ystr("primary");
+ y(bool, output->primary);
+
ystr("rect");
y(map_open);
ystr("x");
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.
/* The index of each callback function corresponds to the numeric
* value of the message type (see include/i3/ipc.h) */
-handler_t handlers[7] = {
+handler_t handlers[8] = {
handle_command,
handle_get_workspaces,
handle_subscribe,
handle_tree,
handle_get_marks,
handle_get_bar_config,
+ handle_get_version,
};
/*