2 #define I3__FILE__ "tree.c"
28 __i3->
type = CT_OUTPUT;
31 x_set_name(__i3,
"[i3 con] pseudo-output __i3");
41 DLOG(
"adding main content container\n");
43 content->
type = CT_CON;
53 ws->
type = CT_WORKSPACE;
58 x_set_name(ws,
"[i3 con] workspace __i3_scratch");
68 bool tree_restore(
const char *path, xcb_get_geometry_reply_t *geometry) {
72 LOG(
"%s does not exist, not restoring tree\n", globbed);
89 printf(
"appended tree, using new root\n");
91 printf(
"new root = %p\n", croot);
93 printf(
"out = %p\n", out);
95 printf(
"ws = %p\n", ws);
99 if (strcmp(out->
name,
"__i3") != 0) {
100 DLOG(
"Adding pseudo-output __i3 during inplace restart\n");
119 croot->
name =
"root";
120 croot->
type = CT_ROOT;
149 if (con->
type == CT_FLOATING_CON) {
151 if (con->
type != CT_WORKSPACE)
154 DLOG(
"con = %p\n", con);
193 bool was_mapped = con->
mapped;
212 DLOG(
"next = %p, focused = %p\n", next, focused);
214 DLOG(
"closing %p, kill_window = %d\n", con, kill_window);
215 Con *child, *nextchild;
216 bool abort_kill =
false;
219 for (child =
TAILQ_FIRST(&(con->nodes_head)); child; ) {
221 DLOG(
"killing child=%p\n", child);
222 if (!
tree_close(child, kill_window,
true,
false))
228 DLOG(
"One of the children could not be killed immediately (WM_DELETE sent), aborting.\n");
232 if (con->
window != NULL) {
237 xcb_void_cookie_t cookie;
242 XCB_CW_EVENT_MASK, (uint32_t[]){ XCB_NONE });
253 cookie = xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
254 con->
window->
id, A_WM_STATE, A_WM_STATE, 32, 2, data);
270 if (con == focused) {
271 DLOG(
"This is the focused container, i need to find another one to focus. I start looking at ws = %p\n", ws);
274 dont_kill_parent =
true;
275 DLOG(
"Alright, focusing %p\n", next);
285 if (con->urgency_timer != NULL) {
286 DLOG(
"Removing urgency timer of con %p\n", con);
288 ev_timer_stop(
main_loop, con->urgency_timer);
289 FREE(con->urgency_timer);
292 if (con->type != CT_FLOATING_CON) {
306 if (!dont_kill_parent)
313 DLOG(
"Container was floating, killing floating container\n");
315 DLOG(
"parent container killed\n");
319 FREE(con->deco_render_params);
326 DLOG(
"No next container, i will just exit now\n");
330 if (was_mapped || con == focused) {
331 if ((kill_window !=
DONT_KILL_WINDOW) || !dont_kill_parent || con == focused) {
332 DLOG(
"focusing %p / %s\n", next, next->name);
333 if (next->type == CT_DOCKAREA) {
337 if (!force_set_focus && con != focused)
338 DLOG(
"not changing focus, the container was not focused before\n");
343 DLOG(
"not focusing because we're not killing anybody\n");
346 DLOG(
"not focusing, was not mapped\n");
350 if (!dont_kill_parent)
351 CALL(parent, on_remove_child);
361 assert(focused != NULL);
364 assert(focused->
type != CT_OUTPUT);
365 assert(focused->
type != CT_ROOT);
367 if (focused->
type == CT_WORKSPACE) {
368 DLOG(
"Workspaces cannot be close, closing all children instead\n");
369 Con *child, *nextchild;
370 for (child =
TAILQ_FIRST(&(focused->focus_head)); child; ) {
372 DLOG(
"killing child=%p\n", child);
381 tree_close(focused, kill_window,
false,
false);
390 if (con->
type == CT_FLOATING_CON) {
391 DLOG(
"Floating containers can't be split.\n");
395 if (con->
type == CT_WORKSPACE) {
397 DLOG(
"Just changing orientation of workspace\n");
420 DLOG(
"Just changing orientation of existing container\n");
424 DLOG(
"Splitting in orientation %d\n", orientation);
430 new->parent = parent;
448 if (focused->
parent->
type == CT_FLOATING_CON) {
456 focused->
type == CT_WORKSPACE) {
457 ELOG(
"'focus parent': Focus is already on the workspace, cannot go higher than that.\n");
471 if (next ==
TAILQ_END(&(focused->focus_head))) {
472 DLOG(
"cannot go down\n");
475 else if (next->
type == CT_FLOATING_CON) {
479 if (child ==
TAILQ_END(&(next->focus_head))) {
480 DLOG(
"cannot go down\n");
497 if (con->
type == CT_WORKSPACE) {
500 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
514 DLOG(
"-- BEGIN RENDERING --\n");
523 DLOG(
"-- END RENDERING --\n");
540 if (con->
type == CT_WORKSPACE) {
542 DLOG(
"Cannot change workspace while in global fullscreen mode.\n");
550 DLOG(
"Current output is %s\n", current_output->
name);
554 if (way ==
'n' && orientation ==
HORIZ)
556 else if (way ==
'p' && orientation ==
HORIZ)
558 else if (way ==
'n' && orientation ==
VERT)
560 else if (way ==
'p' && orientation ==
VERT)
568 DLOG(
"Next output is %s\n", next_output->
name);
571 Con *workspace = NULL;
596 if (con->
type == CT_FLOATING_CON) {
598 if (orientation ==
HORIZ) {
602 else next =
TAILQ_PREV(con, floating_head, floating_windows);
608 else next =
TAILQ_LAST(&(parent->floating_head), floating_head);
628 return _tree_next(parent, way, orientation, wrap);
634 DLOG(
"nothing to focus\n");
641 else next =
TAILQ_PREV(current, nodes_head, nodes);
648 if (
_tree_next(parent, way, orientation,
false))
657 else next =
TAILQ_LAST(&(parent->nodes_head), nodes_head);
694 Con *current, *child, *parent = con->
parent;
695 DLOG(
"Checking if I can flatten con = %p / %s\n", con, con->
name);
698 if (con->
type != CT_CON ||
705 if (child == NULL ||
TAILQ_NEXT(child, nodes) != NULL)
708 DLOG(
"child = %p, con = %p, parent = %p\n", child, con, parent);
720 DLOG(
"Alright, I have to flatten this situation now. Stay calm.\n");
724 DLOG(
"detaching...\n");
728 DLOG(
"detaching current=%p / %s\n", current, current->
name);
730 DLOG(
"re-attaching\n");
737 DLOG(
"attaching to focus list\n");
741 DLOG(
"re-attached all\n");
744 if (focus_next != NULL &&
746 DLOG(
"restoring focus to focus_next=%p\n", focus_next);
747 TAILQ_REMOVE(&(parent->focus_head), focus_next, focused);
749 DLOG(
"restored focus.\n");
753 DLOG(
"closing redundant cons\n");
767 while (current != NULL) {
774 while (current != NULL) {