summaryrefslogtreecommitdiffstats
path: root/sway/focus.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/focus.c')
-rw-r--r--sway/focus.c74
1 files changed, 7 insertions, 67 deletions
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 @@
3#include "focus.h" 3#include "focus.h"
4#include "log.h" 4#include "log.h"
5#include "workspace.h" 5#include "workspace.h"
6#include "layout.h"
6 7
7bool locked_container_focus = false; 8bool locked_container_focus = false;
8bool locked_view_focus = false; 9bool locked_view_focus = false;
@@ -53,74 +54,13 @@ static void update_focus(swayc_t *c) {
53} 54}
54 55
55bool move_focus(enum movement_direction direction) { 56bool move_focus(enum movement_direction direction) {
56 if (locked_container_focus) { 57 swayc_t *view = get_swayc_in_direction(
57 return false; 58 get_focused_container(&root_container), direction);
58 } 59 if (view) {
59 swayc_t *current = get_focused_container(&root_container); 60 set_focused_container(view);
60 if (current->type == C_VIEW 61 return true;
61 && wlc_view_get_state(current->handle) & WLC_BIT_FULLSCREEN) {
62 return false;
63 }
64 swayc_t *parent = current->parent;
65
66 if (direction == MOVE_PARENT) {
67 if (parent->type == C_OUTPUT) {
68 sway_log(L_DEBUG, "Focus cannot move to parent");
69 return false;
70 } else {
71 sway_log(L_DEBUG, "Moving focus from %p:%ld to %p:%ld",
72 current, current->handle, parent, parent->handle);
73 set_focused_container(parent);
74 return true;
75 }
76 }
77
78 while (true) {
79 sway_log(L_DEBUG, "Moving focus away from %p", current);
80
81 // Test if we can even make a difference here
82 bool can_move = false;
83 int diff = 0;
84 if (direction == MOVE_LEFT || direction == MOVE_RIGHT) {
85 if (parent->layout == L_HORIZ || parent->type == C_ROOT) {
86 can_move = true;
87 diff = direction == MOVE_LEFT ? -1 : 1;
88 }
89 } else {
90 if (parent->layout == L_VERT) {
91 can_move = true;
92 diff = direction == MOVE_UP ? -1 : 1;
93 }
94 }
95 sway_log(L_DEBUG, "Can move? %s", can_move ? "yes" : "no");
96 if (can_move) {
97 int i;
98 for (i = 0; i < parent->children->length; ++i) {
99 swayc_t *child = parent->children->items[i];
100 if (child == current) {
101 break;
102 }
103 }
104 int desired = i + diff;
105 sway_log(L_DEBUG, "Moving from %d to %d", i, desired);
106 if (desired < 0 || desired >= parent->children->length) {
107 can_move = false;
108 } else {
109 swayc_t *newview = parent->children->items[desired];
110 set_focused_container(get_focused_view(newview));
111 return true;
112 }
113 }
114 if (!can_move) {
115 sway_log(L_DEBUG, "Can't move at current level, moving up tree");
116 current = parent;
117 parent = parent->parent;
118 if (!parent) {
119 // Nothing we can do
120 return false;
121 }
122 }
123 } 62 }
63 return false;
124} 64}
125 65
126swayc_t *get_focused_container(swayc_t *parent) { 66swayc_t *get_focused_container(swayc_t *parent) {