summaryrefslogtreecommitdiffstats
path: root/sway/commands/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/layout.c')
-rw-r--r--sway/commands/layout.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/sway/commands/layout.c b/sway/commands/layout.c
new file mode 100644
index 00000000..c4f5d2b5
--- /dev/null
+++ b/sway/commands/layout.c
@@ -0,0 +1,66 @@
1#include <string.h>
2#include "commands.h"
3#include "container.h"
4#include "layout.h"
5
6struct cmd_results *cmd_layout(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if (config->reading) return cmd_results_new(CMD_FAILURE, "layout", "Can't be used in config file.");
9 if (!config->active) return cmd_results_new(CMD_FAILURE, "layout", "Can only be used when sway is running.");
10 if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) {
11 return error;
12 }
13 swayc_t *parent = get_focused_container(&root_container);
14 if (parent->is_floating) {
15 return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows");
16 }
17
18 while (parent->type == C_VIEW) {
19 parent = parent->parent;
20 }
21
22 enum swayc_layouts old_layout = parent->layout;
23
24 if (strcasecmp(argv[0], "default") == 0) {
25 parent->layout = parent->prev_layout;
26 if (parent->layout == L_NONE) {
27 swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT);
28 parent->layout = default_layout(output);
29 }
30 } else {
31 if (parent->layout != L_TABBED && parent->layout != L_STACKED) {
32 parent->prev_layout = parent->layout;
33 }
34
35 if (strcasecmp(argv[0], "tabbed") == 0) {
36 if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){
37 parent = new_container(parent, L_TABBED);
38 }
39
40 parent->layout = L_TABBED;
41 } else if (strcasecmp(argv[0], "stacking") == 0) {
42 if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)) {
43 parent = new_container(parent, L_STACKED);
44 }
45
46 parent->layout = L_STACKED;
47 } else if (strcasecmp(argv[0], "splith") == 0) {
48 parent->layout = L_HORIZ;
49 } else if (strcasecmp(argv[0], "splitv") == 0) {
50 parent->layout = L_VERT;
51 } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) {
52 if (parent->layout == L_VERT) {
53 parent->layout = L_HORIZ;
54 } else {
55 parent->layout = L_VERT;
56 }
57 }
58 }
59
60 update_layout_geometry(parent, old_layout);
61 update_geometry(parent);
62
63 arrange_windows(parent, parent->width, parent->height);
64
65 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
66}