Add scale factor to gears.wallpaper.centered (#1653)
This commit is contained in:
parent
26fedadc07
commit
008bd185ba
|
@ -108,13 +108,19 @@ end
|
||||||
-- all screens are set.
|
-- all screens are set.
|
||||||
-- @param background The background color that should be used. Gets handled via
|
-- @param background The background color that should be used. Gets handled via
|
||||||
-- gears.color. The default is black.
|
-- gears.color. The default is black.
|
||||||
|
-- @param scale The scale factor for the wallpaper. Default is 1 (original size).
|
||||||
-- @see gears.color
|
-- @see gears.color
|
||||||
function wallpaper.centered(surf, s, background)
|
function wallpaper.centered(surf, s, background, scale)
|
||||||
local geom, cr = wallpaper.prepare_context(s)
|
local geom, cr = wallpaper.prepare_context(s)
|
||||||
local original_surf = surf
|
local original_surf = surf
|
||||||
surf = surface.load_uncached(surf)
|
surf = surface.load_uncached(surf)
|
||||||
background = color(background)
|
background = color(background)
|
||||||
|
|
||||||
|
-- Set default scale if unset
|
||||||
|
if not scale or scale <= 0 then
|
||||||
|
scale = 1
|
||||||
|
end
|
||||||
|
|
||||||
-- Fill the area with the background
|
-- Fill the area with the background
|
||||||
cr.operator = cairo.Operator.SOURCE
|
cr.operator = cairo.Operator.SOURCE
|
||||||
cr.source = background
|
cr.source = background
|
||||||
|
@ -122,9 +128,12 @@ function wallpaper.centered(surf, s, background)
|
||||||
|
|
||||||
-- Now center the surface
|
-- Now center the surface
|
||||||
local w, h = surface.get_size(surf)
|
local w, h = surface.get_size(surf)
|
||||||
cr:translate((geom.width - w) / 2, (geom.height - h) / 2)
|
cr:translate((geom.width - (w * scale)) / 2, (geom.height - (h * scale)) / 2)
|
||||||
cr:rectangle(0, 0, w, h)
|
cr:rectangle(0, 0, (w * scale), (h * scale))
|
||||||
|
|
||||||
cr:clip()
|
cr:clip()
|
||||||
|
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
|
if surf ~= original_surf then
|
||||||
|
|
Loading…
Reference in New Issue