beautiful: theme are now handled in Lua

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
perry 2009-04-28 19:40:14 +02:00 committed by Julien Danjou
parent f2c104ba78
commit 5e284c4ab3
3 changed files with 28 additions and 24 deletions

View File

@ -275,13 +275,11 @@ set(AWESOME_THEMES_PATH ${AWESOME_DATA_PATH}/themes)
# }}}
# {{{ Configure files
file(GLOB_RECURSE awesome_lua_configure_files RELATIVE ${SOURCE_DIR} ${SOURCE_DIR}/lib/*.lua.in)
file(GLOB_RECURSE awesome_lua_configure_files RELATIVE ${SOURCE_DIR} ${SOURCE_DIR}/lib/*.lua.in ${SOURCE_DIR}/themes/*/*.lua.in)
set(AWESOME_CONFIGURE_FILES
${awesome_lua_configure_files}
config.h.in
awesomerc.lua.in
themes/default/theme.in
themes/sky/theme.in
awesome-version-internal.h.in
awesome.doxygen.in)

View File

@ -8,9 +8,9 @@ require("naughty")
-- {{{ Variable definitions
-- Themes define colours, icons, and wallpapers
-- The default is a dark theme
theme_path = "@AWESOME_THEMES_PATH@/default/theme"
theme_path = "@AWESOME_THEMES_PATH@/default/theme.lua"
-- Uncommment this for a lighter theme
-- theme_path = "@AWESOME_THEMES_PATH@/sky/theme"
-- theme_path = "@AWESOME_THEMES_PATH@/sky/theme.lua"
-- Actually load theme
beautiful.init(theme_path)

View File

@ -9,6 +9,9 @@
local io = io
local os = os
local print = print
local pairs = pairs
local type = type
local dofile = dofile
local setmetatable = setmetatable
local util = require("awful.util")
local package = package
@ -36,29 +39,32 @@ end
-- @param path The theme file path.
function init(path)
if path then
local f = io.open(path)
theme = dofile(path)
if not f then
return print("E: unable to load theme " .. path)
end
for key, value in f:read("*all"):gsub("^", "\n"):gmatch("\n[\t ]*([a-z_]+)[\t ]*=[\t ]*([^\n\t]+)") do
value = value:gsub("~", os.getenv("HOME"))
if key == "wallpaper_cmd" then
for s = 1, capi.screen.count() do
util.spawn(value, false, s)
if theme then
-- try and grab user's $HOME directory
local homedir = os.getenv("HOME")
-- expand '~'
if homedir then
for k, v in pairs(theme) do
if type(v) == "string" then theme[k] = v:gsub("~", homedir) end
end
elseif key == "font" then
capi.awesome.font = value
elseif key == "fg_normal" then
capi.awesome.fg = value
elseif key == "bg_normal" then
capi.awesome.bg = value
end
-- Store.
theme[key] = value
-- setup wallpaper
if theme.wallpaper_cmd then
for s = 1, capi.screen.count() do
util.spawn(theme.wallpaper_cmd[util.cycle(#theme.wallpaper_cmd, s)], false, s)
end
end
if theme.font then capi.awesome.font = theme.font end
if theme.fg_normal then capi.awesome.fg = theme.fg_normal end
if theme.bg_normal then capi.awesome.bg = theme.bg_normal end
else
return print("E: error loading theme file " .. path)
end
f:close()
else
return print("E: error loading theme: no path specified " )
end
end