Merge pull request #1579 from psychon/gears-wallpaper-improvements
Gears wallpaper improvements
This commit is contained in:
commit
94311913bb
|
@ -111,6 +111,7 @@ end
|
||||||
-- @see gears.color
|
-- @see gears.color
|
||||||
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)
|
||||||
|
local original_surf = surf
|
||||||
surf = surface.load_uncached(surf)
|
surf = surface.load_uncached(surf)
|
||||||
background = color(background)
|
background = color(background)
|
||||||
|
|
||||||
|
@ -126,8 +127,11 @@ 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()
|
||||||
|
if surf ~= original_surf then
|
||||||
surf:finish()
|
surf:finish()
|
||||||
end
|
end
|
||||||
|
assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status)
|
||||||
|
end
|
||||||
|
|
||||||
--- Set a tiled wallpaper.
|
--- Set a tiled wallpaper.
|
||||||
-- @param surf The wallpaper to tile. Either a cairo surface or a file name.
|
-- @param surf The wallpaper to tile. Either a cairo surface or a file name.
|
||||||
|
@ -141,14 +145,18 @@ function wallpaper.tiled(surf, s, offset)
|
||||||
cr:translate(offset.x, offset.y)
|
cr:translate(offset.x, offset.y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local original_surf = surf
|
||||||
surf = surface.load_uncached(surf)
|
surf = surface.load_uncached(surf)
|
||||||
local pattern = cairo.Pattern.create_for_surface(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()
|
||||||
|
if surf ~= original_surf then
|
||||||
surf:finish()
|
surf:finish()
|
||||||
end
|
end
|
||||||
|
assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status)
|
||||||
|
end
|
||||||
|
|
||||||
--- Set a maximized wallpaper.
|
--- Set a maximized wallpaper.
|
||||||
-- @param surf The wallpaper to set. Either a cairo surface or a file name.
|
-- @param surf The wallpaper to set. Either a cairo surface or a file name.
|
||||||
|
@ -159,6 +167,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)
|
||||||
|
local original_surf = surf
|
||||||
surf = surface.load_uncached(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
|
||||||
|
@ -181,8 +190,11 @@ 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()
|
||||||
|
if surf ~= original_surf then
|
||||||
surf:finish()
|
surf:finish()
|
||||||
end
|
end
|
||||||
|
assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status)
|
||||||
|
end
|
||||||
|
|
||||||
--- Set a fitting wallpaper.
|
--- Set a fitting wallpaper.
|
||||||
-- @param surf The wallpaper to set. Either a cairo surface or a file name.
|
-- @param surf The wallpaper to set. Either a cairo surface or a file name.
|
||||||
|
@ -193,6 +205,7 @@ end
|
||||||
-- @see gears.color
|
-- @see gears.color
|
||||||
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)
|
||||||
|
local original_surf = surf
|
||||||
surf = surface.load_uncached(surf)
|
surf = surface.load_uncached(surf)
|
||||||
background = color(background)
|
background = color(background)
|
||||||
|
|
||||||
|
@ -213,8 +226,11 @@ 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()
|
||||||
|
if surf ~= original_surf then
|
||||||
surf:finish()
|
surf:finish()
|
||||||
end
|
end
|
||||||
|
assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status)
|
||||||
|
end
|
||||||
|
|
||||||
return wallpaper
|
return wallpaper
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue