i3
tree.c
Go to the documentation of this file.
1/*
2 * vim:ts=4:sw=4:expandtab
3 *
4 * i3 - an improved tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6 *
7 * tree.c: Everything that primarily modifies the layout tree data structure.
8 *
9 */
10#include "all.h"
11
12struct Con *croot;
13struct Con *focused;
14
16
17/*
18 * Create the pseudo-output __i3. Output-independent workspaces such as
19 * __i3_scratch will live there.
20 *
21 */
22static Con *_create___i3(void) {
23 Con *__i3 = con_new(croot, NULL);
24 FREE(__i3->name);
25 __i3->name = sstrdup("__i3");
26 __i3->type = CT_OUTPUT;
27 __i3->layout = L_OUTPUT;
29 x_set_name(__i3, "[i3 con] pseudo-output __i3");
30 /* For retaining the correct position/size of a scratchpad window, the
31 * dimensions of the real outputs should be multiples of the __i3
32 * pseudo-output. Ensuring that is the job of scratchpad_fix_resolution()
33 * which gets called after this function and after detecting all the
34 * outputs (or whenever an output changes). */
35 __i3->rect.width = 1280;
36 __i3->rect.height = 1024;
37
38 /* Add a content container. */
39 DLOG("adding main content container\n");
40 Con *content = con_new(NULL, NULL);
41 content->type = CT_CON;
42 FREE(content->name);
43 content->name = sstrdup("content");
44 content->layout = L_SPLITH;
45
46 x_set_name(content, "[i3 con] content __i3");
47 con_attach(content, __i3, false);
48
49 /* Attach the __i3_scratch workspace. */
50 Con *ws = con_new(NULL, NULL);
51 ws->type = CT_WORKSPACE;
52 ws->num = -1;
53 ws->name = sstrdup("__i3_scratch");
54 ws->layout = L_SPLITH;
55 con_attach(ws, content, false);
56 x_set_name(ws, "[i3 con] workspace __i3_scratch");
58
59 return __i3;
60}
61
62/*
63 * Loads tree from 'path' (used for in-place restarts).
64 *
65 */
66bool tree_restore(const char *path, xcb_get_geometry_reply_t *geometry) {
67 bool result = false;
68 char *globbed = resolve_tilde(path);
69 char *buf = NULL;
70
71 if (!path_exists(globbed)) {
72 LOG("%s does not exist, not restoring tree\n", globbed);
73 goto out;
74 }
75
76 ssize_t len;
77 if ((len = slurp(globbed, &buf)) < 0) {
78 /* slurp already logged an error. */
79 goto out;
80 }
81
82 /* TODO: refactor the following */
83 croot = con_new(NULL, NULL);
84 croot->rect = (Rect){
85 geometry->x,
86 geometry->y,
87 geometry->width,
88 geometry->height};
89 focused = croot;
90
91 tree_append_json(focused, buf, len, NULL);
92
93 DLOG("appended tree, using new root\n");
94 croot = TAILQ_FIRST(&(croot->nodes_head));
95 if (!croot) {
96 /* tree_append_json failed. Continuing here would segfault. */
97 goto out;
98 }
99 DLOG("new root = %p\n", croot);
100 Con *out = TAILQ_FIRST(&(croot->nodes_head));
101 DLOG("out = %p\n", out);
102 Con *ws = TAILQ_FIRST(&(out->nodes_head));
103 DLOG("ws = %p\n", ws);
104
105 /* For in-place restarting into v4.2, we need to make sure the new
106 * pseudo-output __i3 is present. */
107 if (strcmp(out->name, "__i3") != 0) {
108 DLOG("Adding pseudo-output __i3 during inplace restart\n");
109 Con *__i3 = _create___i3();
110 /* Ensure that it is the first output, other places in the code make
111 * that assumption. */
112 TAILQ_REMOVE(&(croot->nodes_head), __i3, nodes);
113 TAILQ_INSERT_HEAD(&(croot->nodes_head), __i3, nodes);
114 }
115
117 result = true;
118
119out:
120 free(globbed);
121 free(buf);
122 return result;
123}
124
125/*
126 * Initializes the tree by creating the root node. The CT_OUTPUT Cons below the
127 * root node are created in randr.c for each Output.
128 *
129 */
130void tree_init(xcb_get_geometry_reply_t *geometry) {
131 croot = con_new(NULL, NULL);
132 FREE(croot->name);
133 croot->name = "root";
134 croot->type = CT_ROOT;
136 croot->rect = (Rect){
137 geometry->x,
138 geometry->y,
139 geometry->width,
140 geometry->height};
141
142 _create___i3();
143}
144
145/*
146 * Opens an empty container in the current container
147 *
148 */
149Con *tree_open_con(Con *con, i3Window *window) {
150 if (con == NULL) {
151 /* every focusable Con has a parent (outputs have parent root) */
152 con = focused->parent;
153 /* If the parent is an output, we are on a workspace. In this case,
154 * the new container needs to be opened as a leaf of the workspace. */
155 if (con->parent->type == CT_OUTPUT && con->type != CT_DOCKAREA) {
156 con = focused;
157 }
158
159 /* If the currently focused container is a floating container, we
160 * attach the new container to the currently focused spot in its
161 * workspace. */
162 if (con->type == CT_FLOATING_CON) {
164 if (con->type != CT_WORKSPACE) {
165 con = con->parent;
166 }
167 }
168 DLOG("con = %p\n", con);
169 }
170
171 assert(con != NULL);
172
173 /* 3. create the container and attach it to its parent */
174 Con *new = con_new(con, window);
175 new->layout = L_SPLITH;
176
177 /* 4: re-calculate child->percent for each child */
178 con_fix_percent(con);
179
180 return new;
181}
182
183/*
184 * Closes the given container including all children.
185 * Returns true if the container was killed or false if just WM_DELETE was sent
186 * and the window is expected to kill itself.
187 *
188 * The dont_kill_parent flag is specified when the function calls itself
189 * recursively while deleting a containers children.
190 *
191 */
192bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent) {
193 Con *parent = con->parent;
194
195 /* remove the urgency hint of the workspace (if set) */
196 if (con->urgent) {
197 con_set_urgency(con, false);
200 }
201
202 DLOG("closing %p, kill_window = %d\n", con, kill_window);
203 Con *child, *nextchild;
204 bool abort_kill = false;
205 /* We cannot use TAILQ_FOREACH because the children get deleted
206 * in their parent’s nodes_head */
207 for (child = TAILQ_FIRST(&(con->nodes_head)); child;) {
208 nextchild = TAILQ_NEXT(child, nodes);
209 DLOG("killing child=%p\n", child);
210 if (!tree_close_internal(child, kill_window, true)) {
211 abort_kill = true;
212 }
213 child = nextchild;
214 }
215
216 if (abort_kill) {
217 DLOG("One of the children could not be killed immediately (WM_DELETE sent), aborting.\n");
218 return false;
219 }
220
221 if (con->window != NULL) {
222 if (kill_window != DONT_KILL_WINDOW) {
223 x_window_kill(con->window->id, kill_window);
224 return false;
225 } else {
226 xcb_void_cookie_t cookie;
227 /* Ignore any further events by clearing the event mask,
228 * unmap the window,
229 * then reparent it to the root window. */
230 xcb_change_window_attributes(conn, con->window->id,
231 XCB_CW_EVENT_MASK, (uint32_t[]){XCB_NONE});
232 xcb_unmap_window(conn, con->window->id);
233 cookie = xcb_reparent_window(conn, con->window->id, root, con->rect.x, con->rect.y);
234
235 /* Ignore X11 errors for the ReparentWindow request.
236 * X11 Errors are returned when the window was already destroyed */
237 add_ignore_event(cookie.sequence, 0);
238
239 /* We are no longer handling this window, thus set WM_STATE to
240 * WM_STATE_WITHDRAWN (see ICCCM 4.1.3.1) */
241 long data[] = {XCB_ICCCM_WM_STATE_WITHDRAWN, XCB_NONE};
242 cookie = xcb_change_property(conn, XCB_PROP_MODE_REPLACE,
243 con->window->id, A_WM_STATE, A_WM_STATE, 32, 2, data);
244
245 /* Remove the window from the save set. All windows in the save set
246 * will be mapped when i3 closes its connection (e.g. when
247 * restarting). This is not what we want, since some apps keep
248 * unmapped windows around and don’t expect them to suddenly be
249 * mapped. See https://bugs.i3wm.org/1617 */
250 xcb_change_save_set(conn, XCB_SET_MODE_DELETE, con->window->id);
251
252 /* Stop receiving ShapeNotify events. */
253 if (shape_supported) {
254 xcb_shape_select_input(conn, con->window->id, false);
255 }
256
257 /* Ignore X11 errors for the ReparentWindow request.
258 * X11 Errors are returned when the window was already destroyed */
259 add_ignore_event(cookie.sequence, 0);
260 }
261 ipc_send_window_event("close", con);
262 window_free(con->window);
263 con->window = NULL;
264 }
265
266 Con *ws = con_get_workspace(con);
267
268 /* Figure out which container to focus next before detaching 'con'. */
269 Con *next = (con == focused) ? con_next_focused(con) : NULL;
270 DLOG("next = %p, focused = %p\n", next, focused);
271
272 /* Detach the container so that it will not be rendered anymore. */
273 con_detach(con);
274
275 /* disable urgency timer, if needed */
276 if (con->urgency_timer != NULL) {
277 DLOG("Removing urgency timer of con %p\n", con);
279 ev_timer_stop(main_loop, con->urgency_timer);
280 FREE(con->urgency_timer);
281 }
282
283 if (con->type != CT_FLOATING_CON) {
284 /* If the container is *not* floating, we might need to re-distribute
285 * percentage values for the resized containers. */
286 con_fix_percent(parent);
287 }
288
289 /* Render the tree so that the surrounding containers take up the space
290 * which 'con' does no longer occupy. If we don’t render here, there will
291 * be a gap in our containers and that could trigger an EnterNotify for an
292 * underlying container, see ticket #660.
293 *
294 * Rendering has to be avoided when dont_kill_parent is set (when
295 * tree_close_internal calls itself recursively) because the tree is in a
296 * non-renderable state during that time. */
297 if (!dont_kill_parent) {
298 tree_render();
299 }
300
301 /* kill the X11 part of this container */
302 x_con_kill(con);
303
304 if (ws == con) {
305 DLOG("Closing workspace container %s, updating EWMH atoms\n", ws->name);
307 }
308
309 con_free(con);
310
311 if (next) {
312 con_activate(next);
313 } else {
314 DLOG("not changing focus, the container was not focused before\n");
315 }
316
317 /* check if the parent container is empty now and close it */
318 if (!dont_kill_parent) {
319 CALL(parent, on_remove_child);
320 }
321
322 return true;
323}
324
325/*
326 * Splits (horizontally or vertically) the given container by creating a new
327 * container which contains the old one and the future ones.
328 *
329 */
330void tree_split(Con *con, orientation_t orientation) {
331 if (con_is_floating(con)) {
332 DLOG("Floating containers can't be split.\n");
333 return;
334 }
335
336 if (con->type == CT_WORKSPACE) {
337 if (con_num_children(con) < 2) {
338 if (con_num_children(con) == 0) {
339 DLOG("Changing workspace_layout to L_DEFAULT\n");
341 }
342 DLOG("Changing orientation of workspace\n");
343 con->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV;
344 return;
345 } else {
346 /* if there is more than one container on the workspace
347 * move them into a new container and handle this instead */
348 con = workspace_encapsulate(con);
349 }
350 }
351
352 Con *parent = con->parent;
353
354 /* Force re-rendering to make the indicator border visible. */
356
357 /* if we are in a container whose parent contains only one
358 * child (its split functionality is unused so far), we just change the
359 * orientation (more intuitive than splitting again) */
360 if (con_num_children(parent) == 1 &&
361 (parent->layout == L_SPLITH ||
362 parent->layout == L_SPLITV)) {
363 parent->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV;
364 DLOG("Just changing orientation of existing container\n");
365 return;
366 }
367
368 DLOG("Splitting in orientation %d\n", orientation);
369
370 /* 2: replace it with a new Con */
371 Con *new = con_new(NULL, NULL);
372 TAILQ_REPLACE(&(parent->nodes_head), con, new, nodes);
373 TAILQ_REPLACE(&(parent->focus_head), con, new, focused);
374 new->parent = parent;
375 new->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV;
376
377 /* 3: swap 'percent' (resize factor) */
378 new->percent = con->percent;
379 con->percent = 0.0;
380
381 /* 4: add it as a child to the new Con */
382 con_attach(con, new, false);
383}
384
385/*
386 * Moves focus one level up. Returns true if focus changed.
387 *
388 */
389bool level_up(void) {
390 /* Skip over floating containers and go directly to the grandparent
391 * (which should always be a workspace) */
392 if (focused->parent->type == CT_FLOATING_CON) {
394 return true;
395 }
396
397 /* We can focus up to the workspace, but not any higher in the tree */
398 if ((focused->parent->type != CT_CON &&
399 focused->parent->type != CT_WORKSPACE) ||
400 focused->type == CT_WORKSPACE) {
401 ELOG("'focus parent': Focus is already on the workspace, cannot go higher than that.\n");
402 return false;
403 }
405 return true;
406}
407
408/*
409 * Moves focus one level down. Returns true if focus changed.
410 *
411 */
412bool level_down(void) {
413 /* Go down the focus stack of the current node */
414 Con *next = TAILQ_FIRST(&(focused->focus_head));
415 if (next == TAILQ_END(&(focused->focus_head))) {
416 DLOG("cannot go down\n");
417 return false;
418 } else if (next->type == CT_FLOATING_CON) {
419 /* Floating cons shouldn't be directly focused; try immediately
420 * going to the grandchild of the focused con. */
421 Con *child = TAILQ_FIRST(&(next->focus_head));
422 if (child == TAILQ_END(&(next->focus_head))) {
423 DLOG("cannot go down\n");
424 return false;
425 } else {
426 next = TAILQ_FIRST(&(next->focus_head));
427 }
428 }
429
430 con_activate(next);
431 return true;
432}
433
434static void mark_unmapped(Con *con) {
435 Con *current;
436
437 con->mapped = false;
438 TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
439 mark_unmapped(current);
440 }
441 if (con->type == CT_WORKSPACE) {
442 /* We need to call mark_unmapped on floating nodes as well since we can
443 * make containers floating. */
444 TAILQ_FOREACH (current, &(con->floating_head), floating_windows) {
445 mark_unmapped(current);
446 }
447 }
448}
449
450/*
451 * Renders the tree, that is rendering all outputs using render_con() and
452 * pushing the changes to X11 using x_push_changes().
453 *
454 */
455void tree_render(void) {
456 if (croot == NULL) {
457 return;
458 }
459
460 DLOG("-- BEGIN RENDERING --\n");
461 /* Reset map state for all nodes in tree */
462 /* TODO: a nicer method to walk all nodes would be good, maybe? */
464 croot->mapped = true;
465
467
469 DLOG("-- END RENDERING --\n");
470}
471
472static Con *get_tree_next_workspace(Con *con, direction_t direction) {
474 DLOG("Cannot change workspace while in global fullscreen mode.\n");
475 return NULL;
476 }
477
478 // Use the center of the container instead of the left/top edges, to make
479 // this work with negative gaps. See https://github.com/i3/i3/issues/5293
480 const uint32_t x = con->rect.x + (con->rect.width / 2);
481 const uint32_t y = con->rect.y + (con->rect.height / 2);
482 Output *current_output = get_output_containing(x, y);
483 if (!current_output) {
484 return NULL;
485 }
486 DLOG("Current output is %s\n", output_primary_name(current_output));
487
488 Output *next_output = get_output_next(direction, current_output, CLOSEST_OUTPUT);
489 if (!next_output) {
490 return NULL;
491 }
492 DLOG("Next output is %s\n", output_primary_name(next_output));
493
494 /* Find visible workspace on next output */
495 Con *workspace = NULL;
496 GREP_FIRST(workspace, output_get_content(next_output->con), workspace_is_visible(child));
497 return workspace;
498}
499
500/*
501 * Returns the next / previous container to focus in the given direction. Does
502 * not modify focus and ensures focus restrictions for fullscreen containers
503 * are respected.
504 *
505 */
506static Con *get_tree_next(Con *con, direction_t direction) {
507 const bool previous = position_from_direction(direction) == BEFORE;
508 const orientation_t orientation = orientation_from_direction(direction);
509
510 Con *first_wrap = NULL;
511
512 if (con->type == CT_WORKSPACE) {
513 /* Special case for FOCUS_WRAPPING_WORKSPACE: allow the focus to leave
514 * the workspace only when a workspace is selected. */
515 goto handle_workspace;
516 }
517
518 while (con->type != CT_WORKSPACE) {
519 if (con->fullscreen_mode == CF_OUTPUT) {
520 /* We've reached a fullscreen container. Directional focus should
521 * now operate on the workspace level. */
522 con = con_get_workspace(con);
523 break;
524 } else if (con->fullscreen_mode == CF_GLOBAL) {
525 /* Focus changes should happen only inside the children of a global
526 * fullscreen container. */
527 return first_wrap;
528 }
529
530 Con *const parent = con->parent;
531 if (con->type == CT_FLOATING_CON) {
532 if (orientation != HORIZ) {
533 /* up/down does not change floating containers */
534 return NULL;
535 }
536
537 /* left/right focuses the previous/next floating container */
538 Con *next = previous ? TAILQ_PREV(con, floating_head, floating_windows)
539 : TAILQ_NEXT(con, floating_windows);
540 /* If there is no next/previous container, wrap */
541 if (!next) {
542 next = previous ? TAILQ_LAST(&(parent->floating_head), floating_head)
543 : TAILQ_FIRST(&(parent->floating_head));
544 }
545 /* Our parent does not list us in floating heads? */
546 assert(next);
547
548 return next;
549 }
550
551 if (con_num_children(parent) > 1 && con_orientation(parent) == orientation) {
552 Con *const next = previous ? TAILQ_PREV(con, nodes_head, nodes)
553 : TAILQ_NEXT(con, nodes);
554 if (next && con_fullscreen_permits_focusing(next)) {
555 return next;
556 }
557
558 Con *const wrap = previous ? TAILQ_LAST(&(parent->nodes_head), nodes_head)
559 : TAILQ_FIRST(&(parent->nodes_head));
560 switch (config.focus_wrapping) {
562 break;
565 if (!first_wrap && con_fullscreen_permits_focusing(wrap)) {
566 first_wrap = wrap;
567 }
568 break;
570 /* 'force' should always return to ensure focus doesn't
571 * leave the parent. */
572 if (next) {
573 return NULL; /* blocked by fullscreen */
574 }
575 return con_fullscreen_permits_focusing(wrap) ? wrap : NULL;
576 }
577 }
578
579 con = parent;
580 }
581
582 assert(con->type == CT_WORKSPACE);
584 return first_wrap;
585 }
586
587handle_workspace:;
588 Con *workspace = get_tree_next_workspace(con, direction);
589 return workspace ? workspace : first_wrap;
590}
591
592/*
593 * Changes focus in the given direction
594 *
595 */
596void tree_next(Con *con, direction_t direction) {
597 Con *next = get_tree_next(con, direction);
598 if (!next) {
599 return;
600 }
601 if (next->type == CT_WORKSPACE) {
602 /* Show next workspace and focus appropriate container if possible. */
603 /* Use descend_focused first to give higher priority to floating or
604 * tiling fullscreen containers. */
605 Con *focus = con_descend_focused(next);
606 if (focus->fullscreen_mode == CF_NONE) {
607 Con *focus_tiling = con_descend_tiling_focused(next);
608 /* If descend_tiling returned a workspace then focus is either a
609 * floating container or the same workspace. */
610 if (focus_tiling != next) {
611 focus = focus_tiling;
612 }
613 }
614
615 workspace_show(next);
616 con_activate(focus);
617 x_set_warp_to(&(focus->rect));
618 return;
619 } else if (next->type == CT_FLOATING_CON) {
620 /* Raise the floating window on top of other windows preserving relative
621 * stack order */
622 Con *parent = next->parent;
623 while (TAILQ_LAST(&(parent->floating_head), floating_head) != next) {
624 Con *last = TAILQ_LAST(&(parent->floating_head), floating_head);
625 TAILQ_REMOVE(&(parent->floating_head), last, floating_windows);
626 TAILQ_INSERT_HEAD(&(parent->floating_head), last, floating_windows);
627 }
628 }
629
632}
633
634/*
635 * Get the previous / next sibling
636 *
637 */
639 Con *to_focus = (direction == BEFORE ? TAILQ_PREV(con, nodes_head, nodes)
640 : TAILQ_NEXT(con, nodes));
642 return to_focus;
643 }
644 return NULL;
645}
646
647/*
648 * tree_flatten() removes pairs of redundant split containers, e.g.:
649 * [workspace, horizontal]
650 * [v-split] [child3]
651 * [h-split]
652 * [child1] [child2]
653 * In this example, the v-split and h-split container are redundant.
654 * Such a situation can be created by moving containers in a direction which is
655 * not the orientation of their parent container. i3 needs to create a new
656 * split container then and if you move containers this way multiple times,
657 * redundant chains of split-containers can be the result.
658 *
659 */
660void tree_flatten(Con *con) {
661 Con *current, *child, *parent = con->parent;
662 DLOG("Checking if I can flatten con = %p / %s\n", con, con->name);
663
664 /* We only consider normal containers without windows */
665 if (con->type != CT_CON ||
666 parent->layout == L_OUTPUT || /* con == "content" */
667 con->window != NULL) {
668 goto recurse;
669 }
670
671 /* Ensure it got only one child */
672 child = TAILQ_FIRST(&(con->nodes_head));
673 if (child == NULL || TAILQ_NEXT(child, nodes) != NULL) {
674 goto recurse;
675 }
676
677 DLOG("child = %p, con = %p, parent = %p\n", child, con, parent);
678
679 /* The child must have a different orientation than the con but the same as
680 * the con’s parent to be redundant */
681 if (!con_is_split(con) ||
682 !con_is_split(child) ||
683 (con->layout != L_SPLITH && con->layout != L_SPLITV) ||
684 (child->layout != L_SPLITH && child->layout != L_SPLITV) ||
685 con_orientation(con) == con_orientation(child) ||
686 con_orientation(child) != con_orientation(parent)) {
687 goto recurse;
688 }
689
690 DLOG("Alright, I have to flatten this situation now. Stay calm.\n");
691 /* 1: save focus */
692 Con *focus_next = TAILQ_FIRST(&(child->focus_head));
693
694 DLOG("detaching...\n");
695 /* 2: re-attach the children to the parent before con */
696 while (!TAILQ_EMPTY(&(child->nodes_head))) {
697 current = TAILQ_FIRST(&(child->nodes_head));
698 DLOG("detaching current=%p / %s\n", current, current->name);
699 con_detach(current);
700 DLOG("re-attaching\n");
701 /* We don’t use con_attach() here because for a CT_CON, the special
702 * case handling of con_attach() does not trigger. So all it would do
703 * is calling TAILQ_INSERT_AFTER, but with the wrong container. So we
704 * directly use the TAILQ macros. */
705 current->parent = parent;
706 TAILQ_INSERT_BEFORE(con, current, nodes);
707 DLOG("attaching to focus list\n");
708 TAILQ_INSERT_TAIL(&(parent->focus_head), current, focused);
709 current->percent = con->percent;
710 }
711 DLOG("re-attached all\n");
712
713 /* 3: restore focus, if con was focused */
714 if (focus_next != NULL &&
715 TAILQ_FIRST(&(parent->focus_head)) == con) {
716 DLOG("restoring focus to focus_next=%p\n", focus_next);
717 TAILQ_REMOVE(&(parent->focus_head), focus_next, focused);
718 TAILQ_INSERT_HEAD(&(parent->focus_head), focus_next, focused);
719 DLOG("restored focus.\n");
720 }
721
722 /* 4: close the redundant cons */
723 DLOG("closing redundant cons\n");
725
726 /* Well, we got to abort the recursion here because we destroyed the
727 * container. However, if tree_flatten() is called sufficiently often,
728 * there can’t be the situation of having two pairs of redundant containers
729 * at once. Therefore, we can safely abort the recursion on this level
730 * after flattening. */
731 return;
732
733recurse:
734 /* We cannot use normal foreach here because tree_flatten might close the
735 * current container. */
736 current = TAILQ_FIRST(&(con->nodes_head));
737 while (current != NULL) {
738 Con *next = TAILQ_NEXT(current, nodes);
739 tree_flatten(current);
740 current = next;
741 }
742
743 current = TAILQ_FIRST(&(con->floating_head));
744 while (current != NULL) {
745 Con *next = TAILQ_NEXT(current, floating_windows);
746 tree_flatten(current);
747 current = next;
748 }
749}
#define y(x,...)
Definition commands.c:18
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
Definition con.c:599
void con_set_urgency(Con *con, bool urgent)
Set urgency flag to the container, all the parent containers and the workspace.
Definition con.c:2431
bool con_is_floating(Con *con)
Returns true if the node is floating.
Definition con.c:670
orientation_t con_orientation(Con *con)
Returns the orientation of the given container (for stacked containers, vertical orientation is used ...
Definition con.c:1625
void con_force_split_parents_redraw(Con *con)
force parent split containers to be redrawn
Definition con.c:21
void con_update_parents_urgency(Con *con)
Make all parent containers urgent if con is urgent or clear the urgent flag of all parent containers ...
Definition con.c:2401
Con * con_new(Con *parent, i3Window *window)
A wrapper for con_new_skeleton, to retain the old con_new behaviour.
Definition con.c:70
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition con.c:547
bool con_is_split(Con *con)
Returns true if a container should be considered split.
Definition con.c:390
Con * con_descend_tiling_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
Definition con.c:1714
bool con_fullscreen_permits_focusing(Con *con)
Returns true if changing the focus to con would be allowed considering the fullscreen focus constrain...
Definition con.c:2334
void con_detach(Con *con)
Detaches the given container from its current parent.
Definition con.c:234
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
Definition con.c:1144
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Definition con.c:226
void con_free(Con *con)
Frees the specified container.
Definition con.c:80
int con_num_children(Con *con)
Returns the number of children of this container.
Definition con.c:1075
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
Definition con.c:292
Con * con_next_focused(Con *con)
Returns the container which will be focused next when the given container is not available anymore.
Definition con.c:1656
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
Definition con.c:1698
Config config
Definition config.c:19
void ewmh_update_desktop_properties(void)
Updates all the EWMH desktop properties.
Definition ewmh.c:118
static Con * to_focus
Definition load_layout.c:22
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Definition output.c:53
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition output.c:16
Output * get_output_containing(unsigned int x, unsigned int y)
Returns the active (!) output which contains the coordinates x, y or NULL if there is no output which...
Definition randr.c:122
Output * get_output_next(direction_t direction, Output *current, output_close_far_t close_far)
Gets the output which is the next one in the given direction.
Definition randr.c:255
void render_con(Con *con)
"Renders" the given container (and its children), meaning that all rects are updated correctly.
Definition render.c:43
void restore_open_placeholder_windows(Con *parent)
Open placeholder windows for all children of parent.
struct Con * focused
Definition tree.c:13
void tree_flatten(Con *con)
tree_flatten() removes pairs of redundant split containers, e.g.: [workspace, horizontal] [v-split] [...
Definition tree.c:660
bool tree_restore(const char *path, xcb_get_geometry_reply_t *geometry)
Loads tree from ~/.i3/_restart.json (used for in-place restarts).
Definition tree.c:66
struct Con * croot
Definition tree.c:12
static Con * get_tree_next_workspace(Con *con, direction_t direction)
Definition tree.c:472
void tree_next(Con *con, direction_t direction)
Changes focus in the given direction.
Definition tree.c:596
bool level_up(void)
Moves focus one level up.
Definition tree.c:389
static Con * _create___i3(void)
Definition tree.c:22
static Con * get_tree_next(Con *con, direction_t direction)
Definition tree.c:506
bool level_down(void)
Moves focus one level down.
Definition tree.c:412
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
Definition tree.c:149
bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent)
Closes the given container including all children.
Definition tree.c:192
static void mark_unmapped(Con *con)
Definition tree.c:434
void tree_init(xcb_get_geometry_reply_t *geometry)
Initializes the tree by creating the root node, adding all RandR outputs to the tree (that means rand...
Definition tree.c:130
struct all_cons_head all_cons
Definition tree.c:15
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
Definition tree.c:455
void tree_split(Con *con, orientation_t orientation)
Splits (horizontally or vertically) the given container by creating a new container which contains th...
Definition tree.c:330
Con * get_tree_next_sibling(Con *con, position_t direction)
Get the previous / next sibling.
Definition tree.c:638
orientation_t orientation_from_direction(direction_t direction)
Convert a direction to its corresponding orientation.
Definition util.c:466
position_t position_from_direction(direction_t direction)
Convert a direction to its corresponding position.
Definition util.c:474
ssize_t slurp(const char *path, char **buf)
Slurp reads path in its entirety into buf, returning the length of the file or -1 if the file could n...
Definition util.c:437
void window_free(i3Window *win)
Frees an i3Window and all its members.
Definition window.c:18
void workspace_update_urgent_flag(Con *ws)
Goes through all clients on the given workspace and updates the workspace’s urgent flag accordingly.
Definition workspace.c:938
void workspace_show(Con *workspace)
Switches to the given workspace.
Definition workspace.c:438
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
Definition workspace.c:320
Con * workspace_encapsulate(Con *ws)
Creates a new container and re-parents all of children from the given workspace into it.
Definition workspace.c:1028
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
Definition x.c:1545
void x_window_kill(xcb_window_t window, kill_window_t kill_window)
Kills the given X11 window using WM_DELETE_WINDOW (if supported).
Definition x.c:331
void x_set_name(Con *con, const char *name)
Sets the WM_NAME property (so, no UTF8, but used only for debugging anyways) of the given name.
Definition x.c:1497
void x_push_changes(Con *con)
Pushes all changes (state of each node, see x_push_node() and the window stack) to X11.
Definition x.c:1270
void x_con_kill(Con *con)
Kills the window decoration associated with the given container.
Definition x.c:287
void ipc_send_window_event(const char *property, Con *con)
For the window events we send, along the usual "change" field, also the window container,...
Definition ipc.c:1650
xcb_connection_t * conn
XCB connection and root screen.
Definition main.c:54
xcb_window_t root
Definition main.c:67
bool shape_supported
Definition main.c:105
struct ev_loop * main_loop
Definition main.c:79
position_t
Definition data.h:63
@ BEFORE
Definition data.h:63
struct Rect Rect
Definition data.h:44
@ L_OUTPUT
Definition data.h:106
@ L_SPLITH
Definition data.h:108
@ L_SPLITV
Definition data.h:107
@ L_DEFAULT
Definition data.h:102
@ FOCUS_WRAPPING_OFF
Definition data.h:169
@ FOCUS_WRAPPING_ON
Definition data.h:170
@ FOCUS_WRAPPING_FORCE
Definition data.h:171
@ FOCUS_WRAPPING_WORKSPACE
Definition data.h:172
orientation_t
Definition data.h:60
@ HORIZ
Definition data.h:61
@ CF_OUTPUT
Definition data.h:630
@ CF_GLOBAL
Definition data.h:631
@ CF_NONE
Definition data.h:629
kill_window_t
parameter to specify whether tree_close_internal() and x_window_kill() should kill only this specific...
Definition data.h:73
@ DONT_KILL_WINDOW
Definition data.h:73
direction_t
Definition data.h:56
void add_ignore_event(const int sequence, const int response_type)
Adds the given sequence to the list of events which are ignored.
char * resolve_tilde(const char *path)
This function resolves ~ in pathnames.
#define DLOG(fmt,...)
Definition libi3.h:105
#define LOG(fmt,...)
Definition libi3.h:95
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define ELOG(fmt,...)
Definition libi3.h:100
bool path_exists(const char *path)
Checks if the given path exists by calling stat().
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:347
#define TAILQ_END(head)
Definition queue.h:337
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:376
#define TAILQ_PREV(elm, headname, field)
Definition queue.h:342
#define TAILQ_REPLACE(head, elm, elm2, field)
Definition queue.h:413
#define TAILQ_FIRST(head)
Definition queue.h:336
#define TAILQ_REMOVE(head, elm, field)
Definition queue.h:402
#define TAILQ_NEXT(elm, field)
Definition queue.h:338
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:324
#define TAILQ_EMPTY(head)
Definition queue.h:344
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
Definition queue.h:394
#define TAILQ_LAST(head, headname)
Definition queue.h:339
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition queue.h:366
@ CLOSEST_OUTPUT
Definition randr.h:23
#define CALL(obj, member,...)
Definition util.h:53
#define GREP_FIRST(dest, head, condition)
Definition util.h:38
#define FREE(pointer)
Definition util.h:47
focus_wrapping_t focus_wrapping
When focus wrapping is enabled (the default), attempting to move focus past the edge of the screen (i...
uint32_t height
Definition data.h:189
uint32_t x
Definition data.h:186
uint32_t y
Definition data.h:187
uint32_t width
Definition data.h:188
An Output is a physical output on your graphics driver.
Definition data.h:391
Con * con
Pointer to the Con which represents this output.
Definition data.h:411
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
Definition data.h:424
xcb_window_t id
Definition data.h:425
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition data.h:643
struct Con * parent
Definition data.h:678
enum Con::@18 type
layout_t workspace_layout
Definition data.h:755
double percent
Definition data.h:712
struct Rect rect
Definition data.h:682
layout_t layout
Definition data.h:755
bool mapped
Definition data.h:644
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
Definition data.h:673
struct ev_timer * urgency_timer
Definition data.h:721
struct Window * window
Definition data.h:718
char * name
Definition data.h:692
fullscreen_mode_t fullscreen_mode
Definition data.h:734
bool urgent
Definition data.h:648