Merge pull request #132 from taiyu-len/master

fixed segfault on exit + a little fixup of that floatfocus pr
This commit is contained in:
Drew DeVault 2015-08-25 16:39:16 -04:00
commit 77dcf70a9b
5 changed files with 24 additions and 17 deletions

View file

@ -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);

View file

@ -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:

View file

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

View file

@ -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) {

View file

@ -152,6 +152,8 @@ swayc_t *remove_child(swayc_t *child) {
if (parent->focused == child) {
if (parent->children->length > 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;
}