From 7bf2f17a8a6781159e189e64934a11031ba8797d Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 28 Feb 2016 12:11:36 +0100 Subject: [PATCH] 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 --- lib/wibox/widget/base.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/wibox/widget/base.lua b/lib/wibox/widget/base.lua index c528ad1d..d347a43c 100644 --- a/lib/wibox/widget/base.lua +++ b/lib/wibox/widget/base.lua @@ -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))