sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit 77dcf70a9b9037f7582718c37b4dff04324d8c7a
parent 0bf380a0b1a83f49e2e33066ab6504d308dcec89
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 25 Aug 2015 16:39:16 -0400

Merge pull request #132 from taiyu-len/master

fixed segfault on exit + a little fixup of that floatfocus pr
Diffstat:
Minclude/focus.h | 1+
Msway/container.c | 2+-
Msway/focus.c | 25++++++++++++++++++-------
Msway/handlers.c | 9+--------
Msway/layout.c | 4+++-
5 files changed, 24 insertions(+), 17 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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; }