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);
88 DLOG(
"appended tree, using new root\n");
90 DLOG(
"new root = %p\n", croot);
92 DLOG(
"out = %p\n", out);
94 DLOG(
"ws = %p\n", ws);
98 if (strcmp(out->
name,
"__i3") != 0) {
99 DLOG(
"Adding pseudo-output __i3 during inplace restart\n");
118 croot->
name =
"root";
119 croot->
type = CT_ROOT;
147 if (con->
type == CT_FLOATING_CON) {
149 if (con->
type != CT_WORKSPACE)
152 DLOG(
"con = %p\n", con);
191 bool was_mapped = con->
mapped;
210 DLOG(
"next = %p, focused = %p\n", next, focused);
212 DLOG(
"closing %p, kill_window = %d\n", con, kill_window);
213 Con *child, *nextchild;
214 bool abort_kill =
false;
217 for (child =
TAILQ_FIRST(&(con->nodes_head)); child;) {
219 DLOG(
"killing child=%p\n", child);
220 if (!
tree_close(child, kill_window,
true,
false))
226 DLOG(
"One of the children could not be killed immediately (WM_DELETE sent), aborting.\n");
230 if (con->
window != NULL) {
235 xcb_void_cookie_t cookie;
240 XCB_CW_EVENT_MASK, (uint32_t[]) {XCB_NONE});
251 cookie = xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
252 con->
window->
id, A_WM_STATE, A_WM_STATE, 32, 2, data);
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);
273 dont_kill_parent =
true;
274 DLOG(
"Alright, focusing %p\n", next);
284 if (con->urgency_timer != NULL) {
285 DLOG(
"Removing urgency timer of con %p\n", con);
287 ev_timer_stop(
main_loop, con->urgency_timer);
288 FREE(con->urgency_timer);
291 if (con->type != CT_FLOATING_CON) {
305 if (!dont_kill_parent)
312 DLOG(
"Container was floating, killing floating container\n");
314 DLOG(
"parent container killed\n");
318 FREE(con->deco_render_params);
325 DLOG(
"No next container, i will just exit now\n");
329 if (was_mapped || con == focused) {
330 if ((kill_window !=
DONT_KILL_WINDOW) || !dont_kill_parent || con == focused) {
331 DLOG(
"focusing %p / %s\n", next, next->name);
332 if (next->type == CT_DOCKAREA) {
336 if (!force_set_focus && con != focused)
337 DLOG(
"not changing focus, the container was not focused before\n");
342 DLOG(
"not focusing because we're not killing anybody\n");
345 DLOG(
"not focusing, was not mapped\n");
349 if (!dont_kill_parent)
350 CALL(parent, on_remove_child);
360 assert(focused != NULL);
363 assert(focused->
type != CT_OUTPUT);
364 assert(focused->
type != CT_ROOT);
366 if (focused->
type == CT_WORKSPACE) {
367 DLOG(
"Workspaces cannot be close, closing all children instead\n");
368 Con *child, *nextchild;
369 for (child =
TAILQ_FIRST(&(focused->focus_head)); child;) {
371 DLOG(
"killing child=%p\n", child);
380 tree_close(focused, kill_window,
false,
false);
390 DLOG(
"Floating containers can't be split.\n");
394 if (con->
type == CT_WORKSPACE) {
396 DLOG(
"Just changing orientation of workspace\n");
419 DLOG(
"Just changing orientation of existing container\n");
423 DLOG(
"Splitting in orientation %d\n", orientation);
429 new->parent = parent;
447 if (focused->
parent->
type == CT_FLOATING_CON) {
455 focused->
type == CT_WORKSPACE) {
456 ELOG(
"'focus parent': Focus is already on the workspace, cannot go higher than that.\n");
470 if (next ==
TAILQ_END(&(focused->focus_head))) {
471 DLOG(
"cannot go down\n");
473 }
else if (next->
type == CT_FLOATING_CON) {
477 if (child ==
TAILQ_END(&(next->focus_head))) {
478 DLOG(
"cannot go down\n");
494 if (con->
type == CT_WORKSPACE) {
497 TAILQ_FOREACH (current, &(con->floating_head), floating_windows)
511 DLOG(
"-- BEGIN RENDERING --\n");
520 DLOG(
"-- END RENDERING --\n");
537 if (con->
type == CT_WORKSPACE) {
539 DLOG(
"Cannot change workspace while in global fullscreen mode.\n");
547 DLOG(
"Current output is %s\n", current_output->
name);
551 if (way ==
'n' && orientation ==
HORIZ)
553 else if (way ==
'p' && orientation ==
HORIZ)
555 else if (way ==
'n' && orientation ==
VERT)
557 else if (way ==
'p' && orientation ==
VERT)
565 DLOG(
"Next output is %s\n", next_output->
name);
568 Con *workspace = NULL;
593 if (con->
type == CT_FLOATING_CON) {
595 if (orientation ==
HORIZ) {
600 next =
TAILQ_PREV(con, floating_head, floating_windows);
607 next =
TAILQ_LAST(&(parent->floating_head), floating_head);
627 return _tree_next(parent, way, orientation, wrap);
633 DLOG(
"nothing to focus\n");
641 next =
TAILQ_PREV(current, nodes_head, nodes);
648 if (
_tree_next(parent, way, orientation,
false))
658 next =
TAILQ_LAST(&(parent->nodes_head), nodes_head);
695 Con *current, *child, *parent = con->
parent;
696 DLOG(
"Checking if I can flatten con = %p / %s\n", con, con->
name);
699 if (con->
type != CT_CON ||
706 if (child == NULL ||
TAILQ_NEXT(child, nodes) != NULL)
709 DLOG(
"child = %p, con = %p, parent = %p\n", child, con, parent);
721 DLOG(
"Alright, I have to flatten this situation now. Stay calm.\n");
725 DLOG(
"detaching...\n");
729 DLOG(
"detaching current=%p / %s\n", current, current->
name);
731 DLOG(
"re-attaching\n");
738 DLOG(
"attaching to focus list\n");
742 DLOG(
"re-attached all\n");
745 if (focus_next != NULL &&
747 DLOG(
"restoring focus to focus_next=%p\n", focus_next);
748 TAILQ_REMOVE(&(parent->focus_head), focus_next, focused);
750 DLOG(
"restored focus.\n");
754 DLOG(
"closing redundant cons\n");
768 while (current != NULL) {
775 while (current != NULL) {
void tree_next(char way, orientation_t orientation)
Changes focus in the given way (next/previous) and given orientation (horizontal/vertical).
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
static bool _is_con_mapped(Con *con)
char * name
Name of the output.
bool con_is_floating(Con *con)
Returns true if the node is floating.
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
#define TAILQ_REMOVE(head, elm, field)
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Con * workspace_encapsulate(Con *ws)
Creates a new container and re-parents all of children from the given workspace into it...
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.
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
void con_detach(Con *con)
Detaches the given container from its current parent.
#define TAILQ_LAST(head, headname)
void workspace_show(Con *workspace)
Switches to the given workspace.
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
struct all_cons_head all_cons
#define TAILQ_REPLACE(head, elm, elm2, field)
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
Con * con_descend_tiling_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
struct ev_loop * main_loop
#define TAILQ_FIRST(head)
bool level_up(void)
Moves focus one level up.
void x_window_kill(xcb_window_t window, kill_window_t kill_window)
Kills the given X11 window using WM_DELETE_WINDOW (if supported).
An Output is a physical output on your graphics driver.
#define TAILQ_NEXT(elm, field)
Con * con_new(Con *parent, i3Window *window)
void tree_append_json(Con *con, const char *filename, char **errormsg)
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
Con * con_descend_direction(Con *con, direction_t direction)
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
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 ...
Con * con_next_focused(Con *con)
Returns the container which will be focused next when the given container is not available anymore...
void tree_split(Con *con, orientation_t orientation)
Splits (horizontally or vertically) the given container by creating a new container which contains th...
#define XCB_ICCCM_WM_STATE_WITHDRAWN
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
bool tree_close(Con *con, kill_window_t kill_window, bool dont_kill_parent, bool force_set_focus)
Closes the given container including all children.
bool tree_restore(const char *path, xcb_get_geometry_reply_t *geometry)
Loads tree from ~/.i3/_restart.json (used for in-place restarts).
struct deco_render_params * deco_render_params
Cache for the decoration rendering.
#define TAILQ_INSERT_HEAD(head, elm, field)
Con * con
Pointer to the Con which represents this output.
void x_push_changes(Con *con)
Pushes all changes (state of each node, see x_push_node() and the window stack) to X11...
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
fullscreen_mode_t fullscreen_mode
bool level_down(void)
Moves focus one level down.
bool con_fullscreen_permits_focusing(Con *con)
Returns true if changing the focus to con would be allowed considering the fullscreen focus constrain...
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...
void con_focus(Con *con)
Sets input focus to the given container.
void add_ignore_event(const int sequence, const int response_type)
Adds the given sequence to the list of events which are ignored.
#define TAILQ_EMPTY(head)
int con_num_children(Con *con)
Returns the number of children of this container.
void workspace_update_urgent_flag(Con *ws)
Goes through all clients on the given workspace and updates the workspace’s urgent flag accordingly...
void tree_flatten(Con *con)
tree_flatten() removes pairs of redundant split containers, e.g.
void i3string_free(i3String *str)
Free an i3String.
char * resolve_tilde(const char *path)
This function resolves ~ in pathnames.
bool con_is_split(Con *con)
#define TAILQ_PREV(elm, headname, field)
bool force_focus_wrapping
Think of the following layout: Horizontal workspace with a tabbed con on the left of the screen and a...
#define GREP_FIRST(dest, head, condition)
orientation_t con_orientation(Con *con)
Returns the orientation of the given container (for stacked containers, vertical orientation is used ...
A 'Con' represents everything from the X11 root window down to a single X11 window.
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...
#define CALL(obj, member,...)
#define TAILQ_INSERT_TAIL(head, elm, field)
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...
#define TAILQ_HEAD_INITIALIZER(head)
static void mark_unmapped(Con *con)
bool path_exists(const char *path)
Checks if the given path exists by calling stat().
Con * output_get_content(Con *output)
Returns the output container below the given output container.
i3String * name
The name of the window.
#define TAILQ_FOREACH(var, head, field)
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
void tree_close_con(kill_window_t kill_window)
Closes the current container using tree_close().
Assignment ** ran_assignments
static bool _tree_next(Con *con, char way, orientation_t orientation, bool wrap)
void x_con_kill(Con *con)
Kills the window decoration associated with the given container.
void render_con(Con *con, bool render_fullscreen)
"Renders" the given container (and its children), meaning that all rects are updated correctly...
kill_window_t
parameter to specify whether tree_close() and x_window_kill() should kill only this specific window o...
static Con * _create___i3(void)