aboutsummaryrefslogtreecommitdiff
path: root/sway/layout.c
diff options
context:
space:
mode:
authorMikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-28 18:20:18 +0100
committerMikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-28 18:20:18 +0100
commit6088c6cdf0a72a430a22a6c7ac4e75c14e98a949 (patch)
treebfa2fd2360f72ae4e4d036e58821fbe49e5c3eb3 /sway/layout.c
parent3453910c3e887be900c69394b738e34d9d8ba095 (diff)
Correctly move focus from one output to a new one.
This patch aims to correctly handle moving focus <left|right|up|down> between outputs. For instance, if moving from one output to a new output at the left of the current one, it should focus the right-most view/container on the new output, and the opposite if moving from right to left. This should happen regardless of the previously stored focus of the new output. This also handles moving to a new output above or below the current one.
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/sway/layout.c b/sway/layout.c
index d5fdbf0b..dca4e47f 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -617,6 +617,50 @@ void arrange_windows(swayc_t *container, double width, double height) {
layout_log(&root_container, 0);
}
+/**
+ * Get swayc in the direction of newly entered output.
+ */
+static swayc_t *get_swayc_in_output_direction(swayc_t *output, enum movement_direction dir) {
+ if (!output) {
+ return NULL;
+ }
+
+ swayc_t *ws = swayc_focus_by_type(output, C_WORKSPACE);
+ if (ws && ws->children->length > 0) {
+ switch (dir) {
+ case MOVE_LEFT:
+ // get most right child of new output
+ return ws->children->items[ws->children->length-1];
+ case MOVE_RIGHT:
+ // get most left child of new output
+ return ws->children->items[0];
+ case MOVE_UP:
+ case MOVE_DOWN:
+ {
+ swayc_t *focused_view = swayc_focus_by_type(ws, C_VIEW);
+ if (focused_view && focused_view->parent) {
+ swayc_t *parent = focused_view->parent;
+ if (parent->layout == L_VERT) {
+ if (dir == MOVE_UP) {
+ // get child furthest down on new output
+ return parent->children->items[parent->children->length-1];
+ } else if (dir == MOVE_DOWN) {
+ // get child furthest up on new output
+ return parent->children->items[0];
+ }
+ }
+ return focused_view;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ return output;
+}
+
swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_direction dir, swayc_t *limit) {
swayc_t *parent = container->parent;
if (dir == MOVE_PARENT) {
@@ -635,7 +679,8 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
sway_log(L_DEBUG, "Moving from fullscreen view, skipping to output");
container = swayc_parent_by_type(container, C_OUTPUT);
get_absolute_center_position(container, &abs_pos);
- return swayc_adjacent_output(container, dir, &abs_pos, true);
+ swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true);
+ return get_swayc_in_output_direction(output, dir);
}
if (container->type == C_WORKSPACE && container->fullscreen) {
@@ -649,7 +694,8 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
int diff = 0;
if (parent->type == C_ROOT) {
sway_log(L_DEBUG, "Moving between outputs");
- return swayc_adjacent_output(container, dir, &abs_pos, true);
+ swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true);
+ return get_swayc_in_output_direction(output, dir);
} else {
if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
if (parent->layout == L_HORIZ) {