aboutsummaryrefslogtreecommitdiffstats
path: root/sway/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c75
1 files changed, 8 insertions, 67 deletions
diff --git a/sway/layout.c b/sway/layout.c
index f4079d4b..8ff5c4b7 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -31,9 +31,6 @@ void add_child(swayc_t *parent, swayc_t *child) {
31 child->width, child->height, parent, parent->type, parent->width, parent->height); 31 child->width, child->height, parent, parent->type, parent->width, parent->height);
32 list_add(parent->children, child); 32 list_add(parent->children, child);
33 child->parent = parent; 33 child->parent = parent;
34 if (parent->focused == NULL) {
35 parent->focused = child;
36 }
37} 34}
38 35
39swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { 36swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) {
@@ -63,8 +60,9 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
63 return parent; 60 return parent;
64} 61}
65 62
66swayc_t *remove_child(swayc_t *parent, swayc_t *child) { 63swayc_t *remove_child(swayc_t *child) {
67 int i; 64 int i;
65 swayc_t *parent = child->parent;
68 // Special case for floating views 66 // Special case for floating views
69 if (child->is_floating) { 67 if (child->is_floating) {
70 for (i = 0; i < parent->floating->length; ++i) { 68 for (i = 0; i < parent->floating->length; ++i) {
@@ -82,7 +80,11 @@ swayc_t *remove_child(swayc_t *parent, swayc_t *child) {
82 } 80 }
83 } 81 }
84 if (parent->focused == child) { 82 if (parent->focused == child) {
85 parent->focused = NULL; 83 if (parent->children->length > 0) {
84 parent->focused = parent->children->items[i?i-1:0];
85 } else {
86 parent->focused = NULL;
87 }
86 } 88 }
87 return parent; 89 return parent;
88} 90}
@@ -206,7 +208,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
206 // Arrage floating layouts for workspaces last 208 // Arrage floating layouts for workspaces last
207 if (container->type == C_WORKSPACE) { 209 if (container->type == C_WORKSPACE) {
208 for (i = 0; i < container->floating->length; ++i) { 210 for (i = 0; i < container->floating->length; ++i) {
209 swayc_t *view = ((swayc_t *)container->floating->items[i]); 211 swayc_t *view = container->floating->items[i];
210 // Set the geometry 212 // Set the geometry
211 struct wlc_geometry geometry = { 213 struct wlc_geometry geometry = {
212 .origin = { 214 .origin = {
@@ -262,64 +264,3 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) {
262 return NULL; 264 return NULL;
263} 265}
264 266
265swayc_t *get_focused_container(swayc_t *parent) {
266 if (parent->focused == NULL) {
267 return parent;
268 }
269 return get_focused_container(parent->focused);
270}
271
272void unfocus_all(swayc_t *container) {
273 if (container->children == NULL) {
274 return;
275 }
276 int i;
277 for (i = 0; i < container->children->length; ++i) {
278 swayc_t *view = container->children->items[i];
279 if (view->type == C_VIEW) {
280 wlc_view_set_state(view->handle, WLC_BIT_ACTIVATED, false);
281 } else {
282 unfocus_all(view);
283 }
284 }
285}
286
287void focus_view(swayc_t *view) {
288 if (!view) {
289 return;
290 }
291 sway_log(L_DEBUG, "Setting focus for %p:%ld", view, view->handle);
292 swayc_t *c = view;
293 //Set focus from root to view
294 while (c != &root_container) {
295 c->parent->focused = c;
296 c = c->parent;
297 }
298 //Set output
299 wlc_output_focus(c->focused->handle);
300 //get focus for views focused window
301 while (view && view->type != C_VIEW) {
302 view = view->focused;
303 }
304 if (view) {
305 wlc_view_set_state(view->handle, WLC_BIT_ACTIVATED, true);
306 wlc_view_focus(view->handle);
307 }
308}
309
310void focus_view_for(swayc_t *top, swayc_t *view) {
311 swayc_t *find = view;
312 //Make sure top is a ancestor of view
313 while (find != top) {
314 if (find == &root_container) {
315 return;
316 }
317 find = find->parent;
318 }
319 //Set focus for top to go to view
320 while (view != top) {
321 view->parent->focused = view;
322 view = view->parent;
323 }
324}
325