summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-25 16:39:16 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-25 16:39:16 -0400
commit77dcf70a9b9037f7582718c37b4dff04324d8c7a (patch)
tree3099d9e4b4f1b2491bfc0e93d9976e4e8161fd89
parentMerge pull request #131 from nicklaswj/master (diff)
parentfixed segfault on exit + a little fixup of that floatfocus pr (diff)
downloadsway-77dcf70a9b9037f7582718c37b4dff04324d8c7a.tar.gz
sway-77dcf70a9b9037f7582718c37b4dff04324d8c7a.tar.zst
sway-77dcf70a9b9037f7582718c37b4dff04324d8c7a.zip
Merge pull request #132 from taiyu-len/master
fixed segfault on exit + a little fixup of that floatfocus pr
-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 {
19 19
20swayc_t *get_focused_container(swayc_t *parent); 20swayc_t *get_focused_container(swayc_t *parent);
21swayc_t *get_focused_view(swayc_t *parent); 21swayc_t *get_focused_view(swayc_t *parent);
22swayc_t *get_focused_float(swayc_t *ws);
22 23
23void set_focused_container(swayc_t *container); 24void set_focused_container(swayc_t *container);
24void set_focused_container_for(swayc_t *ancestor, swayc_t *container); 25void 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
166swayc_t *get_focused_view(swayc_t *parent) { 166swayc_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
180swayc_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 4d1dc56c..758af8d6 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
244static void handle_view_focus(wlc_handle view, bool focus) { 237static 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 }