diff options
Diffstat (limited to 'sway/commands/layout.c')
-rw-r--r-- | sway/commands/layout.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/sway/commands/layout.c b/sway/commands/layout.c new file mode 100644 index 00000000..b0fc5d66 --- /dev/null +++ b/sway/commands/layout.c | |||
@@ -0,0 +1,56 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/container.h" | ||
5 | #include "sway/layout.h" | ||
6 | #include "log.h" | ||
7 | |||
8 | struct cmd_results *cmd_layout(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) { | ||
11 | return error; | ||
12 | } | ||
13 | swayc_t *parent = config->handler_context.current_container; | ||
14 | |||
15 | // TODO: floating | ||
16 | /* | ||
17 | if (parent->is_floating) { | ||
18 | return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows"); | ||
19 | } | ||
20 | */ | ||
21 | |||
22 | while (parent->type == C_VIEW) { | ||
23 | parent = parent->parent; | ||
24 | } | ||
25 | |||
26 | // TODO: stacks and tabs | ||
27 | |||
28 | if (strcasecmp(argv[0], "default") == 0) { | ||
29 | swayc_change_layout(parent, parent->prev_layout); | ||
30 | if (parent->layout == L_NONE) { | ||
31 | swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); | ||
32 | swayc_change_layout(parent, default_layout(output)); | ||
33 | } | ||
34 | } else { | ||
35 | if (parent->layout != L_TABBED && parent->layout != L_STACKED) { | ||
36 | parent->prev_layout = parent->layout; | ||
37 | } | ||
38 | |||
39 | if (strcasecmp(argv[0], "splith") == 0) { | ||
40 | swayc_change_layout(parent, L_HORIZ); | ||
41 | } else if (strcasecmp(argv[0], "splitv") == 0) { | ||
42 | swayc_change_layout(parent, L_VERT); | ||
43 | } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { | ||
44 | if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE | ||
45 | || parent->workspace_layout == L_HORIZ)) { | ||
46 | swayc_change_layout(parent, L_VERT); | ||
47 | } else { | ||
48 | swayc_change_layout(parent, L_HORIZ); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
53 | arrange_windows(parent, parent->width, parent->height); | ||
54 | |||
55 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
56 | } | ||