2008-08-05 22:21:22 +02:00
|
|
|
----------------------------------------------------------------------------
|
2008-08-05 22:26:34 +02:00
|
|
|
-- @author Damien Leone <damien.leone@gmail.com>
|
2008-08-05 22:21:22 +02:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
2009-04-18 16:05:18 +02:00
|
|
|
-- @copyright 2008-2009 Damien Leone, Julien Danjou
|
2008-08-18 11:41:58 +02:00
|
|
|
-- @release @AWESOME_VERSION@
|
2008-08-05 22:21:22 +02:00
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment
|
2009-04-18 16:05:18 +02:00
|
|
|
local os = os
|
2008-08-05 22:21:22 +02:00
|
|
|
local print = print
|
2009-08-21 21:26:50 +02:00
|
|
|
local pcall = pcall
|
2009-04-28 19:40:14 +02:00
|
|
|
local pairs = pairs
|
|
|
|
local type = type
|
|
|
|
local dofile = dofile
|
2008-08-05 22:21:22 +02:00
|
|
|
local setmetatable = setmetatable
|
2008-09-29 16:49:18 +02:00
|
|
|
local util = require("awful.util")
|
2008-08-20 18:15:08 +02:00
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
screen = screen,
|
2010-10-06 14:18:11 +02:00
|
|
|
awesome = awesome,
|
|
|
|
oocairo = oocairo,
|
|
|
|
oopango = oopango
|
2008-08-20 18:15:08 +02:00
|
|
|
}
|
2008-08-05 22:21:22 +02:00
|
|
|
|
2009-04-28 22:54:55 +02:00
|
|
|
--- Theme library.
|
2008-08-08 19:07:42 +02:00
|
|
|
module("beautiful")
|
2008-08-05 22:21:22 +02:00
|
|
|
|
|
|
|
-- Local data
|
2009-08-21 21:26:50 +02:00
|
|
|
local theme
|
2011-04-14 22:40:56 +02:00
|
|
|
local descs = setmetatable({}, { __mode = 'k' })
|
|
|
|
local fonts = setmetatable({}, { __mode = 'v' })
|
2011-04-14 07:04:48 +02:00
|
|
|
local active_font
|
2010-10-06 14:18:11 +02:00
|
|
|
|
2011-04-14 07:04:48 +02:00
|
|
|
local function load_font(name)
|
|
|
|
name = name or active_font
|
|
|
|
if name and type(name) ~= "string" and descs[name] then
|
|
|
|
name = descs[name]
|
|
|
|
end
|
|
|
|
if fonts[name] then
|
|
|
|
return fonts[name]
|
|
|
|
end
|
|
|
|
-- load new font
|
|
|
|
local desc = capi.oopango.font_description_from_string(name)
|
2010-10-06 14:18:11 +02:00
|
|
|
|
|
|
|
-- Create a temporary surface that we need for computing the size :(
|
|
|
|
local surface = capi.oocairo.image_surface_create("argb32", 1, 1)
|
|
|
|
local cr = capi.oocairo.context_create(surface)
|
2010-10-06 15:11:20 +02:00
|
|
|
local layout
|
|
|
|
-- Api breakage in oopango
|
|
|
|
if capi.oopango.cairo_layout_create then
|
|
|
|
layout = capi.oopango.cairo_layout_create(cr)
|
|
|
|
else
|
|
|
|
layout = capi.oopango.cairo.layout_create(cr)
|
|
|
|
end
|
|
|
|
|
2011-04-14 07:04:48 +02:00
|
|
|
layout:set_font_description(desc)
|
2010-10-06 14:18:11 +02:00
|
|
|
|
|
|
|
local width, height = layout:get_pixel_size()
|
2011-04-14 07:04:48 +02:00
|
|
|
local font = { name = name, description = desc, height = height }
|
|
|
|
fonts[name] = font
|
|
|
|
descs[desc] = name
|
|
|
|
return font
|
|
|
|
end
|
|
|
|
|
|
|
|
local function set_font(name)
|
|
|
|
active_font = load_font(name).name
|
|
|
|
end
|
|
|
|
|
|
|
|
function get_font(name)
|
|
|
|
return load_font(name).description
|
|
|
|
end
|
|
|
|
|
|
|
|
function get_font_height(name)
|
|
|
|
return load_font(name).height
|
2010-10-06 14:18:11 +02:00
|
|
|
end
|
2008-08-05 22:21:22 +02:00
|
|
|
|
|
|
|
--- Init function, should be runned at the beginning of configuration file.
|
|
|
|
-- @param path The theme file path.
|
|
|
|
function init(path)
|
|
|
|
if path then
|
2009-08-21 21:26:50 +02:00
|
|
|
local success
|
|
|
|
success, theme = pcall(function() return dofile(path) end)
|
2008-08-05 22:21:22 +02:00
|
|
|
|
2009-08-21 21:26:50 +02:00
|
|
|
if not success then
|
|
|
|
return print("E: beautiful: error loading theme file " .. theme)
|
|
|
|
elseif theme then
|
2009-04-28 19:40:14 +02:00
|
|
|
-- 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
|
|
|
|
end
|
2008-08-05 22:21:22 +02:00
|
|
|
|
2009-04-28 19:40:14 +02:00
|
|
|
-- setup wallpaper
|
|
|
|
if theme.wallpaper_cmd then
|
2008-11-22 08:47:05 +01:00
|
|
|
for s = 1, capi.screen.count() do
|
2009-04-28 19:40:14 +02:00
|
|
|
util.spawn(theme.wallpaper_cmd[util.cycle(#theme.wallpaper_cmd, s)], false, s)
|
2008-08-05 22:21:22 +02:00
|
|
|
end
|
|
|
|
end
|
2010-10-06 14:18:11 +02:00
|
|
|
if theme.font then set_font(theme.font) end
|
2009-04-28 19:40:14 +02:00
|
|
|
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
|
2009-08-21 21:26:50 +02:00
|
|
|
return print("E: beautiful: error loading theme file " .. path)
|
2008-08-05 22:21:22 +02:00
|
|
|
end
|
2009-04-28 19:40:14 +02:00
|
|
|
else
|
2009-08-21 21:26:50 +02:00
|
|
|
return print("E: beautiful: error loading theme: no path specified")
|
2008-08-05 22:21:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-13 11:53:41 +01:00
|
|
|
--- Get the current theme.
|
|
|
|
-- @return The current theme table.
|
|
|
|
function get()
|
2009-04-28 22:54:55 +02:00
|
|
|
return theme
|
2008-11-13 11:53:41 +01:00
|
|
|
end
|
|
|
|
|
2010-10-06 14:18:11 +02:00
|
|
|
-- Set the default font
|
|
|
|
set_font("sans 8")
|
|
|
|
|
2009-04-28 22:54:55 +02:00
|
|
|
setmetatable(_M, { __index = function(t, k) return theme[k] end })
|
2008-08-06 15:39:51 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|