2012-05-27 19:20:34 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2012 Uli Schlachter
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local type = type
|
|
|
|
local capi = { awesome = awesome }
|
|
|
|
local cairo = require("lgi").cairo
|
|
|
|
|
2012-06-22 23:22:58 +02:00
|
|
|
-- This checks for '<= 0.5' because there are git versions after 0.6 which still
|
|
|
|
-- identify themselves as 0.6 but already have the needed cairo support
|
2012-06-22 01:22:01 +02:00
|
|
|
if tonumber(string.match(require('lgi.version'), '(%d%.%d)')) <= 0.5 then
|
2012-06-22 23:22:58 +02:00
|
|
|
error("lgi too old, need at least version 0.6.1")
|
2012-06-05 16:22:04 +02:00
|
|
|
end
|
|
|
|
|
2012-06-12 10:13:46 +02:00
|
|
|
-- gears.surface
|
|
|
|
local surface = { mt = {} }
|
2012-05-27 19:20:34 +02:00
|
|
|
|
|
|
|
--- Try to convert the argument into an lgi cairo surface.
|
|
|
|
-- This is usually needed for loading images by file name.
|
2012-06-12 10:13:46 +02:00
|
|
|
function surface.load(_surface)
|
2012-05-27 19:20:34 +02:00
|
|
|
-- Nil is not changed
|
2012-06-12 10:13:46 +02:00
|
|
|
if not _surface then
|
2012-05-27 19:20:34 +02:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
-- lgi cairo surfaces don't get changed either
|
2012-06-12 10:13:46 +02:00
|
|
|
if cairo.Surface:is_type_of(_surface) then
|
|
|
|
return _surface
|
2012-05-27 19:20:34 +02:00
|
|
|
end
|
|
|
|
-- Strings are assumed to be file names and get loaded
|
2012-06-12 10:13:46 +02:00
|
|
|
if type(_surface) == "string" then
|
|
|
|
_surface = capi.awesome.load_image(_surface)
|
2012-05-27 19:20:34 +02:00
|
|
|
end
|
|
|
|
-- Everything else gets forced into a surface
|
2012-06-12 10:13:46 +02:00
|
|
|
return cairo.Surface(_surface, true)
|
2012-05-27 19:20:34 +02:00
|
|
|
end
|
|
|
|
|
2012-06-12 10:13:46 +02:00
|
|
|
function surface.mt:__call(...)
|
|
|
|
return surface.load(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(surface, surface.mt)
|
2012-05-27 19:20:34 +02:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|