Add "opacity" property for widgets

This commit is contained in:
kindlycat 2015-08-12 22:31:06 +00:00
parent 9cbab8fa08
commit 03663fe778
3 changed files with 15 additions and 0 deletions

View File

@ -59,7 +59,10 @@ local function do_redraw(self)
self._widget_geometries = {}
if self.widget and self.widget.visible then
cr:set_source(self.foreground_color)
cr:push_group()
self.widget:draw(self.widget_arg, cr, width, height)
cr:pop_group_to_source()
cr:paint_with_alpha(self.widget.opacity)
self:widget_at(self.widget, 0, 0, width, height)
end

View File

@ -66,11 +66,14 @@ function base.draw_widget(wibox, cr, widget, x, y, width, height)
cr:rectangle(0, 0, width, height)
cr:clip()
cr:push_group()
-- Let the widget draw itself
local success, msg = pcall(widget.draw, widget, wibox, cr, width, height)
if not success then
print("Error while drawing widget: " .. msg)
end
cr:pop_group_to_source()
cr:paint_with_alpha(widget.opacity)
-- Register the widget for input handling
wibox:widget_at(widget, base.rect_to_device_geometry(cr, 0, 0, width, height))

View File

@ -116,6 +116,15 @@ function base.make_widget(proxy, widget_name)
end
end
-- Add opacity property and setter.
ret.opacity = 1
function ret:set_opacity(b)
if b ~= self.opacity then
self.opacity = b
self:emit_signal("widget::updated")
end
end
-- Add __tostring method to metatable.
ret.widget_name = widget_name or object.modulename(3)
local mt = {}