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;
46 content->
layout = L_SPLITH;
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);
161 new->layout = L_SPLITH;
193 bool was_mapped = con->
mapped;
205 DLOG(
"next = %p, focused = %p\n", next, focused);
207 DLOG(
"closing %p, kill_window = %d\n", con, kill_window);
208 Con *child, *nextchild;
209 bool abort_kill =
false;
212 for (child =
TAILQ_FIRST(&(con->nodes_head)); child; ) {
214 DLOG(
"killing child=%p\n", child);
215 if (!
tree_close(child, kill_window,
true,
false))
221 DLOG(
"One of the children could not be killed immediately (WM_DELETE sent), aborting.\n");
225 if (con->
window != NULL) {
230 xcb_void_cookie_t cookie;
241 cookie = xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
242 con->
window->
id, A_WM_STATE, A_WM_STATE, 32, 2, data);
261 DLOG(
"Removing urgency timer of con %p\n", con);
267 if (con->
type != CT_FLOATING_CON) {
275 DLOG(
"Container was floating, killing floating container\n");
277 DLOG(
"parent container killed\n");
278 if (con == focused) {
279 DLOG(
"This is the focused container, i need to find another one to focus. I start looking at ws = %p\n", ws);
283 dont_kill_parent =
true;
284 DLOG(
"Alright, focusing %p\n", next);
298 DLOG(
"No next container, i will just exit now\n");
302 if (was_mapped || con == focused) {
303 if ((kill_window !=
DONT_KILL_WINDOW) || !dont_kill_parent || con == focused) {
304 DLOG(
"focusing %p / %s\n", next, next->
name);
305 if (next->
type == CT_DOCKAREA) {
309 if (!force_set_focus && con != focused)
310 DLOG(
"not changing focus, the container was not focused before\n");
315 DLOG(
"not focusing because we're not killing anybody\n");
318 DLOG(
"not focusing, was not mapped\n");
322 if (!dont_kill_parent)
323 CALL(parent, on_remove_child);
333 assert(focused != NULL);
334 if (focused->
type == CT_WORKSPACE) {
335 LOG(
"Cannot close workspace\n");
340 assert(focused->
type != CT_OUTPUT);
341 assert(focused->
type != CT_ROOT);
344 tree_close(focused, kill_window,
false,
false);
354 if (con->
type == CT_WORKSPACE) {
355 DLOG(
"Workspace, simply changing orientation to %d\n", orientation);
356 con->
layout = (orientation ==
HORIZ) ? L_SPLITH : L_SPLITV;
359 else if (con->
type == CT_FLOATING_CON) {
360 DLOG(
"Floating containers can't be split.\n");
374 (parent->
layout == L_SPLITH ||
375 parent->
layout == L_SPLITV)) {
376 parent->
layout = (orientation ==
HORIZ) ? L_SPLITH : L_SPLITV;
377 DLOG(
"Just changing orientation of existing container\n");
381 DLOG(
"Splitting in orientation %d\n", orientation);
387 new->parent = parent;
388 new->
layout = (orientation ==
HORIZ) ? L_SPLITH : L_SPLITV;
405 if (focused->
parent->
type == CT_FLOATING_CON) {
413 focused->
type == CT_WORKSPACE) {
414 ELOG(
"'focus parent': Focus is already on the workspace, cannot go higher than that.\n");
428 if (next ==
TAILQ_END(&(focused->focus_head))) {
429 DLOG(
"cannot go down\n");
432 else if (next->
type == CT_FLOATING_CON) {
436 if (child ==
TAILQ_END(&(next->focus_head))) {
437 DLOG(
"cannot go down\n");
454 if (con->
type == CT_WORKSPACE) {
457 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
471 DLOG(
"-- BEGIN RENDERING --\n");
480 DLOG(
"-- END RENDERING --\n");
497 if (con->
type == CT_WORKSPACE) {
499 DLOG(
"Cannot change workspace while in global fullscreen mode.\n");
507 DLOG(
"Current output is %s\n", current_output->
name);
511 if (way ==
'n' && orientation ==
HORIZ)
513 else if (way ==
'p' && orientation ==
HORIZ)
515 else if (way ==
'n' && orientation ==
VERT)
517 else if (way ==
'p' && orientation ==
VERT)
525 DLOG(
"Next output is %s\n", next_output->
name);
528 Con *workspace = NULL;
553 if (con->
type == CT_FLOATING_CON) {
555 if (orientation ==
HORIZ) {
559 else next =
TAILQ_PREV(con, floating_head, floating_windows);
565 else next =
TAILQ_LAST(&(parent->floating_head), floating_head);
585 return _tree_next(parent, way, orientation, wrap);
591 DLOG(
"nothing to focus\n");
598 else next =
TAILQ_PREV(current, nodes_head, nodes);
605 if (
_tree_next(parent, way, orientation,
false))
614 else next =
TAILQ_LAST(&(parent->nodes_head), nodes_head);
651 Con *current, *child, *parent = con->
parent;
652 DLOG(
"Checking if I can flatten con = %p / %s\n", con, con->
name);
655 if (con->
type != CT_CON ||
656 parent->
layout == L_OUTPUT ||
662 if (child == NULL ||
TAILQ_NEXT(child, nodes) != NULL)
665 DLOG(
"child = %p, con = %p, parent = %p\n", child, con, parent);
675 DLOG(
"Alright, I have to flatten this situation now. Stay calm.\n");
679 DLOG(
"detaching...\n");
683 DLOG(
"detaching current=%p / %s\n", current, current->
name);
685 DLOG(
"re-attaching\n");
692 DLOG(
"attaching to focus list\n");
696 DLOG(
"re-attached all\n");
699 if (focus_next != NULL &&
701 DLOG(
"restoring focus to focus_next=%p\n", focus_next);
702 TAILQ_REMOVE(&(parent->focus_head), focus_next, focused);
704 DLOG(
"restored focus.\n");
708 DLOG(
"closing redundant cons\n");
722 while (current != NULL) {
729 while (current != NULL) {