1 ----------------------------------------------------------------------------
2 -- @author Damien Leone <damien.leone@gmail.com>
3 -- @author Julien Danjou <julien@danjou.info>
4 -- @copyright 2008-2009 Damien Leone, Julien Danjou
5 -- @release @AWESOME_VERSION@
6 ----------------------------------------------------------------------------
15 local setmetatable
= setmetatable
16 local util
= require("awful.util")
30 local descs
= setmetatable({}, { __mode
= 'k' })
31 local fonts
= setmetatable({}, { __mode
= 'v' })
34 local function load_font(name
)
35 name
= name
or active_font
36 if name
and type(name
) ~= "string" and descs
[name
] then
43 local desc
= capi
.oopango
.font_description_from_string(name
)
45 -- Create a temporary surface that we need for computing the size :(
46 local surface
= capi
.oocairo
.image_surface_create("argb32", 1, 1)
47 local cr
= capi
.oocairo
.context_create(surface
)
49 -- Api breakage in oopango
50 if capi
.oopango
.cairo_layout_create
then
51 layout
= capi
.oopango
.cairo_layout_create(cr
)
53 layout
= capi
.oopango
.cairo
.layout_create(cr
)
56 layout
:set_font_description(desc
)
58 local width
, height
= layout
:get_pixel_size()
59 local font
= { name
= name
, description
= desc
, height
= height
}
65 local function set_font(name
)
66 active_font
= load_font(name
).name
69 function get_font(name
)
70 return load_font(name
).description
73 function get_font_height(name
)
74 return load_font(name
).height
77 --- Init function, should be runned at the beginning of configuration file.
78 -- @param path The theme file path.
82 success
, theme
= pcall(function() return dofile(path
) end)
85 return print("E: beautiful: error loading theme file " .. theme
)
87 -- try and grab user's $HOME directory
88 local homedir
= os
.getenv("HOME")
91 for k
, v
in pairs(theme
) do
92 if type(v
) == "string" then theme
[k
] = v
:gsub("~", homedir
) end
97 if theme
.wallpaper_cmd
then
98 for s
= 1, capi
.screen
.count() do
99 util
.spawn(theme
.wallpaper_cmd
[util
.cycle(#theme
.wallpaper_cmd
, s
)], false, s
)
102 if theme
.font
then set_font(theme
.font
) end
103 if theme
.fg_normal
then capi
.awesome
.fg
= theme
.fg_normal
end
104 if theme
.bg_normal
then capi
.awesome
.bg
= theme
.bg_normal
end
106 return print("E: beautiful: error loading theme file " .. path
)
109 return print("E: beautiful: error loading theme: no path specified")
113 --- Get the current theme.
114 -- @return The current theme table.
119 -- Set the default font
122 setmetatable(_M
, { __index
= function(t
, k
) return theme
[k
] end })
124 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80