From ab977b2358913fe6ce08b4e0be9836d9ca161341 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 5 Jul 2021 15:25:57 -0700 Subject: [PATCH] placement: Fix the struts size when margins are present. Previously, it only added 1 of the 2 sides of the relevant margins to the struct size. For example, if the position was "top", then only the top margin was added, not the bottom one. --- lib/awful/placement.lua | 45 +++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index 32ebd8463..e12add91c 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -280,6 +280,30 @@ local outer_positions = { bottom_middle = function(r, w, _) return {x=r.x-w/2+r.width/2, y=r.y }, "middle" end, } +-- Map the opposite side for a string +local opposites = { + top = "bottom", + bottom = "top", + left = "right", + right = "left", + width = "height", + height = "width", + x = "y", + y = "x", +} + +-- List reletvant sides for each orientation. +local struts_orientation_to_sides = { + horizontal = { "top" , "bottom" }, + vertical = { "left", "right" } +} + +-- Map orientation to the length components (width/height). +local orientation_to_length = { + horizontal = "width", + vertical = "height" +} + --- Add a context to the arguments. -- This function extend the argument table. The context is used by some -- internal helper methods. If there already is a context, it has priority and @@ -481,8 +505,8 @@ wibox_update_strut = function(d, position, args) end -- Detect horizontal or vertical drawables - local geo = area_common(d) - local vertical = geo.width < geo.height + local geo = area_common(d) + local orientation = geo.width < geo.height and "vertical" or "horizontal" -- Look into the `position` string to find the relevants sides to crop from -- the workarea @@ -490,17 +514,12 @@ wibox_update_strut = function(d, position, args) local m = get_decoration(args) - if vertical then - for _, v in ipairs {"right", "left"} do - if (not position) or position:match(v) then - struts[v] = geo.width + m[v] - end - end - else - for _, v in ipairs {"top", "bottom"} do - if (not position) or position:match(v) then - struts[v] = geo.height + m[v] - end + for _, v in ipairs(struts_orientation_to_sides[orientation]) do + if (not position) or position:match(v) then + -- Add the "short" rectangle lenght then the above and below margins. + struts[v] = geo[opposites[orientation_to_length[orientation]]] + + m[v] + + m[opposites[v]] end end