summaryrefslogtreecommitdiffstats
path: root/sway/tree/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r--sway/tree/layout.c70
1 files changed, 38 insertions, 32 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 122ea494..3333f9f1 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -106,8 +106,10 @@ struct sway_container *container_reap_empty(struct sway_container *container) {
106 if (!sway_assert(container, "reaping null container")) { 106 if (!sway_assert(container, "reaping null container")) {
107 return NULL; 107 return NULL;
108 } 108 }
109 wlr_log(L_DEBUG, "reaping %p %s", container, container->name); 109 wlr_log(L_DEBUG, "Reaping %p %s '%s'", container,
110 while (container != &root_container && container->children->length == 0) { 110 container_type_to_str(container->type), container->name);
111 while (container->type != C_ROOT && container->type != C_OUTPUT
112 && container->children->length == 0) {
111 if (container->type == C_WORKSPACE) { 113 if (container->type == C_WORKSPACE) {
112 if (!workspace_is_visible(container)) { 114 if (!workspace_is_visible(container)) {
113 struct sway_container *parent = container->parent; 115 struct sway_container *parent = container->parent;
@@ -138,22 +140,46 @@ struct sway_container *container_remove_child(struct sway_container *child) {
138 return container_reap_empty(parent); 140 return container_reap_empty(parent);
139} 141}
140 142
141void container_move_to(struct sway_container* container, 143void container_move_to(struct sway_container *container,
142 struct sway_container* destination) { 144 struct sway_container *destination) {
143 if (container == destination 145 if (container == destination
144 || container_has_anscestor(container, destination)) { 146 || container_has_anscestor(container, destination)) {
145 return; 147 return;
146 } 148 }
147 struct sway_container *old_parent = container_remove_child(container); 149 struct sway_container *old_parent = container_remove_child(container);
148 container->width = container->height = 0; 150 container->width = container->height = 0;
149 struct sway_container *new_parent = 151 struct sway_container *new_parent;
150 container_add_sibling(destination, container); 152 if (destination->type == C_VIEW) {
153 new_parent = container_add_sibling(destination, container);
154 } else {
155 new_parent = destination;
156 container_add_child(destination, container);
157 }
158 wl_signal_emit(&container->events.reparent, old_parent);
159 if (container->type == C_WORKSPACE) {
160 struct sway_seat *seat = input_manager_get_default_seat(
161 input_manager);
162 if (old_parent->children->length == 0) {
163 char *ws_name = workspace_next_name(old_parent->name);
164 struct sway_container *ws =
165 container_workspace_create(old_parent, ws_name);
166 free(ws_name);
167 seat_set_focus(seat, ws);
168 }
169 container_sort_workspaces(new_parent);
170 seat_set_focus(seat, new_parent);
171 }
151 if (old_parent) { 172 if (old_parent) {
152 arrange_windows(old_parent, -1, -1); 173 arrange_windows(old_parent, -1, -1);
153 } 174 }
154 arrange_windows(new_parent, -1, -1); 175 arrange_windows(new_parent, -1, -1);
155} 176}
156 177
178void container_move(struct sway_container *container,
179 enum movement_direction dir, int move_amt) {
180 // TODO
181}
182
157enum sway_container_layout container_get_default_layout( 183enum sway_container_layout container_get_default_layout(
158 struct sway_container *output) { 184 struct sway_container *output) {
159 if (config->default_layout != L_NONE) { 185 if (config->default_layout != L_NONE) {
@@ -248,8 +274,8 @@ void arrange_windows(struct sway_container *container,
248 struct wlr_box *area = &output->sway_output->usable_area; 274 struct wlr_box *area = &output->sway_output->usable_area;
249 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", 275 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
250 area->width, area->height, area->x, area->y); 276 area->width, area->height, area->x, area->y);
251 container->width = area->width; 277 container->width = width = area->width;
252 container->height = area->height; 278 container->height = height = area->height;
253 container->x = x = area->x; 279 container->x = x = area->x;
254 container->y = y = area->y; 280 container->y = y = area->y;
255 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", 281 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f",
@@ -406,7 +432,7 @@ static struct sway_container *get_swayc_in_output_direction(
406 return NULL; 432 return NULL;
407 } 433 }
408 434
409 struct sway_container *ws = sway_seat_get_focus_inactive(seat, output); 435 struct sway_container *ws = seat_get_focus_inactive(seat, output);
410 if (ws->type != C_WORKSPACE) { 436 if (ws->type != C_WORKSPACE) {
411 ws = container_parent(ws, C_WORKSPACE); 437 ws = container_parent(ws, C_WORKSPACE);
412 } 438 }
@@ -427,7 +453,7 @@ static struct sway_container *get_swayc_in_output_direction(
427 case MOVE_UP: 453 case MOVE_UP:
428 case MOVE_DOWN: { 454 case MOVE_DOWN: {
429 struct sway_container *focused = 455 struct sway_container *focused =
430 sway_seat_get_focus_inactive(seat, ws); 456 seat_get_focus_inactive(seat, ws);
431 if (focused && focused->parent) { 457 if (focused && focused->parent) {
432 struct sway_container *parent = focused->parent; 458 struct sway_container *parent = focused->parent;
433 if (parent->layout == L_VERT) { 459 if (parent->layout == L_VERT) {
@@ -511,7 +537,7 @@ static struct sway_container *get_swayc_in_direction_under(
511 struct sway_container *container, enum movement_direction dir, 537 struct sway_container *container, enum movement_direction dir,
512 struct sway_seat *seat, struct sway_container *limit) { 538 struct sway_seat *seat, struct sway_container *limit) {
513 if (dir == MOVE_CHILD) { 539 if (dir == MOVE_CHILD) {
514 return sway_seat_get_focus_inactive(seat, container); 540 return seat_get_focus_inactive(seat, container);
515 } 541 }
516 542
517 struct sway_container *parent = container->parent; 543 struct sway_container *parent = container->parent;
@@ -523,26 +549,6 @@ static struct sway_container *get_swayc_in_direction_under(
523 } 549 }
524 } 550 }
525 551
526 if (dir == MOVE_PREV || dir == MOVE_NEXT) {
527 int focused_idx = index_child(container);
528 if (focused_idx == -1) {
529 return NULL;
530 } else {
531 int desired = (focused_idx + (dir == MOVE_NEXT ? 1 : -1)) %
532 parent->children->length;
533 if (desired < 0) {
534 desired += parent->children->length;
535 }
536 return parent->children->items[desired];
537 }
538 }
539
540 // If moving to an adjacent output we need a starting position (since this
541 // output might border to multiple outputs).
542 //struct wlc_point abs_pos;
543 //get_layout_center_position(container, &abs_pos);
544
545
546 // TODO WLR fullscreen 552 // TODO WLR fullscreen
547 /* 553 /*
548 if (container->type == C_VIEW && swayc_is_fullscreen(container)) { 554 if (container->type == C_VIEW && swayc_is_fullscreen(container)) {
@@ -591,7 +597,7 @@ static struct sway_container *get_swayc_in_direction_under(
591 } 597 }
592 if (next->children && next->children->length) { 598 if (next->children && next->children->length) {
593 // TODO consider floating children as well 599 // TODO consider floating children as well
594 return sway_seat_get_focus_inactive(seat, next); 600 return seat_get_focus_inactive(seat, next);
595 } else { 601 } else {
596 return next; 602 return next;
597 } 603 }