gears.surface: Update required lgi version
[awesome.git] / lib / gears / surface.lua.in
blob7ed624db7919c0a583cca265a4a75f32c8b0f311
1 ---------------------------------------------------------------------------
2 -- @author Uli Schlachter
3 -- @copyright 2012 Uli Schlachter
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 local setmetatable = setmetatable
8 local type = type
9 local capi = { awesome = awesome }
10 local cairo = require("lgi").cairo
12 -- This checks for '<= 0.5' because there are git versions after 0.6 which still
13 -- identify themselves as 0.6 but already have the needed cairo support
14 if tonumber(string.match(require('lgi.version'), '(%d%.%d)')) <= 0.5 then
15 error("lgi too old, need at least version 0.6.1")
16 end
18 -- gears.surface
19 local surface = { mt = {} }
21 --- Try to convert the argument into an lgi cairo surface.
22 -- This is usually needed for loading images by file name.
23 function surface.load(_surface)
24 -- Nil is not changed
25 if not _surface then
26 return nil
27 end
28 -- lgi cairo surfaces don't get changed either
29 if cairo.Surface:is_type_of(_surface) then
30 return _surface
31 end
32 -- Strings are assumed to be file names and get loaded
33 if type(_surface) == "string" then
34 _surface = capi.awesome.load_image(_surface)
35 end
36 -- Everything else gets forced into a surface
37 return cairo.Surface(_surface, true)
38 end
40 function surface.mt:__call(...)
41 return surface.load(...)
42 end
44 return setmetatable(surface, surface.mt)
46 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80