From 8bcdd0b79492e80e76680151fa7cde5ed723e745 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 21 Dec 2018 21:09:24 -0500 Subject: [PATCH] placement: Add some extra checks to limit the risk of regressions. Given noone understand this code, this will prevent some semi likely regressions from going unnoticed. The main risk is the shims not producing the exact same results as the real implementation and cause different code paths to be taken. As of this commit, both the "real" and "shim" implementation were given the same set of tests with print() at every step of next_to. The resulting log was then checksummed to ensure both are identical. --- lib/awful/placement.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index 57cc3ed7..578280fb 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -717,6 +717,10 @@ local function get_relative_regions(geo, mode, is_absolute) dgeo = geo.drawable.get_wibox():geometry() elseif geo.drawable and geo.drawable.drawable then bw, dgeo = 0, geo.drawable.drawable:geometry() + else + -- The placement isn't done on an object at all, having no border is + -- normal. + assert(mode == "geometry") end -- Add the infamous border size @@ -1392,6 +1396,7 @@ function placement.next_to(d, args) args = add_context(args, "next_to") d = d or capi.client.focus + local osize = type(d.geometry) == "function" and d:geometry() or nil local original_pos, original_anchors = args.preferred_positions, args.preferred_anchors if type(original_pos) == "string" then @@ -1492,7 +1497,14 @@ function placement.next_to(d, args) attach(d, placement.next_to, args) - return fix_new_geometry(ngeo, args, true), pref_name, dir + local ret = fix_new_geometry(ngeo, args, true) + + -- Make sure the geometry didn't change, it would indicate an + -- "off by border" issue. + assert((not osize.width) or ret.width == d.width) + assert((not osize.height) or ret.height == d.height) + + return ret, pref_name, dir end --- Restore the geometry.