diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2022-10-30 16:10:12 +0100 |
---|---|---|
committer | Michael Stapelberg <stapelberg@users.noreply.github.com> | 2022-11-01 17:55:46 +0100 |
commit | 9ac027234b517a9de64cfe165029ee64a5afc6af (patch) | |
tree | f76c5d1a65dec000dd4f54c655ed898256c42100 | |
parent | 2fbb36b95f2286f69685d2869fb7a488195eb183 (diff) | |
download | i3-9ac027234b517a9de64cfe165029ee64a5afc6af.tar.gz i3-9ac027234b517a9de64cfe165029ee64a5afc6af.zip |
refactor render_con() global parameter into should_inset_con()
This bundles the logic all in one place and thereby makes it a little easier to
understand.
-rw-r--r-- | include/render.h | 2 | ||||
-rw-r--r-- | src/commands.c | 2 | ||||
-rw-r--r-- | src/floating.c | 6 | ||||
-rw-r--r-- | src/manage.c | 4 | ||||
-rw-r--r-- | src/render.c | 42 | ||||
-rw-r--r-- | src/tree.c | 2 |
6 files changed, 35 insertions, 23 deletions
diff --git a/include/render.h b/include/render.h index 8500b71d..03751c01 100644 --- a/include/render.h +++ b/include/render.h @@ -40,7 +40,7 @@ typedef struct render_params { * updated in X11. * */ -void render_con(Con *con, bool already_inset); +void render_con(Con *con); /** * Returns the height for the decorations diff --git a/src/commands.c b/src/commands.c index 52c3fcd1..2d49a0d2 100644 --- a/src/commands.c +++ b/src/commands.c @@ -831,7 +831,7 @@ void cmd_append_layout(I3_CMD, const char *cpath) { // is not executed yet and will be batched with append_layout’s // needs_tree_render after the parser finished. We should check if that is // necessary at all. - render_con(croot, false); + render_con(croot); restore_open_placeholder_windows(parent); diff --git a/src/floating.c b/src/floating.c index 5eaf639c..992ca23c 100644 --- a/src/floating.c +++ b/src/floating.c @@ -415,7 +415,7 @@ bool floating_enable(Con *con, bool automatic) { DLOG("Corrected y = %d (deco_height = %d)\n", nc->rect.y, deco_height); /* render the cons to get initial window_rect correct */ - render_con(nc, true); + render_con(nc); if (set_focus) con_activate(con); @@ -580,7 +580,7 @@ DRAGGING_CB(drag_window_callback) { con->rect.x = old_rect->x + (new_x - event->root_x); con->rect.y = old_rect->y + (new_y - event->root_y); - render_con(con, true); + render_con(con); x_push_node(con); xcb_flush(conn); @@ -685,7 +685,7 @@ DRAGGING_CB(resize_window_callback) { con->rect.x = dest_x; con->rect.y = dest_y; - render_con(con, true); + render_con(con); x_push_changes(croot); } diff --git a/src/manage.c b/src/manage.c index 6125af34..a7de243e 100644 --- a/src/manage.c +++ b/src/manage.c @@ -591,13 +591,13 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki * workspace at all. However, just calling render_con() on the * workspace isn’t enough either — it needs the rect. */ ws->rect = ws->parent->rect; - render_con(ws, false); + render_con(ws); /* Disable setting focus, otherwise we’d move focus to an invisible * workspace, which we generally prevent (e.g. in * con_move_to_workspace). */ set_focus = false; } - render_con(croot, false); + render_con(croot); cwindow->managed_since = time(NULL); diff --git a/src/render.c b/src/render.c index 6de37e8e..949f62cf 100644 --- a/src/render.c +++ b/src/render.c @@ -41,7 +41,7 @@ int render_deco_height(void) { * updated in X11. * */ -void render_con(Con *con, bool already_inset) { +void render_con(Con *con) { render_params params = { .rect = con->rect, .x = con->rect.x, @@ -51,8 +51,7 @@ void render_con(Con *con, bool already_inset) { DLOG("Rendering node %p / %s / layout %d / children %d\n", con, con->name, con->layout, params.children); - bool should_inset = should_inset_con(con, params.children); - if (!already_inset && should_inset) { + if (should_inset_con(con, params.children)) { gaps_t gaps = calculate_effective_gaps(con); Rect inset = (Rect){ has_adjacent_container(con, D_LEFT) ? gaps.inner : gaps.left, @@ -111,7 +110,7 @@ void render_con(Con *con, bool already_inset) { if (fullscreen) { fullscreen->rect = params.rect; x_raise_con(fullscreen); - render_con(fullscreen, false); + render_con(fullscreen); /* Fullscreen containers are either global (underneath the CT_ROOT * container) or per-output (underneath the CT_CONTENT container). For * global fullscreen containers, we cannot abort rendering here yet, @@ -156,7 +155,7 @@ void render_con(Con *con, bool already_inset) { DLOG("child at (%d, %d) with (%d x %d)\n", child->rect.x, child->rect.y, child->rect.width, child->rect.height); x_raise_con(child); - render_con(child, should_inset || already_inset); + render_con(child); i++; } @@ -170,7 +169,7 @@ void render_con(Con *con, bool already_inset) { * that we have a non-leaf-container inside the stack. In that * case, the children of the non-leaf-container need to be * raised as well. */ - render_con(child, true); + render_con(child); } if (params.children != 1) @@ -219,7 +218,7 @@ static void render_root(Con *con, Con *fullscreen) { Con *output; if (!fullscreen) { TAILQ_FOREACH (output, &(con->nodes_head), nodes) { - render_con(output, false); + render_con(output); } } @@ -263,7 +262,7 @@ static void render_root(Con *con, Con *fullscreen) { DLOG("floating child at (%d,%d) with %d x %d\n", child->rect.x, child->rect.y, child->rect.width, child->rect.height); x_raise_con(child); - render_con(child, true); + render_con(child); } } } @@ -313,7 +312,7 @@ static void render_output(Con *con) { if (fullscreen) { fullscreen->rect = con->rect; x_raise_con(fullscreen); - render_con(fullscreen, false); + render_con(fullscreen); return; } @@ -354,7 +353,7 @@ static void render_output(Con *con) { DLOG("child at (%d, %d) with (%d x %d)\n", child->rect.x, child->rect.y, child->rect.width, child->rect.height); x_raise_con(child); - render_con(child, child->type == CT_DOCKAREA); + render_con(child); } } @@ -461,14 +460,27 @@ static void render_con_dockarea(Con *con, Con *child, render_params *p) { * Decides whether the container should be inset. */ bool should_inset_con(Con *con, int children) { - /* Don't inset floating containers and workspaces. */ - if (con->type == CT_FLOATING_CON || con->type == CT_WORKSPACE) - return false; + /* Inset direct children of the workspace that are leaf containers or + stacked/tabbed containers. */ + if (con->parent != NULL && + con->parent->type == CT_WORKSPACE && + (con_is_leaf(con) || + (con->layout == L_STACKED || con->layout == L_TABBED))) { + return true; + } - if (con_is_leaf(con)) + /* Inset direct children of vertical or horizontal split containers at any + depth in the tree (only leaf containers, not split containers within + split containers, to avoid double insets). */ + if (con_is_leaf(con) && + con->parent != NULL && + con->parent->type == CT_CON && + (con->parent->layout == L_SPLITH || + con->parent->layout == L_SPLITV)) { return true; + } - return (con->layout == L_STACKED || con->layout == L_TABBED) && children > 0; + return false; } /* @@ -458,7 +458,7 @@ void tree_render(void) { mark_unmapped(croot); croot->mapped = true; - render_con(croot, false); + render_con(croot); x_push_changes(croot); DLOG("-- END RENDERING --\n"); |