wibox.layout.base.fit_widget: Enforce sane width and height
Previously, odd things could happen if a widget was getting fitted into a negative width or, even worse, width being NaN (not a number)! This can e.g. happen due to a margin layout which doesn't get enough space to even draw the margin that it is supposed to add. Fix this by enforcing a minimum value of 0 for the width and height that a widget gets fitted into. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
8003156e62
commit
7e21f85c3c
|
@ -32,6 +32,12 @@ end
|
||||||
-- @param height The available height for the widget
|
-- @param height The available height for the widget
|
||||||
-- @return The width and height that the widget wants to use
|
-- @return The width and height that the widget wants to use
|
||||||
function base.fit_widget(widget, width, height)
|
function base.fit_widget(widget, width, height)
|
||||||
|
-- Sanitize the input. This also filters out e.g. NaN.
|
||||||
|
local width = math.max(0, width)
|
||||||
|
local height = math.max(0, height)
|
||||||
|
|
||||||
|
-- Since the geometry cache is a weak table, we have to be careful when
|
||||||
|
-- doing lookups. We can't do "if cache[width] ~= nil then"!
|
||||||
local cache = widget._fit_geometry_cache
|
local cache = widget._fit_geometry_cache
|
||||||
local result = cache[width]
|
local result = cache[width]
|
||||||
if not result then
|
if not result then
|
||||||
|
|
Loading…
Reference in New Issue