Merge pull request #994 from psychon/fix-drawable-bgimage
Fix drawable bgimage
This commit is contained in:
commit
25b6d31e97
|
@ -123,8 +123,11 @@ local function do_redraw(self)
|
|||
cr:set_source(self.background_color)
|
||||
cr:paint()
|
||||
|
||||
cr:restore()
|
||||
|
||||
-- Paint the background image
|
||||
if self.background_image then
|
||||
cr:save()
|
||||
if type(self.background_image) == "function" then
|
||||
self.background_image(context, cr, width, height, unpack(self.background_image_args))
|
||||
else
|
||||
|
@ -132,9 +135,8 @@ local function do_redraw(self)
|
|||
cr:set_source(pattern)
|
||||
cr:paint()
|
||||
end
|
||||
end
|
||||
|
||||
cr:restore()
|
||||
end
|
||||
|
||||
-- Draw the widget
|
||||
if self._widget_hierarchy then
|
||||
|
@ -237,6 +239,9 @@ end
|
|||
-- as arguments. Any other arguments passed to this method will be appended.
|
||||
-- @param image A background image or a function
|
||||
function drawable:set_bgimage(image, ...)
|
||||
if type(image) ~= "function" then
|
||||
image = surface(image)
|
||||
end
|
||||
|
||||
self.background_image = image
|
||||
self.background_image_args = {...}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
local runner = require("_runner")
|
||||
local wibox = require("wibox")
|
||||
local beautiful = require("beautiful")
|
||||
local cairo = require("lgi").cairo
|
||||
|
||||
local w = wibox {
|
||||
x = 10,
|
||||
y = 10,
|
||||
width = 20,
|
||||
height = 20,
|
||||
visible = true,
|
||||
bg = "#ff0000",
|
||||
}
|
||||
|
||||
local callback_called
|
||||
local function callback(context, cr, width, height, arg)
|
||||
assert(type(context) == "table", type(context))
|
||||
assert(type(context.dpi) == "number", context.dpi)
|
||||
assert(cairo.Context:is_type_of(cr), cr)
|
||||
assert(width == 20, width)
|
||||
assert(height == 20, height)
|
||||
assert(arg == "argument: 42", arg)
|
||||
|
||||
callback_called = true
|
||||
end
|
||||
|
||||
runner.run_steps({
|
||||
-- Set some bg image
|
||||
function()
|
||||
local img = assert(beautiful.titlebar_close_button_normal)
|
||||
w:set_bgimage(img)
|
||||
return true
|
||||
end,
|
||||
|
||||
-- Do nothing for a while iteration to give the repaint some time to happen
|
||||
function(arg)
|
||||
if arg == 3 then
|
||||
return true
|
||||
end
|
||||
end,
|
||||
|
||||
-- Set some bg image function
|
||||
function()
|
||||
w:set_bgimage(callback, "argument: 42")
|
||||
return true
|
||||
end,
|
||||
|
||||
-- Wait for the function to be done
|
||||
function()
|
||||
if callback_called then
|
||||
return true
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
Loading…
Reference in New Issue