From 5ff0619ca1cab044004df044c253c9170b8316c3 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 20:22:15 -0700 Subject: input state, find_container_in_direction --- sway/focus.c | 74 ++++++------------------------------------------------------ 1 file changed, 7 insertions(+), 67 deletions(-) (limited to 'sway/focus.c') diff --git a/sway/focus.c b/sway/focus.c index f76b2d9a..1dbac003 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -3,6 +3,7 @@ #include "focus.h" #include "log.h" #include "workspace.h" +#include "layout.h" bool locked_container_focus = false; bool locked_view_focus = false; @@ -53,74 +54,13 @@ static void update_focus(swayc_t *c) { } bool move_focus(enum movement_direction direction) { - if (locked_container_focus) { - return false; - } - swayc_t *current = get_focused_container(&root_container); - if (current->type == C_VIEW - && wlc_view_get_state(current->handle) & WLC_BIT_FULLSCREEN) { - return false; - } - swayc_t *parent = current->parent; - - if (direction == MOVE_PARENT) { - if (parent->type == C_OUTPUT) { - sway_log(L_DEBUG, "Focus cannot move to parent"); - return false; - } else { - sway_log(L_DEBUG, "Moving focus from %p:%ld to %p:%ld", - current, current->handle, parent, parent->handle); - set_focused_container(parent); - return true; - } - } - - while (true) { - sway_log(L_DEBUG, "Moving focus away from %p", current); - - // Test if we can even make a difference here - bool can_move = false; - int diff = 0; - if (direction == MOVE_LEFT || direction == MOVE_RIGHT) { - if (parent->layout == L_HORIZ || parent->type == C_ROOT) { - can_move = true; - diff = direction == MOVE_LEFT ? -1 : 1; - } - } else { - if (parent->layout == L_VERT) { - can_move = true; - diff = direction == MOVE_UP ? -1 : 1; - } - } - sway_log(L_DEBUG, "Can move? %s", can_move ? "yes" : "no"); - if (can_move) { - int i; - for (i = 0; i < parent->children->length; ++i) { - swayc_t *child = parent->children->items[i]; - if (child == current) { - break; - } - } - int desired = i + diff; - sway_log(L_DEBUG, "Moving from %d to %d", i, desired); - if (desired < 0 || desired >= parent->children->length) { - can_move = false; - } else { - swayc_t *newview = parent->children->items[desired]; - set_focused_container(get_focused_view(newview)); - return true; - } - } - if (!can_move) { - sway_log(L_DEBUG, "Can't move at current level, moving up tree"); - current = parent; - parent = parent->parent; - if (!parent) { - // Nothing we can do - return false; - } - } + swayc_t *view = get_swayc_in_direction( + get_focused_container(&root_container), direction); + if (view) { + set_focused_container(view); + return true; } + return false; } swayc_t *get_focused_container(swayc_t *parent) { -- cgit v1.2.3 From 66e82a68fc9d3264413a9d7b54813143ada61d20 Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 20:28:05 -0700 Subject: small fix --- sway/focus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/focus.c') diff --git a/sway/focus.c b/sway/focus.c index 1dbac003..48017fdf 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -57,7 +57,7 @@ bool move_focus(enum movement_direction direction) { swayc_t *view = get_swayc_in_direction( get_focused_container(&root_container), direction); if (view) { - set_focused_container(view); + set_focused_container(get_focused_view(view)); return true; } return false; -- cgit v1.2.3 From 686780f12d40c788a29bfe552c892a802e805dca Mon Sep 17 00:00:00 2001 From: taiyu Date: Wed, 19 Aug 2015 20:29:24 -0700 Subject: another small fix to move_focus --- sway/focus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sway/focus.c') diff --git a/sway/focus.c b/sway/focus.c index 48017fdf..a6ffe73f 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -57,7 +57,11 @@ bool move_focus(enum movement_direction direction) { swayc_t *view = get_swayc_in_direction( get_focused_container(&root_container), direction); if (view) { - set_focused_container(get_focused_view(view)); + if (direction == MOVE_PARENT) { + set_focused_container(view); + } else { + set_focused_container(get_focused_view(view)); + } return true; } return false; -- cgit v1.2.3