Merge pull request #716 from psychon/wallpaper_cleanup

Wallpaper cleanup
This commit is contained in:
Daniel Hahler 2016-03-03 22:16:48 +01:00
commit 7c7295a282
2 changed files with 17 additions and 12 deletions

View File

@ -41,8 +41,6 @@ function surface.load_uncached_silently(_surface, default)
if not _surface then if not _surface then
return get_default(default) return get_default(default)
end end
-- Remove from cache if it was cached
surface_cache[_surface] = nil
-- lgi cairo surfaces don't get changed either -- lgi cairo surfaces don't get changed either
if cairo.Surface:is_type_of(_surface) then if cairo.Surface:is_type_of(_surface) then
return _surface return _surface
@ -57,12 +55,7 @@ function surface.load_uncached_silently(_surface, default)
end end
end end
-- Everything else gets forced into a surface -- Everything else gets forced into a surface
_surface = cairo.Surface(_surface, true) return cairo.Surface(_surface, true)
-- If we loaded a file, cache it
if file then
surface_cache[file] = _surface
end
return _surface
end end
--- Try to convert the argument into an lgi cairo surface. --- Try to convert the argument into an lgi cairo surface.
@ -80,6 +73,12 @@ function surface.load_silently(_surface, default)
if cache then if cache then
return cache return cache
end end
local result, err = surface.load_uncached_silently(_surface, default)
if not err then
-- Cache the file
surface_cache[_surface] = result
end
return result, err
end end
return surface.load_uncached_silently(_surface, default) return surface.load_uncached_silently(_surface, default)
end end

View File

@ -61,6 +61,7 @@ function wallpaper.prepare_context(s)
local paper = pending_wallpaper local paper = pending_wallpaper
pending_wallpaper = nil pending_wallpaper = nil
wallpaper.set(paper) wallpaper.set(paper)
paper:finish()
end) end)
else else
-- Draw to the already-pending wallpaper -- Draw to the already-pending wallpaper
@ -99,7 +100,7 @@ end
-- gears.color. The default is black. -- gears.color. The default is black.
function wallpaper.centered(surf, s, background) function wallpaper.centered(surf, s, background)
local geom, cr = wallpaper.prepare_context(s) local geom, cr = wallpaper.prepare_context(s)
surf = surface(surf) surf = surface.load_uncached(surf)
background = color(background) background = color(background)
-- Fill the area with the background -- Fill the area with the background
@ -114,6 +115,7 @@ function wallpaper.centered(surf, s, background)
cr:clip() cr:clip()
cr:set_source_surface(surf, 0, 0) cr:set_source_surface(surf, 0, 0)
cr:paint() cr:paint()
surf:finish()
end end
--- Set a tiled wallpaper. --- Set a tiled wallpaper.
@ -128,11 +130,13 @@ function wallpaper.tiled(surf, s, offset)
cr:translate(offset.x, offset.y) cr:translate(offset.x, offset.y)
end end
local pattern = cairo.Pattern.create_for_surface(surface(surf)) surf = surface.load_uncached(surf)
local pattern = cairo.Pattern.create_for_surface(surf)
pattern.extend = cairo.Extend.REPEAT pattern.extend = cairo.Extend.REPEAT
cr.source = pattern cr.source = pattern
cr.operator = cairo.Operator.SOURCE cr.operator = cairo.Operator.SOURCE
cr:paint() cr:paint()
surf:finish()
end end
--- Set a maximized wallpaper. --- Set a maximized wallpaper.
@ -144,7 +148,7 @@ end
-- @param offset This can be set to a table with entries x and y. -- @param offset This can be set to a table with entries x and y.
function wallpaper.maximized(surf, s, ignore_aspect, offset) function wallpaper.maximized(surf, s, ignore_aspect, offset)
local geom, cr = wallpaper.prepare_context(s) local geom, cr = wallpaper.prepare_context(s)
surf = surface(surf) surf = surface.load_uncached(surf)
local w, h = surface.get_size(surf) local w, h = surface.get_size(surf)
local aspect_w = geom.width / w local aspect_w = geom.width / w
local aspect_h = geom.height / h local aspect_h = geom.height / h
@ -166,6 +170,7 @@ function wallpaper.maximized(surf, s, ignore_aspect, offset)
cr:set_source_surface(surf, 0, 0) cr:set_source_surface(surf, 0, 0)
cr.operator = cairo.Operator.SOURCE cr.operator = cairo.Operator.SOURCE
cr:paint() cr:paint()
surf:finish()
end end
--- Set a fitting wallpaper. --- Set a fitting wallpaper.
@ -176,7 +181,7 @@ end
-- gears.color. The default is black. -- gears.color. The default is black.
function wallpaper.fit(surf, s, background) function wallpaper.fit(surf, s, background)
local geom, cr = wallpaper.prepare_context(s) local geom, cr = wallpaper.prepare_context(s)
surf = surface(surf) surf = surface.load_uncached(surf)
background = color(background) background = color(background)
-- Fill the area with the background -- Fill the area with the background
@ -196,6 +201,7 @@ function wallpaper.fit(surf, s, background)
cr:scale(scale, scale) cr:scale(scale, scale)
cr:set_source_surface(surf, 0, 0) cr:set_source_surface(surf, 0, 0)
cr:paint() cr:paint()
surf:finish()
end end
return wallpaper return wallpaper