Add awesome.register_xproperty (FS#1212)
[awesome.git] / lib / gears / surface.lua.in
blob7ad9e1f3b67aa89366541f76b3ee85d484679cf9
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 local ver_major,ver_minor = string.match(require('lgi.version'),'(%d)%.(%d)')
15 if ( (tonumber(ver_major)<=0) and (tonumber(ver_minor)<=5) ) then
16 error("lgi too old, need at least version 0.6.1")
17 end
19 -- gears.surface
20 local surface = { mt = {} }
22 --- Try to convert the argument into an lgi cairo surface.
23 -- This is usually needed for loading images by file name.
24 function surface.load(_surface)
25 -- Nil is not changed
26 if not _surface then
27 return nil
28 end
29 -- lgi cairo surfaces don't get changed either
30 if cairo.Surface:is_type_of(_surface) then
31 return _surface
32 end
33 -- Strings are assumed to be file names and get loaded
34 if type(_surface) == "string" then
35 _surface = capi.awesome.load_image(_surface)
36 end
37 -- Everything else gets forced into a surface
38 return cairo.Surface(_surface, true)
39 end
41 function surface.mt:__call(...)
42 return surface.load(...)
43 end
45 return setmetatable(surface, surface.mt)
47 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80