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")
17 local lgi
= require("lgi")
18 local cairo
= lgi
.cairo
19 local Pango
= lgi
.Pango
20 local PangoCairo
= lgi
.PangoCairo
28 local beautiful
= { mt
= {} }
32 local descs
= setmetatable({}, { __mode
= 'k' })
33 local fonts
= setmetatable({}, { __mode
= 'v' })
36 local function load_font(name
)
37 name
= name
or active_font
38 if name
and type(name
) ~= "string" and descs
[name
] then
45 local desc
= Pango
.FontDescription
.from_string(name
)
47 local ctx
= PangoCairo
.font_map_get_default():create_context()
48 local layout
= Pango
.Layout
.new(ctx
)
49 layout
:set_font_description(desc
)
51 local width
, height
= layout
:get_pixel_size()
52 local font
= { name
= name
, description
= desc
, height
= height
}
58 local function set_font(name
)
59 active_font
= load_font(name
).name
62 function beautiful
.get_font(name
)
63 return load_font(name
).description
66 function beautiful
.get_font_height(name
)
67 return load_font(name
).height
70 --- Init function, should be runned at the beginning of configuration file.
71 -- @param path The theme file path.
72 function beautiful
.init(path
)
75 success
, theme
= pcall(function() return dofile(path
) end)
78 return print("E: beautiful: error loading theme file " .. theme
)
80 -- try and grab user's $HOME directory
81 local homedir
= os
.getenv("HOME")
84 for k
, v
in pairs(theme
) do
85 if type(v
) == "string" then theme
[k
] = v
:gsub("~", homedir
) end
89 if theme
.font
then set_font(theme
.font
) end
90 if theme
.fg_normal
then capi
.awesome
.fg
= theme
.fg_normal
end
91 if theme
.bg_normal
then capi
.awesome
.bg
= theme
.bg_normal
end
93 return print("E: beautiful: error loading theme file " .. path
)
96 return print("E: beautiful: error loading theme: no path specified")
100 --- Get the current theme.
101 -- @return The current theme table.
102 function beautiful
.get()
106 function beautiful
.mt
:__index(k
)
110 -- Set the default font
113 return setmetatable(beautiful
, beautiful
.mt
)
115 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80