aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-04-02 13:49:37 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-06 09:43:52 -0400
commit57954a2b24f1e211c3b8811fb898ef4e076cb098 (patch)
treeb9977589b4b84811e31c0edec636252d04603ec7 /sway/tree/container.c
parentAvoid arranging windows while reloading config (diff)
downloadsway-57954a2b24f1e211c3b8811fb898ef4e076cb098.tar.gz
sway-57954a2b24f1e211c3b8811fb898ef4e076cb098.tar.zst
sway-57954a2b24f1e211c3b8811fb898ef4e076cb098.zip
Implement move [left|right|up|down]
The exact semantics of this command are complicated. I'll describe each test scenario as s-expressions. Everything assumes L_HORIZ if not specified, but if you rotate everything 90 degrees the same test cases hold. ``` (container (view a) (view b focus) (view c)) -> move left (container (view b focus) (view a) (view c)) (container (view a) (view b focus) (view c)) -> move right (container (view a) (view c) (view b focus)) (container L_VERT (view a)) (container L_HORIZ (view b) (view c focus)) -> move up (container L_VERT (view a) (view c focus)) (container L_HORIZ (view b)) (workspace (view a) (view b focus) (view c)) -> move up (workspace [split direction flipped] (view b focus) (container (view a) (view c))) (workspace (view a) (view b focus) (view c)) -> move down (workspace [split direction flipped] (container (view a) (view c)) (view b focus))) Note: outputs use wlr_output_layout instead of assuming that i+/-1 is the next output in the move direction. (root (output X11-1 (workspace 1)) (output X11-2 (workspace 1 (view a focus) (view b))))) -> move left (root (output X11-1 (workspace 1 (view a focus))) (output X11-2 (workspace 1 (view b))))) (root (output X11-1 (workspace 1 (container (view a) (view b))) (output X11-2 (workspace 1 (view c focus))))) -> move left (root (output X11-1 (workspace 1 (container (view a) (view b)) (view c focus))) (output X11-2 (workspace 1))) ```
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index ab8363bc..ea1c93bb 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -208,7 +208,7 @@ static void container_root_finish(struct sway_container *con) {
208 wlr_log(L_ERROR, "TODO: destroy the root container"); 208 wlr_log(L_ERROR, "TODO: destroy the root container");
209} 209}
210 210
211static bool container_reap_empty(struct sway_container *con) { 211bool container_reap_empty(struct sway_container *con) {
212 switch (con->type) { 212 switch (con->type) {
213 case C_ROOT: 213 case C_ROOT:
214 case C_OUTPUT: 214 case C_OUTPUT:
@@ -225,14 +225,6 @@ static bool container_reap_empty(struct sway_container *con) {
225 if (con->children->length == 0) { 225 if (con->children->length == 0) {
226 _container_destroy(con); 226 _container_destroy(con);
227 return true; 227 return true;
228 } else if (con->children->length == 1) {
229 struct sway_container *child = con->children->items[0];
230 if (child->type == C_CONTAINER) {
231 container_remove_child(child);
232 container_replace_child(con, child);
233 _container_destroy(con);
234 return true;
235 }
236 } 228 }
237 case C_VIEW: 229 case C_VIEW:
238 break; 230 break;
@@ -245,6 +237,29 @@ static bool container_reap_empty(struct sway_container *con) {
245 return false; 237 return false;
246} 238}
247 239
240struct sway_container *container_reap_empty_recursive(
241 struct sway_container *con) {
242 while (con) {
243 struct sway_container *next = con->parent;
244 if (!container_reap_empty(con)) {
245 break;
246 }
247 con = next;
248 }
249 return con;
250}
251
252struct sway_container *container_flatten(struct sway_container *container) {
253 while (container->type == C_CONTAINER && container->children->length == 1) {
254 struct sway_container *child = container->children->items[0];
255 struct sway_container *parent = container->parent;
256 container_replace_child(container, child);
257 container_destroy(container);
258 container = parent;
259 }
260 return container;
261}
262
248struct sway_container *container_destroy(struct sway_container *con) { 263struct sway_container *container_destroy(struct sway_container *con) {
249 if (con == NULL) { 264 if (con == NULL) {
250 return NULL; 265 return NULL;
@@ -283,18 +298,7 @@ struct sway_container *container_destroy(struct sway_container *con) {
283 break; 298 break;
284 } 299 }
285 300
286 struct sway_container *tmp = parent; 301 return container_reap_empty_recursive(parent);
287 while (parent) {
288 tmp = parent->parent;
289
290 if (!container_reap_empty(parent)) {
291 break;
292 }
293
294 parent = tmp;
295 }
296
297 return tmp;
298} 302}
299 303
300static void container_close_func(struct sway_container *container, void *data) { 304static void container_close_func(struct sway_container *container, void *data) {