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:
Michael Stapelberg
2012-02-07 17:38:21 -05:00
parent 58ecd14900
commit e114b3dba2
9 changed files with 262 additions and 219 deletions

View File

@ -10,6 +10,23 @@
#ifndef _COMMANDS_PARSER_H
#define _COMMANDS_PARSER_H
char *parse_command(const char *input);
/*
* Holds the result of a call to any command. When calling
* parse_command("floating enable, border none"), the parser will internally
* use a struct CommandResult when calling cmd_floating and cmd_border.
* parse_command will also return another struct CommandResult, whose
* json_output is set to a map of individual json_outputs and whose
* needs_tree_trender is true if any individual needs_tree_render was true.
*
*/
struct CommandResult {
/* The JSON-serialized output of this command. */
char *json_output;
/* Whether the command requires calling tree_render. */
bool needs_tree_render;
};
struct CommandResult *parse_command(const char *input);
#endif