]> git.sur5r.net Git - i3/i3/blob - include/commands_parser.h
Merge branch 'release-4.16.1'
[i3/i3] / include / commands_parser.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * commands.c: all command functions (see commands_parser.c)
8  *
9  */
10 #pragma once
11
12 #include <config.h>
13
14 #include <yajl/yajl_gen.h>
15
16 /**
17  * Holds an intermediate represenation of the result of a call to any command.
18  * When calling parse_command("floating enable, border none"), the parser will
19  * internally use this struct when calling cmd_floating and cmd_border.
20  */
21 struct CommandResultIR {
22     /* The JSON generator to append a reply to (may be NULL). */
23     yajl_gen json_gen;
24
25     /* The next state to transition to. Passed to the function so that we can
26      * determine the next state as a result of a function call, like
27      * cfg_criteria_pop_state() does. */
28     int next_state;
29
30     /* Whether the command requires calling tree_render. */
31     bool needs_tree_render;
32 };
33
34 typedef struct CommandResult CommandResult;
35
36 /**
37  * A struct that contains useful information about the result of a command as a
38  * whole (e.g. a compound command like "floating enable, border none").
39  * needs_tree_render is true if needs_tree_render of any individual command was
40  * true.
41  */
42 struct CommandResult {
43     bool parse_error;
44     /* the error_message is currently only set for parse errors */
45     char *error_message;
46     bool needs_tree_render;
47 };
48
49 /**
50  * Parses a string (or word, if as_word is true). Extracted out of
51  * parse_command so that it can be used in src/workspace.c for interpreting
52  * workspace commands.
53  *
54  */
55 char *parse_string(const char **walk, bool as_word);
56
57 /**
58  * Parses and executes the given command. If a caller-allocated yajl_gen is
59  * passed, a json reply will be generated in the format specified by the ipc
60  * protocol. Pass NULL if no json reply is required.
61  *
62  * Free the returned CommandResult with command_result_free().
63  */
64 CommandResult *parse_command(const char *input, yajl_gen gen);
65
66 /**
67  * Frees a CommandResult
68  */
69 void command_result_free(CommandResult *result);