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.
This commit is contained in:
Emmanuel Lepage Vallee 2021-07-05 15:25:57 -07:00
parent b4afd0206b
commit ab977b2358
1 changed files with 32 additions and 13 deletions

View File

@ -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, 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. --- Add a context to the arguments.
-- This function extend the argument table. The context is used by some -- 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 -- 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 end
-- Detect horizontal or vertical drawables -- Detect horizontal or vertical drawables
local geo = area_common(d) local geo = area_common(d)
local vertical = geo.width < geo.height local orientation = geo.width < geo.height and "vertical" or "horizontal"
-- Look into the `position` string to find the relevants sides to crop from -- Look into the `position` string to find the relevants sides to crop from
-- the workarea -- the workarea
@ -490,17 +514,12 @@ wibox_update_strut = function(d, position, args)
local m = get_decoration(args) local m = get_decoration(args)
if vertical then for _, v in ipairs(struts_orientation_to_sides[orientation]) do
for _, v in ipairs {"right", "left"} do if (not position) or position:match(v) then
if (not position) or position:match(v) then -- Add the "short" rectangle lenght then the above and below margins.
struts[v] = geo.width + m[v] struts[v] = geo[opposites[orientation_to_length[orientation]]]
end + m[v]
end + m[opposites[v]]
else
for _, v in ipairs {"top", "bottom"} do
if (not position) or position:match(v) then
struts[v] = geo.height + m[v]
end
end end
end end