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:
Uli Schlachter 2014-03-23 17:48:26 +01:00
parent 0ac80ddf30
commit db00145406
1 changed files with 6 additions and 0 deletions

View File

@ -32,6 +32,12 @@ end
-- @param height The available height for the widget
-- @return The width and height that the widget wants to use
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 result = cache[width]
if not result then