From 4fc396ec579881da20e73fd1ed699df8c1353c18 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 18 Feb 2017 17:45:44 +0100 Subject: [PATCH 1/2] 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 --- lib/gears/wallpaper.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/gears/wallpaper.lua b/lib/gears/wallpaper.lua index 70ecf482..c3bd379b 100644 --- a/lib/gears/wallpaper.lua +++ b/lib/gears/wallpaper.lua @@ -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 From 4efee3c3d6fff4247dad43092c7decbfee19ab6d Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 18 Feb 2017 17:41:31 +0100 Subject: [PATCH 2/2] gears.wallpaper: Check for cairo errors This makes things fail loudly which otherwise fail without giving a hint on what went wrong. Reference: https://github.com/awesomeWM/awesome/issues/1570 Signed-off-by: Uli Schlachter --- lib/gears/wallpaper.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/gears/wallpaper.lua b/lib/gears/wallpaper.lua index c3bd379b..4d896fc8 100644 --- a/lib/gears/wallpaper.lua +++ b/lib/gears/wallpaper.lua @@ -130,6 +130,7 @@ function wallpaper.centered(surf, s, background) if surf ~= original_surf then surf:finish() end + assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status) end --- Set a tiled wallpaper. @@ -154,6 +155,7 @@ function wallpaper.tiled(surf, s, offset) if surf ~= original_surf then surf:finish() end + assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status) end --- Set a maximized wallpaper. @@ -191,6 +193,7 @@ function wallpaper.maximized(surf, s, ignore_aspect, offset) if surf ~= original_surf then surf:finish() end + assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status) end --- Set a fitting wallpaper. @@ -226,6 +229,7 @@ function wallpaper.fit(surf, s, background) if surf ~= original_surf then surf:finish() end + assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status) end return wallpaper