aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/focus.h1
-rw-r--r--sway/container.c2
-rw-r--r--sway/focus.c25
-rw-r--r--sway/handlers.c9
-rw-r--r--sway/layout.c4
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 {
swayc_t *get_focused_container(swayc_t *parent);
swayc_t *get_focused_view(swayc_t *parent);
+swayc_t *get_focused_float(swayc_t *ws);
void set_focused_container(swayc_t *container);
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) {
/* Fallthrough */
case C_OUTPUT:
- cont = cont->focused;
+ cont = cont ? cont->focused : NULL;
/* Fallthrough */
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) {
}
swayc_t *get_focused_view(swayc_t *parent) {
- while (parent && parent->type != C_VIEW) {
- if (parent->type == C_WORKSPACE && parent->focused == NULL) {
- return parent;
+ swayc_t *c = parent;
+ while (c && c->type != C_VIEW) {
+ if (c->type == C_WORKSPACE && c->focused == NULL) {
+ return c;
}
- parent = parent->focused;
+ c = c->focused;
}
- if (parent == NULL) {
- return swayc_active_workspace_for(parent);
+ if (c == NULL) {
+ c = swayc_active_workspace_for(parent);
}
- return parent;
+ return c;
+}
+
+swayc_t *get_focused_float(swayc_t *ws) {
+ if(!sway_assert(ws->type == C_WORKSPACE, "must be of workspace type")) {
+ ws = swayc_active_workspace();
+ }
+ if (ws->floating->length) {
+ return ws->floating->items[ws->floating->length - 1];
+ }
+ return NULL;
}
diff --git a/sway/handlers.c b/sway/handlers.c
index 4d1dc56c..758af8d6 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -231,14 +231,7 @@ static void handle_view_destroyed(wlc_handle handle) {
break;
}
- swayc_t *focused_view = get_focused_view(&root_container);
- if (focused_view->type == C_WORKSPACE && focused_view->children->length == 0) {
- if (focused_view->floating->length > 0) {
- focused_view = focused_view->floating->items[focused_view->floating->length-1];
- focused_view = get_focused_view(focused_view);
- }
- }
- set_focused_container(focused_view);
+ set_focused_container(get_focused_view(&root_container));
}
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) {
// Set focused to new container
if (parent->focused == child) {
if (parent->children->length > 0) {
- parent->focused = parent->children->items[i?i-1:0];
+ parent->focused = parent->children->items[i ? i-1:0];
+ } else if (parent->floating && parent->floating->length) {
+ parent->focused = parent->floating->items[parent->floating->length - 1];
} else {
parent->focused = NULL;
}