diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-02-22 18:03:46 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-02-22 18:37:14 -0500 |
commit | 66d1e0b313c6bbee142bb08e4af07ce6f15cffca (patch) | |
tree | f00e015bbf929b4d88bfe5b12e0f809f2c27525e | |
parent | bug: fix crash on focus up (diff) | |
download | sway-66d1e0b313c6bbee142bb08e4af07ce6f15cffca.tar.gz sway-66d1e0b313c6bbee142bb08e4af07ce6f15cffca.tar.zst sway-66d1e0b313c6bbee142bb08e4af07ce6f15cffca.zip |
basic layout command
-rw-r--r-- | include/sway/container.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/layout.c | 65 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/tree/container.c | 12 |
5 files changed, 81 insertions, 0 deletions
diff --git a/include/sway/container.h b/include/sway/container.h index 48363be6..f200a1a2 100644 --- a/include/sway/container.h +++ b/include/sway/container.h | |||
@@ -164,4 +164,6 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | |||
164 | void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | 164 | void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), |
165 | void *data); | 165 | void *data); |
166 | 166 | ||
167 | swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout); | ||
168 | |||
167 | #endif | 169 | #endif |
diff --git a/sway/commands.c b/sway/commands.c index bc2a85d7..a7eb6b4a 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -136,6 +136,7 @@ static struct cmd_handler handlers[] = { | |||
136 | { "include", cmd_include }, | 136 | { "include", cmd_include }, |
137 | { "input", cmd_input }, | 137 | { "input", cmd_input }, |
138 | { "kill", cmd_kill }, | 138 | { "kill", cmd_kill }, |
139 | { "layout", cmd_layout }, | ||
139 | { "output", cmd_output }, | 140 | { "output", cmd_output }, |
140 | { "reload", cmd_reload }, | 141 | { "reload", cmd_reload }, |
141 | { "seat", cmd_seat }, | 142 | { "seat", cmd_seat }, |
diff --git a/sway/commands/layout.c b/sway/commands/layout.c new file mode 100644 index 00000000..d953abc8 --- /dev/null +++ b/sway/commands/layout.c | |||
@@ -0,0 +1,65 @@ | |||
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 (config->reading) { | ||
11 | return cmd_results_new(CMD_FAILURE, "layout", "Can't be used in config file."); | ||
12 | } | ||
13 | if (!config->active) { | ||
14 | return cmd_results_new(CMD_FAILURE, "layout", "Can only be used when sway is running."); | ||
15 | } | ||
16 | if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) { | ||
17 | return error; | ||
18 | } | ||
19 | swayc_t *parent = config->handler_context.current_container; | ||
20 | if (!sway_assert(parent != NULL, "command called without container context")) { | ||
21 | return NULL; | ||
22 | } | ||
23 | |||
24 | // TODO: floating | ||
25 | /* | ||
26 | if (parent->is_floating) { | ||
27 | return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows"); | ||
28 | } | ||
29 | */ | ||
30 | |||
31 | while (parent->type == C_VIEW) { | ||
32 | parent = parent->parent; | ||
33 | } | ||
34 | |||
35 | // TODO: stacks and tabs | ||
36 | |||
37 | if (strcasecmp(argv[0], "default") == 0) { | ||
38 | swayc_change_layout(parent, parent->prev_layout); | ||
39 | if (parent->layout == L_NONE) { | ||
40 | swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); | ||
41 | swayc_change_layout(parent, default_layout(output)); | ||
42 | } | ||
43 | } else { | ||
44 | if (parent->layout != L_TABBED && parent->layout != L_STACKED) { | ||
45 | parent->prev_layout = parent->layout; | ||
46 | } | ||
47 | |||
48 | if (strcasecmp(argv[0], "splith") == 0) { | ||
49 | swayc_change_layout(parent, L_HORIZ); | ||
50 | } else if (strcasecmp(argv[0], "splitv") == 0) { | ||
51 | swayc_change_layout(parent, L_VERT); | ||
52 | } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { | ||
53 | if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE | ||
54 | || parent->workspace_layout == L_HORIZ)) { | ||
55 | swayc_change_layout(parent, L_VERT); | ||
56 | } else { | ||
57 | swayc_change_layout(parent, L_HORIZ); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | arrange_windows(parent, parent->width, parent->height); | ||
63 | |||
64 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
65 | } | ||
diff --git a/sway/meson.build b/sway/meson.build index 8d5a97d2..26e56ad2 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -14,6 +14,7 @@ sway_sources = files( | |||
14 | 'commands/kill.c', | 14 | 'commands/kill.c', |
15 | 'commands/include.c', | 15 | 'commands/include.c', |
16 | 'commands/input.c', | 16 | 'commands/input.c', |
17 | 'commands/layout.c', | ||
17 | 'commands/seat.c', | 18 | 'commands/seat.c', |
18 | 'commands/seat/attach.c', | 19 | 'commands/seat/attach.c', |
19 | 'commands/seat/fallback.c', | 20 | 'commands/seat/fallback.c', |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 84e14ba6..b56e72e1 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -400,3 +400,15 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | |||
400 | 400 | ||
401 | list_free(queue); | 401 | list_free(queue); |
402 | } | 402 | } |
403 | |||
404 | swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) { | ||
405 | if (container->type == C_WORKSPACE) { | ||
406 | container->workspace_layout = layout; | ||
407 | if (layout == L_HORIZ || layout == L_VERT) { | ||
408 | container->layout = layout; | ||
409 | } | ||
410 | } else { | ||
411 | container->layout = layout; | ||
412 | } | ||
413 | return container; | ||
414 | } | ||