aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-04-06 13:17:22 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-06 13:17:22 -0400
commit1f70b94f34813ee997a175e943dabbfec96648a6 (patch)
tree60d2f9565199b9849d4955aad6749fe1940a5dc4
parentFix issues @orestisf1993 raised (diff)
downloadsway-1f70b94f34813ee997a175e943dabbfec96648a6.tar.gz
sway-1f70b94f34813ee997a175e943dabbfec96648a6.tar.zst
sway-1f70b94f34813ee997a175e943dabbfec96648a6.zip
Fix moving into right end of container
-rw-r--r--sway/tree/layout.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index a0586f40..f4049c71 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -107,6 +107,7 @@ void container_insert_child(struct sway_container *parent,
107 if (old_parent) { 107 if (old_parent) {
108 container_remove_child(child); 108 container_remove_child(child);
109 } 109 }
110 wlr_log(L_DEBUG, "Inserting id:%zd at index %d", child->id, i);
110 list_insert(parent->children, i, child); 111 list_insert(parent->children, i, child);
111 child->parent = parent; 112 child->parent = parent;
112 wl_signal_emit(&child->events.reparent, old_parent); 113 wl_signal_emit(&child->events.reparent, old_parent);
@@ -229,23 +230,24 @@ static enum movement_direction invert_movement(enum movement_direction dir) {
229 case MOVE_UP: 230 case MOVE_UP:
230 return MOVE_DOWN; 231 return MOVE_DOWN;
231 case MOVE_DOWN: 232 case MOVE_DOWN:
232 return MOVE_LEFT; 233 return MOVE_UP;
233 default: 234 default:
234 sway_assert(0, "This function expects left|right|up|down"); 235 sway_assert(0, "This function expects left|right|up|down");
235 return MOVE_LEFT; 236 return MOVE_LEFT;
236 } 237 }
237} 238}
238 239
240static int move_offs(enum movement_direction move_dir) {
241 return move_dir == MOVE_LEFT || move_dir == MOVE_UP ? -1 : 1;
242}
243
239/* Gets the index of the most extreme member based on the movement offset */ 244/* Gets the index of the most extreme member based on the movement offset */
240static int container_limit(struct sway_container *container, int offs) { 245static int container_limit(struct sway_container *container,
246 enum movement_direction move_dir) {
241 if (container->children->length == 0) { 247 if (container->children->length == 0) {
242 return 0; 248 return 0;
243 } 249 }
244 return offs < 0 ? 0 : container->children->length - 1; 250 return move_offs(move_dir) < 0 ? 0 : container->children->length - 1;
245}
246
247static int move_offs(enum movement_direction move_dir) {
248 return move_dir == MOVE_LEFT || move_dir == MOVE_UP ? -1 : 1;
249} 251}
250 252
251static void workspace_rejigger(struct sway_container *ws, 253static void workspace_rejigger(struct sway_container *ws,
@@ -301,7 +303,7 @@ void container_move(struct sway_container *container,
301 container_type_to_str(current->type), current->name); 303 container_type_to_str(current->type), current->name);
302 304
303 int index = index_child(current); 305 int index = index_child(current);
304 int limit = container_limit(parent, offs); 306 int limit = container_limit(parent, move_dir);
305 307
306 switch (current->type) { 308 switch (current->type) {
307 case C_OUTPUT: { 309 case C_OUTPUT: {
@@ -402,9 +404,11 @@ void container_move(struct sway_container *container,
402 case C_WORKSPACE: // Note: only in the case of moving between outputs 404 case C_WORKSPACE: // Note: only in the case of moving between outputs
403 case C_CONTAINER: 405 case C_CONTAINER:
404 if (is_parallel(sibling->layout, move_dir)) { 406 if (is_parallel(sibling->layout, move_dir)) {
405 int limit = container_limit(sibling, move_dir); 407 int limit = container_limit(sibling, invert_movement(move_dir));
406 wlr_log(L_DEBUG, "Reparenting container (paralell)");
407 limit = limit != 0 ? limit + 1 : limit; // Convert to index 408 limit = limit != 0 ? limit + 1 : limit; // Convert to index
409 wlr_log(L_DEBUG,
410 "Reparenting container (parallel) to index %d "
411 "(move dir: %d)", limit, move_dir);
408 container_insert_child(sibling, container, limit); 412 container_insert_child(sibling, container, limit);
409 container->width = container->height = 0; 413 container->width = container->height = 0;
410 arrange_windows(sibling, -1, -1); 414 arrange_windows(sibling, -1, -1);
@@ -421,8 +425,10 @@ void container_move(struct sway_container *container,
421 sibling = focus_inactive; 425 sibling = focus_inactive;
422 continue; 426 continue;
423 } else if (sibling->children->length) { 427 } else if (sibling->children->length) {
428 wlr_log(L_DEBUG, "No focus-inactive, adding arbitrarily");
424 container_add_sibling(sibling->children->items[0], container); 429 container_add_sibling(sibling->children->items[0], container);
425 } else { 430 } else {
431 wlr_log(L_DEBUG, "No kiddos, adding container alone");
426 container_add_child(sibling, container); 432 container_add_child(sibling, container);
427 } 433 }
428 container->width = container->height = 0; 434 container->width = container->height = 0;