diff options
-rw-r--r-- | include/focus.h | 1 | ||||
-rw-r--r-- | sway/container.c | 2 | ||||
-rw-r--r-- | sway/focus.c | 25 | ||||
-rw-r--r-- | sway/handlers.c | 9 | ||||
-rw-r--r-- | sway/layout.c | 4 |
5 files changed, 24 insertions, 17 deletions
diff --git a/include/focus.h b/include/focus.h index 383993fa..1ab63a6c 100644 --- a/include/focus.h +++ b/include/focus.h | |||
@@ -19,6 +19,7 @@ enum movement_direction { | |||
19 | 19 | ||
20 | swayc_t *get_focused_container(swayc_t *parent); | 20 | swayc_t *get_focused_container(swayc_t *parent); |
21 | swayc_t *get_focused_view(swayc_t *parent); | 21 | swayc_t *get_focused_view(swayc_t *parent); |
22 | swayc_t *get_focused_float(swayc_t *ws); | ||
22 | 23 | ||
23 | void set_focused_container(swayc_t *container); | 24 | void set_focused_container(swayc_t *container); |
24 | void set_focused_container_for(swayc_t *ancestor, swayc_t *container); | 25 | void set_focused_container_for(swayc_t *ancestor, swayc_t *container); |
diff --git a/sway/container.c b/sway/container.c index 6fbfa360..cd7c9b13 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -477,7 +477,7 @@ swayc_t *swayc_active_workspace_for(swayc_t *cont) { | |||
477 | /* Fallthrough */ | 477 | /* Fallthrough */ |
478 | 478 | ||
479 | case C_OUTPUT: | 479 | case C_OUTPUT: |
480 | cont = cont->focused; | 480 | cont = cont ? cont->focused : NULL; |
481 | /* Fallthrough */ | 481 | /* Fallthrough */ |
482 | 482 | ||
483 | case C_WORKSPACE: | 483 | case C_WORKSPACE: |
diff --git a/sway/focus.c b/sway/focus.c index 1086f1a8..f7b55b27 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -164,14 +164,25 @@ void set_focused_container_for(swayc_t *a, swayc_t *c) { | |||
164 | } | 164 | } |
165 | 165 | ||
166 | swayc_t *get_focused_view(swayc_t *parent) { | 166 | swayc_t *get_focused_view(swayc_t *parent) { |
167 | while (parent && parent->type != C_VIEW) { | 167 | swayc_t *c = parent; |
168 | if (parent->type == C_WORKSPACE && parent->focused == NULL) { | 168 | while (c && c->type != C_VIEW) { |
169 | return parent; | 169 | if (c->type == C_WORKSPACE && c->focused == NULL) { |
170 | return c; | ||
170 | } | 171 | } |
171 | parent = parent->focused; | 172 | c = c->focused; |
172 | } | 173 | } |
173 | if (parent == NULL) { | 174 | if (c == NULL) { |
174 | return swayc_active_workspace_for(parent); | 175 | c = swayc_active_workspace_for(parent); |
175 | } | 176 | } |
176 | return parent; | 177 | return c; |
178 | } | ||
179 | |||
180 | swayc_t *get_focused_float(swayc_t *ws) { | ||
181 | if(!sway_assert(ws->type == C_WORKSPACE, "must be of workspace type")) { | ||
182 | ws = swayc_active_workspace(); | ||
183 | } | ||
184 | if (ws->floating->length) { | ||
185 | return ws->floating->items[ws->floating->length - 1]; | ||
186 | } | ||
187 | return NULL; | ||
177 | } | 188 | } |
diff --git a/sway/handlers.c b/sway/handlers.c index 5624124f..330f6c0c 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -231,14 +231,7 @@ static void handle_view_destroyed(wlc_handle handle) { | |||
231 | break; | 231 | break; |
232 | } | 232 | } |
233 | 233 | ||
234 | swayc_t *focused_view = get_focused_view(&root_container); | 234 | set_focused_container(get_focused_view(&root_container)); |
235 | if (focused_view->type == C_WORKSPACE && focused_view->children->length == 0) { | ||
236 | if (focused_view->floating->length > 0) { | ||
237 | focused_view = focused_view->floating->items[focused_view->floating->length-1]; | ||
238 | focused_view = get_focused_view(focused_view); | ||
239 | } | ||
240 | } | ||
241 | set_focused_container(focused_view); | ||
242 | } | 235 | } |
243 | 236 | ||
244 | static void handle_view_focus(wlc_handle view, bool focus) { | 237 | static void handle_view_focus(wlc_handle view, bool focus) { |
diff --git a/sway/layout.c b/sway/layout.c index cd47037b..ed9479ab 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -151,7 +151,9 @@ swayc_t *remove_child(swayc_t *child) { | |||
151 | // Set focused to new container | 151 | // Set focused to new container |
152 | if (parent->focused == child) { | 152 | if (parent->focused == child) { |
153 | if (parent->children->length > 0) { | 153 | if (parent->children->length > 0) { |
154 | parent->focused = parent->children->items[i?i-1:0]; | 154 | parent->focused = parent->children->items[i ? i-1:0]; |
155 | } else if (parent->floating && parent->floating->length) { | ||
156 | parent->focused = parent->floating->items[parent->floating->length - 1]; | ||
155 | } else { | 157 | } else { |
156 | parent->focused = NULL; | 158 | parent->focused = NULL; |
157 | } | 159 | } |