Skip to content

Instantly share code, notes, and snippets.

@dzhu
Created January 20, 2017 19:26
Show Gist options
  • Save dzhu/1d0889ad1419eb2b971ca5eb6b57d493 to your computer and use it in GitHub Desktop.
Save dzhu/1d0889ad1419eb2b971ca5eb6b57d493 to your computer and use it in GitHub Desktop.
diff --git a/lib/awful/layout/suit/tile.lua b/lib/awful/layout/suit/tile.lua
index 9fa263ca..83f0e3cb 100644
--- a/lib/awful/layout/suit/tile.lua
+++ b/lib/awful/layout/suit/tile.lua
@@ -206,7 +206,8 @@ local function tile_group(gs, cls, wa, orientation, fact, group)
geom[x] = group.coord
geom[y] = coord
gs[cls[c]] = geom
- hints.width, hints.height = cls[c]:apply_size_hints(geom.width, geom.height)
+ hints.width, hints.height = cls[c]:apply_size_hints_with_border(geom.width, geom.height)
+
coord = coord + hints[height]
unused = unused - hints[height]
total_fact = total_fact - fact[i]
diff --git a/objects/client.c b/objects/client.c
index ec4ab424..9d98ffe9 100644
--- a/objects/client.c
+++ b/objects/client.c
@@ -1631,6 +1631,21 @@ client_apply_size_hints(client_t *c, area_t geometry)
return geometry;
}
+/** Apply size hints to the client's new geometry, accounting for the border
+ * size first (i.e., subtract the border size, call the no-border version, and
+ * add back the border size).
+ */
+static area_t
+client_apply_size_hints_with_border(client_t *c, area_t geometry)
+{
+ geometry.width -= 2 * c->border_width;
+ geometry.height -= 2 * c->border_width;
+ area_t h = client_apply_size_hints(c, geometry);
+ h.width += 2 * c->border_width;
+ h.height += 2 * c->border_width;
+ return h;
+}
+
static void
client_resize_do(client_t *c, area_t geometry)
{
@@ -2816,6 +2831,33 @@ luaA_client_apply_size_hints(lua_State *L)
return 2;
}
+/** Apply size hints to a size, with borders included.
+ *
+ * @param width Desired width of client, including borders
+ * @param height Desired height of client, including borders
+ * @return Actual width of client, including borders
+ * @return Actual height of client, including borders
+ * @function apply_size_hints_with_border
+ */
+static int
+luaA_client_apply_size_hints_with_border(lua_State *L)
+{
+ client_t *c = luaA_checkudata(L, 1, &client_class);
+ area_t geometry = c->geometry;
+ if(!client_isfixed(c))
+ {
+ geometry.width = ceil(luaA_checknumber_range(L, 2, MIN_X11_SIZE, MAX_X11_SIZE));
+ geometry.height = ceil(luaA_checknumber_range(L, 3, MIN_X11_SIZE, MAX_X11_SIZE));
+ }
+
+ if (c->size_hints_honor)
+ geometry = client_apply_size_hints_with_border(c, geometry);
+
+ lua_pushinteger(L, geometry.width);
+ lua_pushinteger(L, geometry.height);
+ return 2;
+}
+
static int
luaA_client_set_screen(lua_State *L, client_t *c)
{
@@ -3370,6 +3412,7 @@ client_class_setup(lua_State *L)
{ "isvisible", luaA_client_isvisible },
{ "geometry", luaA_client_geometry },
{ "apply_size_hints", luaA_client_apply_size_hints },
+ { "apply_size_hints_with_border", luaA_client_apply_size_hints_with_border },
{ "tags", luaA_client_tags },
{ "kill", luaA_client_kill },
{ "swap", luaA_client_swap },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment