aboutsummaryrefslogtreecommitdiff
path: root/sway/focus.c
diff options
context:
space:
mode:
authorHalf-Shot <half-shot@molrams.com>2015-08-20 21:32:08 +0100
committerHalf-Shot <half-shot@molrams.com>2015-08-20 21:32:08 +0100
commit5a9ba261bca4ca709ec7a14d2019b55d9ce06994 (patch)
treefe1a924cf8055b2b722566db6ab98295dcf08ce7 /sway/focus.c
parent2a62c5c7fb71fc815663281793ba6a89d2b246ed (diff)
parent1100335ea01ecd56df68568622580db14e72b6c7 (diff)
Merge branch 'master' of https://github.com/SirCmpwn/sway
Diffstat (limited to 'sway/focus.c')
-rw-r--r--sway/focus.c87
1 files changed, 18 insertions, 69 deletions
diff --git a/sway/focus.c b/sway/focus.c
index 628316dd..5008dbbf 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;
@@ -20,6 +21,8 @@ static void update_focus(swayc_t *c) {
// Case where output changes
case C_OUTPUT:
wlc_output_focus(c->handle);
+ // Set new workspace to the outputs focused workspace
+ active_workspace = c->focused;
break;
// Case where workspace changes
@@ -51,74 +54,17 @@ 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;
+ swayc_t *view = get_swayc_in_direction(
+ get_focused_container(&root_container), direction);
+ if (view) {
+ if (direction == MOVE_PARENT) {
+ set_focused_container(view);
} 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;
- }
+ set_focused_container(get_focused_view(view));
}
+ return true;
}
+ return false;
}
swayc_t *get_focused_container(swayc_t *parent) {
@@ -142,13 +88,13 @@ void set_focused_container(swayc_t *c) {
// Find previous focused view, and the new focused view, if they are the same return
swayc_t *focused = get_focused_view(&root_container);
swayc_t *workspace = active_workspace;
- if (focused == get_focused_view(c)) {
- return;
- }
// update container focus from here to root, making necessary changes along
// the way
swayc_t *p = c;
+ if (p->type != C_OUTPUT && p->type != C_ROOT) {
+ p->is_focused = true;
+ }
while (p != &root_container) {
update_focus(p);
p = p->parent;
@@ -171,8 +117,11 @@ void set_focused_container(swayc_t *c) {
}
// activate current focus
if (p->type == C_VIEW) {
- wlc_view_focus(p->handle);
wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true);
+ // set focus if view_focus is unlocked
+ if (!locked_view_focus) {
+ wlc_view_focus(p->handle);
+ }
}
}
}