aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/layout.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-17 18:33:02 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-17 18:33:02 -0500
commitfb37e802252b35fd63c68df6b19549b715474821 (patch)
tree2d8c0d7caf8fec23593500ff56b05abcda363b90 /sway/tree/layout.c
parentfix output rendering issue (diff)
downloadsway-fb37e802252b35fd63c68df6b19549b715474821.tar.gz
sway-fb37e802252b35fd63c68df6b19549b715474821.tar.zst
sway-fb37e802252b35fd63c68df6b19549b715474821.zip
basic move focus in direction across outputs
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r--sway/tree/layout.c86
1 files changed, 73 insertions, 13 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 5e8f4c56..6a574303 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -398,9 +398,58 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output,
398 return output; 398 return output;
399} 399}
400 400
401static void get_absolute_center_position(swayc_t *container, int *x, int *y) { 401static void get_layout_center_position(swayc_t *container, int *x, int *y) {
402 *x = container->x + container->width/2; 402 // FIXME view coords are inconsistently referred to in layout/output systems
403 *y = container->y + container->height/2; 403 if (container->type == C_OUTPUT) {
404 *x = container->x + container->width/2;
405 *y = container->y + container->height/2;
406 } else {
407 swayc_t *output = swayc_parent_by_type(container, C_OUTPUT);
408 if (container->type == C_WORKSPACE) {
409 // Workspace coordinates are actually wrong/arbitrary, but should
410 // be same as output.
411 *x = output->x;
412 *y = output->y;
413 } else {
414 *x = output->x + container->x;
415 *y = output->y + container->y;
416 }
417 }
418}
419
420static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) {
421 *out = 0;
422 switch (dir) {
423 case MOVE_UP:
424 *out = WLR_DIRECTION_UP;
425 break;
426 case MOVE_DOWN:
427 *out = WLR_DIRECTION_DOWN;
428 break;
429 case MOVE_LEFT:
430 *out = WLR_DIRECTION_LEFT;
431 break;
432 case MOVE_RIGHT:
433 *out = WLR_DIRECTION_RIGHT;
434 break;
435 default:
436 break;
437 }
438
439 return *out != 0;
440}
441
442static swayc_t *sway_output_from_wlr(struct wlr_output *output) {
443 if (output == NULL) {
444 return NULL;
445 }
446 for (int i = 0; i < root_container.children->length; ++i) {
447 swayc_t *o = root_container.children->items[i];
448 if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) {
449 return o;
450 }
451 }
452 return NULL;
404} 453}
405 454
406static swayc_t *get_swayc_in_direction_under(swayc_t *container, 455static swayc_t *get_swayc_in_direction_under(swayc_t *container,
@@ -435,7 +484,7 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
435 // If moving to an adjacent output we need a starting position (since this 484 // If moving to an adjacent output we need a starting position (since this
436 // output might border to multiple outputs). 485 // output might border to multiple outputs).
437 //struct wlc_point abs_pos; 486 //struct wlc_point abs_pos;
438 //get_absolute_center_position(container, &abs_pos); 487 //get_layout_center_position(container, &abs_pos);
439 488
440 489
441 // TODO WLR fullscreen 490 // TODO WLR fullscreen
@@ -443,7 +492,7 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
443 if (container->type == C_VIEW && swayc_is_fullscreen(container)) { 492 if (container->type == C_VIEW && swayc_is_fullscreen(container)) {
444 wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); 493 wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output");
445 container = swayc_parent_by_type(container, C_OUTPUT); 494 container = swayc_parent_by_type(container, C_OUTPUT);
446 get_absolute_center_position(container, &abs_pos); 495 get_layout_center_position(container, &abs_pos);
447 swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true); 496 swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true);
448 return get_swayc_in_output_direction(output, dir); 497 return get_swayc_in_output_direction(output, dir);
449 } 498 }
@@ -460,17 +509,28 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
460 int desired; 509 int desired;
461 int idx = index_child(container); 510 int idx = index_child(container);
462 if (parent->type == C_ROOT) { 511 if (parent->type == C_ROOT) {
463 // TODO 512 enum wlr_direction wlr_dir = 0;
464 /* 513 if (!sway_assert(sway_dir_to_wlr(dir, &wlr_dir),
514 "got invalid direction: %d", dir)) {
515 return NULL;
516 }
517 int lx, ly;
518 get_layout_center_position(container, &lx, &ly);
465 struct wlr_output_layout *layout = root_container.sway_root->output_layout; 519 struct wlr_output_layout *layout = root_container.sway_root->output_layout;
466 wlr_output_layout_adjacent_output(layout, container->sway_output->wlr_output); 520 struct wlr_output *wlr_adjacent =
467 //swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true); 521 wlr_output_layout_adjacent_output(layout, wlr_dir,
468 if (!output || output == container) { 522 container->sway_output->wlr_output, lx, ly);
523 swayc_t *adjacent = sway_output_from_wlr(wlr_adjacent);
524
525 if (!adjacent || adjacent == container) {
469 return wrap_candidate; 526 return wrap_candidate;
470 } 527 }
471 wlr_log(L_DEBUG, "Moving between outputs"); 528 // TODO descend into the focus-inactive of the physically closest
472 return get_swayc_in_output_direction(output, dir, seat); 529 // view of the output
473 */ 530 //swayc_t *new_con = get_swayc_in_output_direction(adjacent, dir, seat);
531 swayc_t *new_con = sway_seat_get_focus_inactive(seat, adjacent);
532 return new_con;
533
474 } else { 534 } else {
475 if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { 535 if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
476 if (parent->layout == L_HORIZ || parent->layout == L_TABBED) { 536 if (parent->layout == L_HORIZ || parent->layout == L_TABBED) {