gears.wallpaper: Only finish own surfaces
If the caller provides a file name, these function load the image, set it as the wallpaper and make sure that the memory used for the image data is freed immediately. However, this was also done when the caller provided a cairo surface, thus breaking their surface. Fix the code so that it does not finish surfaces that it did not create itself. Fixes: https://github.com/awesomeWM/awesome/issues/1570 Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
17fe135a9f
commit
4fc396ec57
|
@ -111,6 +111,7 @@ end
|
|||
-- @see gears.color
|
||||
function wallpaper.centered(surf, s, background)
|
||||
local geom, cr = wallpaper.prepare_context(s)
|
||||
local original_surf = surf
|
||||
surf = surface.load_uncached(surf)
|
||||
background = color(background)
|
||||
|
||||
|
@ -126,7 +127,9 @@ function wallpaper.centered(surf, s, background)
|
|||
cr:clip()
|
||||
cr:set_source_surface(surf, 0, 0)
|
||||
cr:paint()
|
||||
surf:finish()
|
||||
if surf ~= original_surf then
|
||||
surf:finish()
|
||||
end
|
||||
end
|
||||
|
||||
--- Set a tiled wallpaper.
|
||||
|
@ -141,13 +144,16 @@ function wallpaper.tiled(surf, s, offset)
|
|||
cr:translate(offset.x, offset.y)
|
||||
end
|
||||
|
||||
local original_surf = surf
|
||||
surf = surface.load_uncached(surf)
|
||||
local pattern = cairo.Pattern.create_for_surface(surf)
|
||||
pattern.extend = cairo.Extend.REPEAT
|
||||
cr.source = pattern
|
||||
cr.operator = cairo.Operator.SOURCE
|
||||
cr:paint()
|
||||
surf:finish()
|
||||
if surf ~= original_surf then
|
||||
surf:finish()
|
||||
end
|
||||
end
|
||||
|
||||
--- Set a maximized wallpaper.
|
||||
|
@ -159,6 +165,7 @@ end
|
|||
-- @param offset This can be set to a table with entries x and y.
|
||||
function wallpaper.maximized(surf, s, ignore_aspect, offset)
|
||||
local geom, cr = wallpaper.prepare_context(s)
|
||||
local original_surf = surf
|
||||
surf = surface.load_uncached(surf)
|
||||
local w, h = surface.get_size(surf)
|
||||
local aspect_w = geom.width / w
|
||||
|
@ -181,7 +188,9 @@ function wallpaper.maximized(surf, s, ignore_aspect, offset)
|
|||
cr:set_source_surface(surf, 0, 0)
|
||||
cr.operator = cairo.Operator.SOURCE
|
||||
cr:paint()
|
||||
surf:finish()
|
||||
if surf ~= original_surf then
|
||||
surf:finish()
|
||||
end
|
||||
end
|
||||
|
||||
--- Set a fitting wallpaper.
|
||||
|
@ -193,6 +202,7 @@ end
|
|||
-- @see gears.color
|
||||
function wallpaper.fit(surf, s, background)
|
||||
local geom, cr = wallpaper.prepare_context(s)
|
||||
local original_surf = surf
|
||||
surf = surface.load_uncached(surf)
|
||||
background = color(background)
|
||||
|
||||
|
@ -213,7 +223,9 @@ function wallpaper.fit(surf, s, background)
|
|||
cr:scale(scale, scale)
|
||||
cr:set_source_surface(surf, 0, 0)
|
||||
cr:paint()
|
||||
surf:finish()
|
||||
if surf ~= original_surf then
|
||||
surf:finish()
|
||||
end
|
||||
end
|
||||
|
||||
return wallpaper
|
||||
|
|
Loading…
Reference in New Issue