aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/layout.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-22 18:03:46 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-22 18:37:14 -0500
commit66d1e0b313c6bbee142bb08e4af07ce6f15cffca (patch)
treef00e015bbf929b4d88bfe5b12e0f809f2c27525e /sway/commands/layout.c
parentbug: fix crash on focus up (diff)
downloadsway-66d1e0b313c6bbee142bb08e4af07ce6f15cffca.tar.gz
sway-66d1e0b313c6bbee142bb08e4af07ce6f15cffca.tar.zst
sway-66d1e0b313c6bbee142bb08e4af07ce6f15cffca.zip
basic layout command
Diffstat (limited to 'sway/commands/layout.c')
-rw-r--r--sway/commands/layout.c65
1 files changed, 65 insertions, 0 deletions
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
8struct 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}