mouse: fix client snapping
[awesome.git] / lib / beautiful.lua
blob7491dc06a31dd71ed7a6edbd6eeb064f57be2e21
1 ----------------------------------------------------------------------------
2 -- @author Damien Leone <damien.leone@gmail.com>
3 -- @author Julien Danjou <julien@danjou.info>
4 -- @copyright 2008 Damien Leone, Julien Danjou
5 ----------------------------------------------------------------------------
7 -- Grab environment
8 local io = io
9 local print = print
10 local setmetatable = setmetatable
11 local awful = require("awful")
12 local package = package
13 local capi = { awesome = awesome }
15 local module_name = "beautiful"
17 --- beautiful: theme library
18 module("beautiful")
20 -- Local data
21 local theme = {}
23 --- Split line in two if it contains the '=' character.
24 -- @param line The line to split.
25 -- @return nil if the '=' character is not in the string
26 local function split_line(line)
27 local split_val = line:find('=')
29 if split_val and line:sub(1, 1) ~= '#' and line:sub(1, 2) ~= '--' then
30 -- Remove spaces in key and extra spaces before value
31 local value = line:sub(split_val + 1, -1)
32 while value:sub(1, 1) == ' ' do
33 value = value:sub(2, -1)
34 end
36 return line:sub(1, split_val - 1):gsub(' ', ''), value
37 end
38 end
40 --- Get a value directly.
41 -- @param key The key.
42 -- @return The value.
43 function __index(self, key)
44 if theme[key] then
45 return theme[key]
46 end
47 end
49 --- Init function, should be runned at the beginning of configuration file.
50 -- @param path The theme file path.
51 function init(path)
52 if path then
53 local f = io.open(path)
55 if not f then
56 return print("E: unable to load theme " .. path)
57 end
59 for line in f:lines() do
60 local key, value
61 key, value = split_line(line)
62 if key then
63 if key == "wallpaper_cmd" then
64 awful.spawn(value)
65 elseif key == "font" then
66 capi.awesome.font_set(value)
67 elseif key == "fg_normal" then
68 capi.awesome.colors_set({ fg = value })
69 elseif key == "bg_normal" then
70 capi.awesome.colors_set({ bg = value })
71 end
72 -- Store.
73 theme[key] = value
74 end
75 end
76 f:close()
77 end
78 end
80 setmetatable(package.loaded[module_name], package.loaded[module_name])
82 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80