Skip to content

Commit b06e645

Browse files
committed
fix: master stack focus corrections
1 parent e88c6cb commit b06e645

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

src/master_stack.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,21 @@ static struct wlr_box node_layout_box(const node_t *node) {
532532
return node->rectangle;
533533
}
534534

535+
static bool aligned_with(const struct wlr_box *source, const struct wlr_box *candidate,
536+
master_stack_direction_t direction) {
537+
if (direction == DIRECTION_NORTH || direction == DIRECTION_SOUTH)
538+
return source->x < candidate->x + candidate->width && candidate->x < source->x + source->width;
539+
return source->y < candidate->y + candidate->height && candidate->y < source->y + source->height;
540+
}
541+
535542
static int directional_target(node_t **nodes, int count, int source_index,
536543
master_stack_direction_t direction, bool wrap) {
537544
struct wlr_box source = node_layout_box(nodes[source_index]);
538545
int64_t source_x = (int64_t)source.x * 2 + source.width;
539546
int64_t source_y = (int64_t)source.y * 2 + source.height;
547+
int aligned_target = -1;
548+
int64_t aligned_primary = INT64_MAX;
549+
int64_t aligned_secondary = INT64_MAX;
540550
int target = -1;
541551
int64_t best_primary = INT64_MAX;
542552
int64_t best_secondary = INT64_MAX;
@@ -576,14 +586,27 @@ static int directional_target(node_t **nodes, int count, int source_index,
576586
break;
577587
}
578588

579-
if (eligible && (primary < best_primary || (primary == best_primary &&
580-
secondary < best_secondary))) {
589+
if (!eligible)
590+
continue;
591+
592+
if (primary < best_primary || (primary == best_primary && secondary < best_secondary)) {
581593
target = i;
582594
best_primary = primary;
583595
best_secondary = secondary;
584596
}
597+
598+
if (!aligned_with(&source, &candidate, direction))
599+
continue;
600+
if (primary < aligned_primary || (primary == aligned_primary && secondary < aligned_secondary)) {
601+
aligned_target = i;
602+
aligned_primary = primary;
603+
aligned_secondary = secondary;
604+
}
585605
}
586606

607+
if (aligned_target >= 0)
608+
target = aligned_target;
609+
587610
if (target >= 0 || !wrap)
588611
return target;
589612

@@ -624,8 +647,11 @@ static bool focus_in_direction(desktop_t *d, master_stack_direction_t direction)
624647
return false;
625648

626649
int target = directional_target(nodes, count, index, direction, focus_wrapping);
627-
if (target >= 0)
650+
if (target >= 0) {
628651
d->focus = nodes[target];
652+
if (d->output)
653+
focus_node(d->output, d, d->focus);
654+
}
629655
free(nodes);
630656
return target >= 0;
631657
}

0 commit comments

Comments
 (0)