diff options
Diffstat (limited to 'sway/focus.c')
-rw-r--r-- | sway/focus.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/sway/focus.c b/sway/focus.c index 5008dbbf..a3e5e77a 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -21,8 +21,6 @@ static void update_focus(swayc_t *c) { | |||
21 | // Case where output changes | 21 | // Case where output changes |
22 | case C_OUTPUT: | 22 | case C_OUTPUT: |
23 | wlc_output_focus(c->handle); | 23 | wlc_output_focus(c->handle); |
24 | // Set new workspace to the outputs focused workspace | ||
25 | active_workspace = c->focused; | ||
26 | break; | 24 | break; |
27 | 25 | ||
28 | // Case where workspace changes | 26 | // Case where workspace changes |
@@ -39,7 +37,6 @@ static void update_focus(swayc_t *c) { | |||
39 | c->parent->focused = c; | 37 | c->parent->focused = c; |
40 | destroy_workspace(ws); | 38 | destroy_workspace(ws); |
41 | } | 39 | } |
42 | active_workspace = c; | ||
43 | break; | 40 | break; |
44 | 41 | ||
45 | default: | 42 | default: |
@@ -54,8 +51,8 @@ static void update_focus(swayc_t *c) { | |||
54 | } | 51 | } |
55 | 52 | ||
56 | bool move_focus(enum movement_direction direction) { | 53 | bool move_focus(enum movement_direction direction) { |
57 | swayc_t *view = get_swayc_in_direction( | 54 | swayc_t *view = get_focused_container(&root_container); |
58 | get_focused_container(&root_container), direction); | 55 | view = get_swayc_in_direction(view, direction); |
59 | if (view) { | 56 | if (view) { |
60 | if (direction == MOVE_PARENT) { | 57 | if (direction == MOVE_PARENT) { |
61 | set_focused_container(view); | 58 | set_focused_container(view); |
@@ -68,13 +65,12 @@ bool move_focus(enum movement_direction direction) { | |||
68 | } | 65 | } |
69 | 66 | ||
70 | swayc_t *get_focused_container(swayc_t *parent) { | 67 | swayc_t *get_focused_container(swayc_t *parent) { |
71 | while (parent && !parent->is_focused) { | 68 | if (!parent) { |
72 | parent = parent->focused; | 69 | return swayc_active_workspace(); |
73 | } | 70 | } |
74 | // just incase | 71 | // get focusde container |
75 | if (parent == NULL) { | 72 | while (!parent->is_focused && parent->focused) { |
76 | sway_log(L_DEBUG, "get_focused_container unable to find container"); | 73 | parent = parent->focused; |
77 | return active_workspace; | ||
78 | } | 74 | } |
79 | return parent; | 75 | return parent; |
80 | } | 76 | } |
@@ -85,9 +81,13 @@ void set_focused_container(swayc_t *c) { | |||
85 | } | 81 | } |
86 | sway_log(L_DEBUG, "Setting focus to %p:%ld", c, c->handle); | 82 | sway_log(L_DEBUG, "Setting focus to %p:%ld", c, c->handle); |
87 | 83 | ||
88 | // Find previous focused view, and the new focused view, if they are the same return | 84 | // Get workspace for c, get that workspaces current focused container. |
89 | swayc_t *focused = get_focused_view(&root_container); | 85 | swayc_t *workspace = swayc_active_workspace_for(c); |
90 | swayc_t *workspace = active_workspace; | 86 | swayc_t *focused = get_focused_view(workspace); |
87 | // if the workspace we are changing focus to has a fullscreen view return | ||
88 | if (swayc_is_fullscreen(focused) && focused != c) { | ||
89 | return; | ||
90 | } | ||
91 | 91 | ||
92 | // update container focus from here to root, making necessary changes along | 92 | // update container focus from here to root, making necessary changes along |
93 | // the way | 93 | // the way |
@@ -101,13 +101,6 @@ void set_focused_container(swayc_t *c) { | |||
101 | p->is_focused = false; | 101 | p->is_focused = false; |
102 | } | 102 | } |
103 | 103 | ||
104 | // if the workspace is the same, and previous focus is fullscreen, dont | ||
105 | // change focus | ||
106 | if (workspace == active_workspace | ||
107 | && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) { | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | // get new focused view and set focus to it. | 104 | // get new focused view and set focus to it. |
112 | p = get_focused_view(c); | 105 | p = get_focused_view(c); |
113 | if (p->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { | 106 | if (p->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { |
@@ -137,6 +130,15 @@ void set_focused_container_for(swayc_t *a, swayc_t *c) { | |||
137 | return; | 130 | return; |
138 | } | 131 | } |
139 | } | 132 | } |
133 | |||
134 | // Get workspace for c, get that workspaces current focused container. | ||
135 | swayc_t *workspace = swayc_active_workspace_for(c); | ||
136 | swayc_t *focused = get_focused_view(workspace); | ||
137 | // if the workspace we are changing focus to has a fullscreen view return | ||
138 | if (swayc_is_fullscreen(focused) && c != focused) { | ||
139 | return; | ||
140 | } | ||
141 | |||
140 | // Check if we changing a parent container that will see chnage | 142 | // Check if we changing a parent container that will see chnage |
141 | bool effective = true; | 143 | bool effective = true; |
142 | while (find != &root_container) { | 144 | while (find != &root_container) { |
@@ -171,7 +173,7 @@ swayc_t *get_focused_view(swayc_t *parent) { | |||
171 | parent = parent->focused; | 173 | parent = parent->focused; |
172 | } | 174 | } |
173 | if (parent == NULL) { | 175 | if (parent == NULL) { |
174 | return active_workspace; | 176 | return swayc_active_workspace_for(parent); |
175 | } | 177 | } |
176 | return parent; | 178 | return parent; |
177 | } | 179 | } |