From 5fdce4d845935c7cc8608213039d111abf2bff86 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 15 Mar 2014 22:00:23 -0400 Subject: [PATCH] Move 'surface_size' to gears.surface and make it public --- lib/gears/surface.lua.in | 9 +++++++++ lib/gears/wallpaper.lua.in | 15 +++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/gears/surface.lua.in b/lib/gears/surface.lua.in index e3ea8941..5fd8c4fd 100644 --- a/lib/gears/surface.lua.in +++ b/lib/gears/surface.lua.in @@ -56,6 +56,15 @@ function surface.mt:__call(...) return surface.load(...) 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) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/gears/wallpaper.lua.in b/lib/gears/wallpaper.lua.in index 9039ee9c..c19c39ad 100644 --- a/lib/gears/wallpaper.lua.in +++ b/lib/gears/wallpaper.lua.in @@ -52,15 +52,6 @@ local function prepare_wallpaper(s) return geom, img, cr 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. -- @param pattern The wallpaper that should be set. This can be a cairo surface, -- a description for gears.color or a cairo pattern. @@ -94,7 +85,7 @@ function wallpaper.centered(surf, s, background) cr:paint() -- 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:rectangle(0, 0, w, h) cr:clip() @@ -135,7 +126,7 @@ end function wallpaper.maximized(surf, s, ignore_aspect, offset) local geom, img, cr = prepare_wallpaper(s) 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_h = geom.height / h @@ -173,7 +164,7 @@ function wallpaper.fit(surf, s, background) cr:paint() -- Now fit the surface - local w, h = surface_size(surf) + local w, h = surface.get_size(surf) local scale = geom.width / w if h * scale > geom.height then scale = geom.height / h