aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r--sway/tree/layout.c73
1 files changed, 48 insertions, 25 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index fb34573f..53ff9ffa 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -16,14 +16,16 @@
16 16
17struct sway_container root_container; 17struct sway_container root_container;
18 18
19static void output_layout_change_notify(struct wl_listener *listener, void *data) { 19static void output_layout_change_notify(struct wl_listener *listener,
20 void *data) {
20 struct wlr_box *layout_box = wlr_output_layout_get_box( 21 struct wlr_box *layout_box = wlr_output_layout_get_box(
21 root_container.sway_root->output_layout, NULL); 22 root_container.sway_root->output_layout, NULL);
22 root_container.width = layout_box->width; 23 root_container.width = layout_box->width;
23 root_container.height = layout_box->height; 24 root_container.height = layout_box->height;
24 25
25 for (int i = 0 ; i < root_container.children->length; ++i) { 26 for (int i = 0 ; i < root_container.children->length; ++i) {
26 struct sway_container *output_container = root_container.children->items[i]; 27 struct sway_container *output_container =
28 root_container.children->items[i];
27 if (output_container->type != C_OUTPUT) { 29 if (output_container->type != C_OUTPUT) {
28 continue; 30 continue;
29 } 31 }
@@ -79,7 +81,8 @@ static int index_child(const struct sway_container *child) {
79 return i; 81 return i;
80} 82}
81 83
82struct sway_container *container_add_sibling(struct sway_container *fixed, struct sway_container *active) { 84struct sway_container *container_add_sibling(struct sway_container *fixed,
85 struct sway_container *active) {
83 // TODO handle floating 86 // TODO handle floating
84 struct sway_container *parent = fixed->parent; 87 struct sway_container *parent = fixed->parent;
85 int i = index_child(fixed); 88 int i = index_child(fixed);
@@ -88,7 +91,8 @@ struct sway_container *container_add_sibling(struct sway_container *fixed, struc
88 return active->parent; 91 return active->parent;
89} 92}
90 93
91void container_add_child(struct sway_container *parent, struct sway_container *child) { 94void container_add_child(struct sway_container *parent,
95 struct sway_container *child) {
92 wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", 96 wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)",
93 child, child->type, child->width, child->height, 97 child, child->type, child->width, child->height,
94 parent, parent->type, parent->width, parent->height); 98 parent, parent->type, parent->width, parent->height);
@@ -96,7 +100,9 @@ void container_add_child(struct sway_container *parent, struct sway_container *c
96 child->parent = parent; 100 child->parent = parent;
97 // set focus for this container 101 // set focus for this container
98 /* TODO WLR 102 /* TODO WLR
99 if (parent->type == C_WORKSPACE && child->type == C_VIEW && (parent->workspace_layout == L_TABBED || parent->workspace_layout == L_STACKED)) { 103 if (parent->type == C_WORKSPACE && child->type == C_VIEW &&
104 (parent->workspace_layout == L_TABBED || parent->workspace_layout ==
105 L_STACKED)) {
100 child = new_container(child, parent->workspace_layout); 106 child = new_container(child, parent->workspace_layout);
101 } 107 }
102 */ 108 */
@@ -115,7 +121,8 @@ struct sway_container *container_remove_child(struct sway_container *child) {
115 return parent; 121 return parent;
116} 122}
117 123
118enum sway_container_layout container_get_default_layout(struct sway_container *output) { 124enum sway_container_layout container_get_default_layout(
125 struct sway_container *output) {
119 /* TODO WLR 126 /* TODO WLR
120 if (config->default_layout != L_NONE) { 127 if (config->default_layout != L_NONE) {
121 //return config->default_layout; 128 //return config->default_layout;
@@ -160,7 +167,8 @@ static void apply_vert_layout(struct sway_container *container, const double x,
160 const double height, const int start, 167 const double height, const int start,
161 const int end); 168 const int end);
162 169
163void container_arrange_windows(struct sway_container *container, double width, double height) { 170void container_arrange_windows(struct sway_container *container,
171 double width, double height) {
164 int i; 172 int i;
165 if (width == -1 || height == -1) { 173 if (width == -1 || height == -1) {
166 width = container->width; 174 width = container->width;
@@ -203,7 +211,8 @@ void container_arrange_windows(struct sway_container *container, double width, d
203 return; 211 return;
204 case C_WORKSPACE: 212 case C_WORKSPACE:
205 { 213 {
206 struct sway_container *output = container_parent(container, C_OUTPUT); 214 struct sway_container *output =
215 container_parent(container, C_OUTPUT);
207 struct wlr_box *area = &output->sway_output->usable_area; 216 struct wlr_box *area = &output->sway_output->usable_area;
208 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", 217 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
209 area->width, area->height, area->x, area->y); 218 area->width, area->height, area->x, area->y);
@@ -259,7 +268,8 @@ static void apply_horiz_layout(struct sway_container *container,
259 double scale = 0; 268 double scale = 0;
260 // Calculate total width 269 // Calculate total width
261 for (int i = start; i < end; ++i) { 270 for (int i = start; i < end; ++i) {
262 double *old_width = &((struct sway_container *)container->children->items[i])->width; 271 double *old_width =
272 &((struct sway_container *)container->children->items[i])->width;
263 if (*old_width <= 0) { 273 if (*old_width <= 0) {
264 if (end - start > 1) { 274 if (end - start > 1) {
265 *old_width = width / (end - start - 1); 275 *old_width = width / (end - start - 1);
@@ -309,7 +319,8 @@ void apply_vert_layout(struct sway_container *container,
309 double scale = 0; 319 double scale = 0;
310 // Calculate total height 320 // Calculate total height
311 for (i = start; i < end; ++i) { 321 for (i = start; i < end; ++i) {
312 double *old_height = &((struct sway_container *)container->children->items[i])->height; 322 double *old_height =
323 &((struct sway_container *)container->children->items[i])->height;
313 if (*old_height <= 0) { 324 if (*old_height <= 0) {
314 if (end - start > 1) { 325 if (end - start > 1) {
315 *old_height = height / (end - start - 1); 326 *old_height = height / (end - start - 1);
@@ -354,8 +365,9 @@ void apply_vert_layout(struct sway_container *container,
354/** 365/**
355 * Get swayc in the direction of newly entered output. 366 * Get swayc in the direction of newly entered output.
356 */ 367 */
357static struct sway_container *get_swayc_in_output_direction(struct sway_container *output, 368static struct sway_container *get_swayc_in_output_direction(
358 enum movement_direction dir, struct sway_seat *seat) { 369 struct sway_container *output, enum movement_direction dir,
370 struct sway_seat *seat) {
359 if (!output) { 371 if (!output) {
360 return NULL; 372 return NULL;
361 } 373 }
@@ -380,13 +392,15 @@ static struct sway_container *get_swayc_in_output_direction(struct sway_containe
380 return ws->children->items[0]; 392 return ws->children->items[0];
381 case MOVE_UP: 393 case MOVE_UP:
382 case MOVE_DOWN: { 394 case MOVE_DOWN: {
383 struct sway_container *focused = sway_seat_get_focus_inactive(seat, ws); 395 struct sway_container *focused =
396 sway_seat_get_focus_inactive(seat, ws);
384 if (focused && focused->parent) { 397 if (focused && focused->parent) {
385 struct sway_container *parent = focused->parent; 398 struct sway_container *parent = focused->parent;
386 if (parent->layout == L_VERT) { 399 if (parent->layout == L_VERT) {
387 if (dir == MOVE_UP) { 400 if (dir == MOVE_UP) {
388 // get child furthest down on new output 401 // get child furthest down on new output
389 return parent->children->items[parent->children->length-1]; 402 int idx = parent->children->length - 1;
403 return parent->children->items[idx];
390 } else if (dir == MOVE_DOWN) { 404 } else if (dir == MOVE_DOWN) {
391 // get child furthest up on new output 405 // get child furthest up on new output
392 return parent->children->items[0]; 406 return parent->children->items[0];
@@ -404,7 +418,8 @@ static struct sway_container *get_swayc_in_output_direction(struct sway_containe
404 return ws; 418 return ws;
405} 419}
406 420
407static void get_layout_center_position(struct sway_container *container, int *x, int *y) { 421static void get_layout_center_position(struct sway_container *container,
422 int *x, int *y) {
408 // FIXME view coords are inconsistently referred to in layout/output systems 423 // FIXME view coords are inconsistently referred to in layout/output systems
409 if (container->type == C_OUTPUT) { 424 if (container->type == C_OUTPUT) {
410 *x = container->x + container->width/2; 425 *x = container->x + container->width/2;
@@ -423,7 +438,8 @@ static void get_layout_center_position(struct sway_container *container, int *x,
423 } 438 }
424} 439}
425 440
426static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) { 441static bool sway_dir_to_wlr(enum movement_direction dir,
442 enum wlr_direction *out) {
427 switch (dir) { 443 switch (dir) {
428 case MOVE_UP: 444 case MOVE_UP:
429 *out = WLR_DIRECTION_UP; 445 *out = WLR_DIRECTION_UP;
@@ -457,8 +473,9 @@ static struct sway_container *sway_output_from_wlr(struct wlr_output *output) {
457 return NULL; 473 return NULL;
458} 474}
459 475
460static struct sway_container *get_swayc_in_direction_under(struct sway_container *container, 476static struct sway_container *get_swayc_in_direction_under(
461 enum movement_direction dir, struct sway_seat *seat, struct sway_container *limit) { 477 struct sway_container *container, enum movement_direction dir,
478 struct sway_seat *seat, struct sway_container *limit) {
462 if (dir == MOVE_CHILD) { 479 if (dir == MOVE_CHILD) {
463 return sway_seat_get_focus_inactive(seat, container); 480 return sway_seat_get_focus_inactive(seat, container);
464 } 481 }
@@ -498,7 +515,8 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container
498 wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); 515 wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output");
499 container = container_parent(container, C_OUTPUT); 516 container = container_parent(container, C_OUTPUT);
500 get_layout_center_position(container, &abs_pos); 517 get_layout_center_position(container, &abs_pos);
501 struct sway_container *output = swayc_adjacent_output(container, dir, &abs_pos, true); 518 struct sway_container *output =
519 swayc_adjacent_output(container, dir, &abs_pos, true);
502 return get_swayc_in_output_direction(output, dir); 520 return get_swayc_in_output_direction(output, dir);
503 } 521 }
504 if (container->type == C_WORKSPACE && container->fullscreen) { 522 if (container->type == C_WORKSPACE && container->fullscreen) {
@@ -521,16 +539,19 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container
521 } 539 }
522 int lx, ly; 540 int lx, ly;
523 get_layout_center_position(container, &lx, &ly); 541 get_layout_center_position(container, &lx, &ly);
524 struct wlr_output_layout *layout = root_container.sway_root->output_layout; 542 struct wlr_output_layout *layout =
543 root_container.sway_root->output_layout;
525 struct wlr_output *wlr_adjacent = 544 struct wlr_output *wlr_adjacent =
526 wlr_output_layout_adjacent_output(layout, wlr_dir, 545 wlr_output_layout_adjacent_output(layout, wlr_dir,
527 container->sway_output->wlr_output, lx, ly); 546 container->sway_output->wlr_output, lx, ly);
528 struct sway_container *adjacent = sway_output_from_wlr(wlr_adjacent); 547 struct sway_container *adjacent =
548 sway_output_from_wlr(wlr_adjacent);
529 549
530 if (!adjacent || adjacent == container) { 550 if (!adjacent || adjacent == container) {
531 return wrap_candidate; 551 return wrap_candidate;
532 } 552 }
533 struct sway_container *next = get_swayc_in_output_direction(adjacent, dir, seat); 553 struct sway_container *next =
554 get_swayc_in_output_direction(adjacent, dir, seat);
534 if (next == NULL) { 555 if (next == NULL) {
535 return NULL; 556 return NULL;
536 } 557 }
@@ -570,8 +591,9 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container
570 } 591 }
571 } 592 }
572 } else { 593 } else {
573 wlr_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__, 594 wlr_log(L_DEBUG,
574 idx, container, dir, desired, parent->children->items[desired]); 595 "%s cont %d-%p dir %i sibling %d: %p", __func__, idx,
596 container, dir, desired, parent->children->items[desired]);
575 return parent->children->items[desired]; 597 return parent->children->items[desired];
576 } 598 }
577 } 599 }
@@ -587,7 +609,8 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container
587 } 609 }
588} 610}
589 611
590struct sway_container *container_get_in_direction(struct sway_container *container, struct sway_seat *seat, 612struct sway_container *container_get_in_direction(
613 struct sway_container *container, struct sway_seat *seat,
591 enum movement_direction dir) { 614 enum movement_direction dir) {
592 return get_swayc_in_direction_under(container, dir, seat, NULL); 615 return get_swayc_in_direction_under(container, dir, seat, NULL);
593} 616}