Refactor the interface of commands.c
This change has two implications: 1) tree_render() will now be called precisely once for input which consists of multiple commands (like "focus left; focus right"). Also, the caller of parse_command() has to call it. This makes us able to fix tickets such as ticket #608 (where multiple tree_render() calls are noticable). 2) The output of a command is now a JSON array of return values of the individual subcommands. In the case of "focus left; focus right", this is: [{"success":true}, {"success":true}] While this is incompatible with what i3 returned before, the return value of commands was undocumented and therefore not subject to our API stability.
This commit is contained in:
16
src/ipc.c
16
src/ipc.c
@ -119,16 +119,18 @@ IPC_HANDLER(command) {
|
||||
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);
|
||||
/* If no reply was provided, we just use the default success message */
|
||||
ipc_send_message(fd, strlen(command_output->json_output),
|
||||
I3_IPC_REPLY_TYPE_COMMAND,
|
||||
(const uint8_t*)command_output->json_output);
|
||||
|
||||
free(command_output->json_output);
|
||||
}
|
||||
|
||||
static void dump_rect(yajl_gen gen, const char *name, Rect r) {
|
||||
|
Reference in New Issue
Block a user