Add color groups

This commit is contained in:
Emmanuel Lepage Vallee 2014-12-31 00:30:52 -05:00
parent 1257ac228e
commit 2f9af8d5dd
4 changed files with 60 additions and 3 deletions

View File

@ -285,6 +285,7 @@ here is the list:
| add_prefix_widget | Add a widget at the beginning of the menu | the widget | --- | | add_prefix_widget | Add a widget at the beginning of the menu | the widget | --- |
| add_suffix_widget | Add a widget at the end of the menu | the widget | --- | | add_suffix_widget | Add a widget at the end of the menu | the widget | --- |
| add_colors_namespace | Use prefixed colors from beautiful | the namespace name | --- | | add_colors_namespace | Use prefixed colors from beautiful | the namespace name | --- |
| add_colors_group | Add a new color group (see below for details)| the group name | --- |
###Signals ###Signals
@ -366,6 +367,16 @@ allow masks such as desaturation, tinting, invert or some matrix to be applied
on the pixmap before it is being drawn. This function take the path/surface as on the pixmap before it is being drawn. This function take the path/surface as
only parameter and return the transformed surface. only parameter and return the transformed surface.
Other elements can be added to items such as prefix, underlay and siffixes.
Those elements sometime need extra color groups. The `add_color_group` method
allow to register such new category. For a common example, the underlay, it
will be possible to pass `underlay_bg_focus` or `underlay_fg_disabled` colors
or any other registered states.
Some generic menu can also register beautiful namespaces using the
`add_colors_namespace` method. For example, the tasklist namespace can be used
by adding elements such as `beautiful.tasklist_bg_urgent` to your theme.
## Extending Radical ## Extending Radical
Radical is not designed to be used "as is". Every menus are different. While Radical is not designed to be used "as is". Every menus are different. While

View File

@ -430,6 +430,10 @@ local function new(args)
end end
end end
data.add_colors_group = function(data,section)
theme.add_section(data,section,args)
end
data.set_layout = function(_,value) data.set_layout = function(_,value)
if value then if value then
value:setup_key_hooks(data) value:setup_key_hooks(data)

View File

@ -143,7 +143,20 @@ local function new_item(data,args)
item.get_fg = function() item.get_fg = function()
return data.fg return data.fg
end end
item.set_underlay = function(item,underlay)
if not item._internal.underlay_init then
data:add_colors_group("underlay")
item._internal.underlay_init = true
end
item._internal.underlay_content = underlay
end
item.get_underlay = function(item)
return item._internal.underlay_content
end
item.state = theme.init_state(item) item.state = theme.init_state(item)
item.underlay = args.underlay
for i=1,10 do for i=1,10 do
item["button"..i] = args["button"..i] item["button"..i] = args["button"..i]

View File

@ -42,6 +42,15 @@ end
-- Util to help match colors to states -- Util to help match colors to states
local theme_colors = {} local theme_colors = {}
local function load_section(data,priv,section,args)
local bg,fg,args = section.."_bg_", section.."_fg_",args or {}
for k,v in pairs(theme_colors) do
priv[bg..k] = args[bg..v.beautiful_name] or beautiful["menu_"..bg..v.beautiful_name] or beautiful[bg..v.beautiful_name]
priv[fg..k] = args[fg..v.beautiful_name] or beautiful["menu_"..fg..v.beautiful_name] or beautiful[fg..v.beautiful_name]
end
end
function module.register_color(state_id,name,beautiful_name,allow_fallback) function module.register_color(state_id,name,beautiful_name,allow_fallback)
theme_colors[name] = {id=state_id,beautiful_name=beautiful_name,fallback=allow_fallback} theme_colors[name] = {id=state_id,beautiful_name=beautiful_name,fallback=allow_fallback}
module.colors_by_id[state_id] = name module.colors_by_id[state_id] = name
@ -51,11 +60,15 @@ function module.setup_colors(data,args)
for k,v in pairs(theme_colors) do for k,v in pairs(theme_colors) do
priv["fg_"..k] = args["fg_"..k] or beautiful["menu_fg_"..v.beautiful_name] or beautiful["fg_"..v.beautiful_name] or (v.fallback and beautiful.fg_normal) priv["fg_"..k] = args["fg_"..k] or beautiful["menu_fg_"..v.beautiful_name] or beautiful["fg_"..v.beautiful_name] or (v.fallback and beautiful.fg_normal)
priv["bg_"..k] = args["bg_"..k] or beautiful["menu_bg_"..v.beautiful_name] or beautiful["bg_"..v.beautiful_name] or (v.fallback and beautiful.bg_normal) priv["bg_"..k] = args["bg_"..k] or beautiful["menu_bg_"..v.beautiful_name] or beautiful["bg_"..v.beautiful_name] or (v.fallback and beautiful.bg_normal)
priv["underlay_bg_"..k] = args["underlay_bg_"..k] or beautiful["menu_underlay_bg_"..v.beautiful_name] or beautiful["underlay_bg_"..v.beautiful_name] --priv["underlay_bg_"..k] = args["underlay_bg_"..k] or beautiful["menu_underlay_bg_"..v.beautiful_name] or beautiful["underlay_bg_"..v.beautiful_name]
end
-- Handle custom sections
for _,section in ipairs(priv.section or {}) do
load_section(data,priv,section,args)
end end
end end
function module.setup_item_colors(data,item,args) function module.setup_item_colors(data,item,args)
local priv = item._private_data local priv = item._private_data
for k,v in pairs(theme_colors) do for k,v in pairs(theme_colors) do
@ -84,8 +97,24 @@ function module.add_colors_from_namespace(data,namespace)
for k,v in pairs(theme_colors) do for k,v in pairs(theme_colors) do
priv["fg_"..k] = beautiful[namespace.."_fg_"..v.beautiful_name] or priv["fg_"..k] priv["fg_"..k] = beautiful[namespace.."_fg_"..v.beautiful_name] or priv["fg_"..k]
priv["bg_"..k] = beautiful[namespace.."_bg_"..v.beautiful_name] or priv["bg_"..k] priv["bg_"..k] = beautiful[namespace.."_bg_"..v.beautiful_name] or priv["bg_"..k]
priv["underlay_bg_"..k] = beautiful[namespace.."_underlay_bg_"..v.beautiful_name] or priv["underlay_bg_"..k]
end end
priv["fg"] = beautiful[namespace.."_fg"] or priv["fg"]
priv["bg"] = beautiful[namespace.."_bg"] or priv["bg"]
priv.namespace = priv.namespace or {}
priv.namespace[#priv.namespace+1] = namespace
end
-- Utils to add new color-able elements of an item
-- this can be used either for extentions, such as {pre,suf}fixes
-- or "special" [item_]styles
function module.add_section(data,section,args)
local priv = data._internal.private_data
load_section(data,priv,section,args)
priv.section = priv.section or {}
priv.section[#priv.section+1] = section
end end
return setmetatable(module, { __call = function(_, ...) return new(...) end }) return setmetatable(module, { __call = function(_, ...) return new(...) end })