widget.background: Allow function as background image
There is already a hack into `awful.widget.common`. This system aim to make the hack obselete while preserving the useful part. I think this is also necessary to properly support SVG (with DPI and resize). Finally, Qt handle this using the QBrush concept, where you can have programmatic patterns. Cairo doesn't have this concept, so there is no "clean" way to have programmatic brushes.
This commit is contained in:
parent
720768330c
commit
cbea82f1c8
|
@ -43,10 +43,14 @@ function background:draw(context, cr, width, height)
|
|||
cr:paint()
|
||||
end
|
||||
if self.bgimage then
|
||||
if type(self.bgimage) == "function" then
|
||||
self.bgimage(context, cr, width, height,unpack(self.bgimage_args))
|
||||
else
|
||||
local pattern = cairo.Pattern.create_for_surface(self.bgimage)
|
||||
cr:set_source(pattern)
|
||||
cr:paint()
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -145,8 +149,12 @@ function background:set_shape_border_color(fg)
|
|||
end
|
||||
|
||||
--- Set the background image to use
|
||||
function background:set_bgimage(image)
|
||||
self.bgimage = surface.load(image)
|
||||
-- If `image` is a function, it will be called with `(context, cr, width, height)`
|
||||
-- as arguments. Any other arguments passed to this method will be appended.
|
||||
-- @param image A background image or a function
|
||||
function background:set_bgimage(image, ...)
|
||||
self.bgimage = type(image) == "function" and image or surface.load(image)
|
||||
self.bgimage_args = {...}
|
||||
self:emit_signal("widget::redraw_needed")
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue