aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/layout.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-11-18 11:22:02 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-11-18 11:22:02 -0500
commit733993a651c71f7e2198d505960d6bbd31e0e107 (patch)
treee51732c5872b624e73355f9e5b3f762101f3cd0d /sway/commands/layout.c
parentInitial (awful) pass on xdg shell support (diff)
downloadsway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.gz
sway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.zst
sway-733993a651c71f7e2198d505960d6bbd31e0e107.zip
Move everything to sway/old/
Diffstat (limited to 'sway/commands/layout.c')
-rw-r--r--sway/commands/layout.c196
1 files changed, 0 insertions, 196 deletions
diff --git a/sway/commands/layout.c b/sway/commands/layout.c
deleted file mode 100644
index 57a86565..00000000
--- a/sway/commands/layout.c
+++ /dev/null
@@ -1,196 +0,0 @@
1#include <string.h>
2#include <strings.h>
3#include "sway/commands.h"
4#include "sway/container.h"
5#include "sway/layout.h"
6
7/**
8 * handle "layout auto" command group
9 */
10static struct cmd_results *cmd_layout_auto(swayc_t *container, int argc, char **argv);
11
12struct cmd_results *cmd_layout(int argc, char **argv) {
13 struct cmd_results *error = NULL;
14 if (config->reading) return cmd_results_new(CMD_FAILURE, "layout", "Can't be used in config file.");
15 if (!config->active) return cmd_results_new(CMD_FAILURE, "layout", "Can only be used when sway is running.");
16 if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) {
17 return error;
18 }
19 swayc_t *parent = current_container;
20 if (parent->is_floating) {
21 return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows");
22 }
23
24 while (parent->type == C_VIEW) {
25 parent = parent->parent;
26 }
27
28 enum swayc_layouts old_layout = parent->layout;
29
30 if (strcasecmp(argv[0], "default") == 0) {
31 swayc_change_layout(parent, parent->prev_layout);
32 if (parent->layout == L_NONE) {
33 swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT);
34 swayc_change_layout(parent, default_layout(output));
35 }
36 } else {
37 if (parent->layout != L_TABBED && parent->layout != L_STACKED) {
38 parent->prev_layout = parent->layout;
39 }
40
41 if (strcasecmp(argv[0], "tabbed") == 0) {
42 if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){
43 parent = new_container(parent, L_TABBED);
44 }
45
46 swayc_change_layout(parent, L_TABBED);
47 } else if (strcasecmp(argv[0], "stacking") == 0) {
48 if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)) {
49 parent = new_container(parent, L_STACKED);
50 }
51
52 swayc_change_layout(parent, L_STACKED);
53 } else if (strcasecmp(argv[0], "splith") == 0) {
54 swayc_change_layout(parent, L_HORIZ);
55 } else if (strcasecmp(argv[0], "splitv") == 0) {
56 swayc_change_layout(parent, L_VERT);
57 } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) {
58 if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE
59 || parent->workspace_layout == L_HORIZ)) {
60 swayc_change_layout(parent, L_VERT);
61 } else {
62 swayc_change_layout(parent, L_HORIZ);
63 }
64 } else if (strcasecmp(argv[0], "auto") == 0) {
65 return cmd_layout_auto(parent, argc, argv);
66 }
67 }
68
69 update_layout_geometry(parent, old_layout);
70 update_geometry(parent);
71
72 arrange_windows(parent, parent->width, parent->height);
73
74 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
75}
76
77static struct cmd_results *cmd_layout_auto(swayc_t *container, int argc, char **argv) {
78 // called after checking that argv[0] is auto, so just continue parsing from there
79 struct cmd_results *error = NULL;
80 const char *cmd_name = "layout auto";
81 const char *set_inc_cmd_name = "layout auto [master|ncol] [set|inc]";
82 const char *err_msg = "Allowed arguments are <right|left|top|bottom|next|prev|master|ncol>";
83
84 bool need_layout_update = false;
85 enum swayc_layouts old_layout = container->layout;
86 enum swayc_layouts layout = old_layout;
87
88 if ((error = checkarg(argc, "layout auto", EXPECTED_MORE_THAN, 1))) {
89 return error;
90 }
91
92 if (strcasecmp(argv[1], "left") == 0) {
93 layout = L_AUTO_LEFT;
94 } else if (strcasecmp(argv[1], "right") == 0) {
95 layout = L_AUTO_RIGHT;
96 } else if (strcasecmp(argv[1], "top") == 0) {
97 layout = L_AUTO_TOP;
98 } else if (strcasecmp(argv[1], "bottom") == 0) {
99 layout = L_AUTO_BOTTOM;
100 } else if (strcasecmp(argv[1], "next") == 0) {
101 if (is_auto_layout(container->layout) && container->layout < L_AUTO_LAST) {
102 layout = container->layout + 1;
103 } else {
104 layout = L_AUTO_FIRST;
105 }
106 } else if (strcasecmp(argv[1], "prev") == 0) {
107 if (is_auto_layout(container->layout) && container->layout > L_AUTO_FIRST) {
108 layout = container->layout - 1;
109 } else {
110 layout = L_AUTO_LAST;
111 }
112 } else {
113 bool is_nmaster;
114 bool is_set;
115 if (strcasecmp(argv[1], "master") == 0) {
116 is_nmaster = true;
117 } else if (strcasecmp(argv[1], "ncol") == 0) {
118 is_nmaster = false;
119 } else {
120 return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command. %s",
121 cmd_name, err_msg);
122 }
123 if ((error = checkarg(argc, "auto <master|ncol>", EXPECTED_EQUAL_TO, 4))) {
124 return error;
125 }
126 if (strcasecmp(argv[2], "set") == 0) {
127 is_set = true;
128 } else if (strcasecmp(argv[2], "inc") == 0) {
129 is_set = false;
130 } else {
131 return cmd_results_new(CMD_INVALID, set_inc_cmd_name, "Invalid %s command. %s, "
132 "Argument must be on of <set|inc>",
133 set_inc_cmd_name);
134 }
135 char *end;
136 int n = (int)strtol(argv[3], &end, 10);
137 if (*end) {
138 return cmd_results_new(CMD_INVALID, set_inc_cmd_name, "Invalid %s command "
139 "(argument must be an integer)", set_inc_cmd_name);
140 }
141 if (is_auto_layout(container->layout)) {
142 int inc = 0; /* difference between current master/ncol and requested value */
143 if (is_nmaster) {
144 if (is_set) {
145 if (n < 0) {
146 return cmd_results_new(CMD_INVALID, set_inc_cmd_name, "Invalid %s command "
147 "(master must be >= 0)", set_inc_cmd_name);
148 }
149 inc = n - (int)container->nb_master;
150 } else { /* inc command */
151 if ((int)container->nb_master + n >= 0) {
152 inc = n;
153 }
154 }
155 if (inc) {
156 for (int i = container->nb_master;
157 i >= 0 && i < container->children->length
158 && i != (int)container->nb_master + inc;) {
159 ((swayc_t *)container->children->items[i])->height = -1;
160 ((swayc_t *)container->children->items[i])->width = -1;
161 i += inc > 0 ? 1 : -1;
162 }
163 container->nb_master += inc;
164 need_layout_update = true;
165 }
166 } else { /* ncol modification */
167 if (is_set) {
168 if (n <= 0) {
169 return cmd_results_new(CMD_INVALID, set_inc_cmd_name, "Invalid %s command "
170 "(ncol must be > 0)", set_inc_cmd_name);
171 }
172 inc = n - (int)container->nb_slave_groups;
173 } else { /* inc command */
174 if ((int)container->nb_slave_groups + n > 0) {
175 inc = n;
176 }
177 }
178 if (inc) {
179 container->nb_slave_groups += inc;
180 need_layout_update = true;
181 }
182 }
183 }
184 }
185
186 if (layout != old_layout) {
187 swayc_change_layout(container, layout);
188 update_layout_geometry(container, old_layout);
189 need_layout_update = true;
190 }
191 if (need_layout_update) {
192 update_geometry(container);
193 arrange_windows(container, container->width, container->height);
194 }
195 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
196}