[i3] [PATCH 5/5] Added window insets (similar to herbstluftwm)

  • From: Kevin Murphy <kemurphy.cmu@xxxxxxxxx>
  • To: i3-discuss@xxxxxxxxxxxxx
  • Date: Sun, 18 Nov 2012 05:56:55 -0500

From: Kevin Murphy <kemurphy@xxxxxxxxxxxxxx>

---
include/render.h | 2 +-
src/floating.c | 6 +++---
src/manage.c | 2 +-
src/randr.c | 2 +-
src/render.c | 35 +++++++++++++++++++++++++++--------
src/tree.c | 2 +-
6 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/include/render.h b/include/render.h
index 0a5949f..d458bd3 100644
--- a/include/render.h
+++ b/include/render.h
@@ -19,6 +19,6 @@
* updated in X11.
*
*/
-void render_con(Con *con, bool render_fullscreen);
+void render_con(Con *con, bool render_fullscreen, bool already_inset);

#endif
diff --git a/src/floating.c b/src/floating.c
index b884a18..7347fcc 100644
--- a/src/floating.c
+++ b/src/floating.c
@@ -251,8 +251,8 @@ void floating_enable(Con *con, bool automatic) {
TAILQ_INSERT_TAIL(&(nc->focus_head), con, focused);

/* render the cons to get initial window_rect correct */
- render_con(nc, false);
- render_con(con, false);
+ render_con(nc, false, true);
+ render_con(con, false, true);

if (set_focus)
con_focus(con);
@@ -376,7 +376,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, false);
+ render_con(con, false, true);
x_push_node(con);
xcb_flush(conn);

diff --git a/src/manage.c b/src/manage.c
index 10aa3a8..24290be 100644
--- a/src/manage.c
+++ b/src/manage.c
@@ -415,7 +415,7 @@ 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, true);
+ render_con(ws, true, false);
}
tree_render();

diff --git a/src/randr.c b/src/randr.c
index 267d6e4..9b22788 100644
--- a/src/randr.c
+++ b/src/randr.c
@@ -351,7 +351,7 @@ void init_ws_for_output(Output *output, Con *content) {
* Then, we need to work with the "content" container, since we cannot
* be sure that the workspace itself was rendered at all (in case it’s
* invisible, it won’t be rendered). */
- render_con(workspace_out, false);
+ render_con(workspace_out, false, true);
Con *ws_out_content = output_get_content(workspace_out);

Con *floating_con;
diff --git a/src/render.c b/src/render.c
index 1216241..63a9deb 100644
--- a/src/render.c
+++ b/src/render.c
@@ -54,7 +54,7 @@ static void render_l_output(Con *con) {
if (fullscreen) {
fullscreen->rect = con->rect;
x_raise_con(fullscreen);
- render_con(fullscreen, true);
+ render_con(fullscreen, true, false);
return;
}

@@ -94,7 +94,7 @@ static void render_l_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, false);
+ render_con(child, false, child->type == CT_DOCKAREA);
}
}

@@ -106,7 +106,7 @@ static void render_l_output(Con *con) {
* updated in X11.
*
*/
-void render_con(Con *con, bool render_fullscreen) {
+void render_con(Con *con, bool render_fullscreen, bool already_inset) {
int children = con_num_children(con);
DLOG("Rendering %snode %p / %s / layout %d / children %d\n",
(render_fullscreen ? "fullscreen " : ""), con, con->name, con->layout,
@@ -124,6 +124,25 @@ void render_con(Con *con, bool render_fullscreen) {
rect.width -= 2 * 2;
rect.height -= 2 * 2;
}
+
+ bool should_inset = ((con_is_leaf(con) ||
+ (children > 0 &&
+ (con->layout == L_STACKED ||
+ con->layout == L_TABBED))) &&
+ con->type != CT_FLOATING_CON &&
+ con->type != CT_WORKSPACE);
+ if ((!already_inset && should_inset)) {
+ Rect inset = (Rect) {4, 4, 4 * -2, 4 * -2};
+ rect = rect_add(rect, inset);
+ if (!render_fullscreen) {
+ con->rect = rect_add(con->rect, inset);
+ if (con->window) {
+ con->window_rect = rect_add(con->window_rect, inset);
+ }
+ }
+ inset.height = 0;
+ con->deco_rect = rect_add(con->deco_rect, inset);
+ }

int x = rect.x;
int y = rect.y;
@@ -191,7 +210,7 @@ void render_con(Con *con, bool render_fullscreen) {
if (fullscreen) {
fullscreen->rect = rect;
x_raise_con(fullscreen);
- render_con(fullscreen, true);
+ render_con(fullscreen, true, false);
return;
}

@@ -231,7 +250,7 @@ void render_con(Con *con, bool render_fullscreen) {
} else if (con->type == CT_ROOT) {
Con *output;
TAILQ_FOREACH(output, &(con->nodes_head), nodes) {
- render_con(output, false);
+ render_con(output, false, false);
}

/* We need to render floating windows after rendering all outputs’
@@ -269,7 +288,7 @@ void render_con(Con *con, bool render_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, false);
+ render_con(child, false, true);
}
}

@@ -365,7 +384,7 @@ void render_con(Con *con, bool render_fullscreen) {
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, false);
+ render_con(child, false, should_inset || already_inset);
i++;
}

@@ -378,7 +397,7 @@ void render_con(Con *con, bool render_fullscreen) {
* that we have a non-leaf-container inside the stack. In that
* case, the children of the non-leaf-container need to be raised
* aswell. */
- render_con(child, false);
+ render_con(child, false, true);
}

if (children != 1)
diff --git a/src/tree.c b/src/tree.c
index 7a5fb9f..12d3b9d 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -474,7 +474,7 @@ void tree_render(void) {
mark_unmapped(croot);
croot->mapped = true;

- render_con(croot, false);
+ render_con(croot, false, false);

x_push_changes(croot);
DLOG("-- END RENDERING --\n");
--
1.8.0


Other related posts:

  • » [i3] [PATCH 5/5] Added window insets (similar to herbstluftwm) - Kevin Murphy