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);
258 if (con->
type != CT_FLOATING_CON) {
266 DLOG(
"Container was floating, killing floating container\n");
268 DLOG(
"parent container killed\n");
269 if (con == focused) {
270 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);
289 DLOG(
"No next container, i will just exit now\n");
293 if (was_mapped || con == focused) {
294 if ((kill_window !=
DONT_KILL_WINDOW) || !dont_kill_parent || con == focused) {
295 DLOG(
"focusing %p / %s\n", next, next->
name);
296 if (next->
type == CT_DOCKAREA) {
300 if (!force_set_focus && con != focused)
301 DLOG(
"not changing focus, the container was not focused before\n");
306 DLOG(
"not focusing because we're not killing anybody\n");
309 DLOG(
"not focusing, was not mapped\n");
313 if (!dont_kill_parent)
314 CALL(parent, on_remove_child);
324 assert(focused != NULL);
325 if (focused->
type == CT_WORKSPACE) {
326 LOG(
"Cannot close workspace\n");
331 assert(focused->
type != CT_OUTPUT);
332 assert(focused->
type != CT_ROOT);
335 tree_close(focused, kill_window,
false,
false);
345 if (con->
type == CT_WORKSPACE) {
346 DLOG(
"Workspace, simply changing orientation to %d\n", orientation);
347 con->
layout = (orientation ==
HORIZ) ? L_SPLITH : L_SPLITV;
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");
368 DLOG(
"Splitting in orientation %d\n", orientation);
374 new->parent = parent;
375 new->
layout = (orientation ==
HORIZ) ? L_SPLITH : L_SPLITV;
394 focused->
type == CT_WORKSPACE) {
395 ELOG(
"'focus parent': Focus is already on the workspace, cannot go higher than that.\n");
409 if (next ==
TAILQ_END(&(focused->focus_head))) {
410 printf(
"cannot go down\n");
423 if (con->
type == CT_WORKSPACE) {
426 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
440 DLOG(
"-- BEGIN RENDERING --\n");
449 DLOG(
"-- END RENDERING --\n");
459 if (con->
type == CT_WORKSPACE) {
465 DLOG(
"Current output is %s\n", current_output->
name);
469 if (way ==
'n' && orientation ==
HORIZ)
471 else if (way ==
'p' && orientation ==
HORIZ)
473 else if (way ==
'n' && orientation ==
VERT)
475 else if (way ==
'p' && orientation ==
VERT)
483 DLOG(
"Next output is %s\n", next_output->
name);
486 Con *workspace = NULL;
504 if (con->
type == CT_FLOATING_CON) {
506 if (orientation ==
HORIZ) {
510 else next =
TAILQ_PREV(con, floating_head, floating_windows);
516 else next =
TAILQ_LAST(&(parent->floating_head), floating_head);
536 return _tree_next(parent, way, orientation, wrap);
542 DLOG(
"nothing to focus\n");
549 else next =
TAILQ_PREV(current, nodes_head, nodes);
556 if (
_tree_next(parent, way, orientation,
false))
565 else next =
TAILQ_LAST(&(parent->nodes_head), nodes_head);
602 Con *current, *child, *parent = con->
parent;
603 DLOG(
"Checking if I can flatten con = %p / %s\n", con, con->
name);
606 if (con->
type != CT_CON ||
607 parent->
layout == L_OUTPUT ||
613 if (child == NULL ||
TAILQ_NEXT(child, nodes) != NULL)
616 DLOG(
"child = %p, con = %p, parent = %p\n", child, con, parent);
626 DLOG(
"Alright, I have to flatten this situation now. Stay calm.\n");
630 DLOG(
"detaching...\n");
634 DLOG(
"detaching current=%p / %s\n", current, current->
name);
636 DLOG(
"re-attaching\n");
643 DLOG(
"attaching to focus list\n");
647 DLOG(
"re-attached all\n");
650 if (focus_next != NULL &&
652 DLOG(
"restoring focus to focus_next=%p\n", focus_next);
653 TAILQ_REMOVE(&(parent->focus_head), focus_next, focused);
655 DLOG(
"restored focus.\n");
659 DLOG(
"closing redundant cons\n");
673 while (current != NULL) {
680 while (current != NULL) {