Move 'surface_size' to gears.surface and make it public

This commit is contained in:
Emmanuel Lepage Vallee 2014-03-15 22:00:23 -04:00 committed by Uli Schlachter
parent b22ea59812
commit 9b872f4bce
2 changed files with 12 additions and 12 deletions

View File

@ -56,6 +56,15 @@ function surface.mt:__call(...)
return surface.load(...) return surface.load(...)
end end
--- Get the size of a cairo surface
-- @param surf The surface you are interested in
-- @return The surface's width and height
function surface.get_size(surf)
local cr = cairo.Context(surf)
local x, y, w, h = cr:clip_extents()
return w - x, h - y
end
return setmetatable(surface, surface.mt) return setmetatable(surface, surface.mt)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -52,15 +52,6 @@ local function prepare_wallpaper(s)
return geom, img, cr return geom, img, cr
end end
--- Get the size of a cairo surface
-- @param surf The surface you are interested in
-- @return The surface's width and height
local function surface_size(surf)
local cr = cairo.Context(surf)
local x, y, w, h = cr:clip_extents()
return w, h
end
--- Set the current wallpaper. --- Set the current wallpaper.
-- @param pattern The wallpaper that should be set. This can be a cairo surface, -- @param pattern The wallpaper that should be set. This can be a cairo surface,
-- a description for gears.color or a cairo pattern. -- a description for gears.color or a cairo pattern.
@ -94,7 +85,7 @@ function wallpaper.centered(surf, s, background)
cr:paint() cr:paint()
-- Now center the surface -- Now center the surface
local w, h = surface_size(surf) local w, h = surface.get_size(surf)
cr:translate((geom.width - w) / 2, (geom.height - h) / 2) cr:translate((geom.width - w) / 2, (geom.height - h) / 2)
cr:rectangle(0, 0, w, h) cr:rectangle(0, 0, w, h)
cr:clip() cr:clip()
@ -135,7 +126,7 @@ end
function wallpaper.maximized(surf, s, ignore_aspect, offset) function wallpaper.maximized(surf, s, ignore_aspect, offset)
local geom, img, cr = prepare_wallpaper(s) local geom, img, cr = prepare_wallpaper(s)
local surf = surface(surf) local surf = surface(surf)
local w, h = surface_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
@ -173,7 +164,7 @@ function wallpaper.fit(surf, s, background)
cr:paint() cr:paint()
-- Now fit the surface -- Now fit the surface
local w, h = surface_size(surf) local w, h = surface.get_size(surf)
local scale = geom.width / w local scale = geom.width / w
if h * scale > geom.height then if h * scale > geom.height then
scale = geom.height / h scale = geom.height / h