diff --git a/lib/wibox/widget/base.lua b/lib/wibox/widget/base.lua index d2d3a056e..8006aca5b 100644 --- a/lib/wibox/widget/base.lua +++ b/lib/wibox/widget/base.lua @@ -51,6 +51,28 @@ function base.widget:set_opacity(o) end end +--- Set the widget's width +-- @tparam number|nil s The width that the widget has. `nil` means to apply the +-- default mechanism of calling the `:fit` method. A number overrides the result +-- from `:fit`. +function base.widget:set_width(s) + if s ~= self._forced_width then + self._forced_width = s + self:emit_signal("widget::layout_changed") + end +end + +--- Set the widget's height +-- @tparam number|nil s The height that the widget has. `nil` means to apply the +-- default mechanism of calling the `:fit` method. A number overrides the result +-- from `:fit`. +function base.widget:set_height(s) + if s ~= self._forced_height then + self._forced_height = s + self:emit_signal("widget::layout_changed") + end +end + -- }}} -- {{{ Caches @@ -141,6 +163,10 @@ 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 + -- Also sanitize the output. w = math.max(0, math.min(w, width)) h = math.max(0, math.min(h, height)) @@ -394,6 +420,10 @@ function base.make_widget(proxy, widget_name) -- Widget is fully opaque ret.opacity = 1 + -- Size is not restricted/forced + ret._forced_width = nil + ret._forced_height = nil + -- Make buttons work ret:connect_signal("button::press", function(...) return base.handle_button("press", ...)