Make gears.widget.{fit,layout}_widget more robust

This commit makes these methods invoke the method on a widget in a protected
context. Thanks to this, e.g. the wibox and other widgets are protected from
errors in a child widget.

Additionally, fit_widget() now assumes 0 if a widget's :fit() method didn't
provide a number.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-28 12:11:36 +01:00
parent 01f11003d6
commit 7bf2f17a8a
1 changed files with 5 additions and 4 deletions

View File

@ -8,6 +8,7 @@
local object = require("gears.object")
local cache = require("gears.cache")
local matrix = require("gears.matrix")
local protected_call = require("gears.protected_call")
local util = require("awful.util")
local setmetatable = setmetatable
local pairs = pairs
@ -144,7 +145,7 @@ local widget_dependencies = setmetatable({}, { __mode = "kv" })
local function get_cache(widget, kind)
if not widget._widget_caches[kind] then
widget._widget_caches[kind] = cache.new(function(...)
return widget[kind](widget, ...)
return protected_call(widget[kind], widget, ...)
end)
end
return widget._widget_caches[kind]
@ -222,9 +223,9 @@ function base.fit_widget(parent, context, widget, width, height)
end
end
-- Apply forced size
w = widget._forced_width or w
h = widget._forced_height or h
-- Apply forced size and handle nil's
w = widget._forced_width or w or 0
h = widget._forced_height or h or 0
-- Also sanitize the output.
w = math.max(0, math.min(w, width))