Add a color namespace helper method

This will allow implementations to use their own colors without
redefining them by hand
This commit is contained in:
Emmanuel Lepage Vallee 2014-12-30 17:27:57 -05:00
parent 7b071fb7d1
commit 1257ac228e
6 changed files with 54 additions and 25 deletions

View File

@ -265,25 +265,26 @@ The colors option are available for both menus and items objects.
All menus provide a bunch of methods. Most of them have been coverred above, but
here is the list:
| Name | Description | Arguments | Return |
| ----------------- | -------------------------------------------- | --------------------- | ------ |
| add_item | Add new item to a menu | array of options | item |
| add_items | Add new items to a menu | array of items arrays | array |
| add_widget | Add a new widget instead of an item | a widget, args | --- |
| add_widgets | Add new widgets | array of widgets | --- |
| add_embeded_menu | Add an inline menu to another menu | an "embed" menu | --- |
| add_key_binding | Add a global key binding to a menu | mod array, key | --- |
| add_key_hook | Add a callback when a key is pressed | mod, key, event, func | --- |
| clear | Remove all items | --- | --- |
| scroll_down | If the menu is cropped, scroll down | --- | --- |
| scroll_up | If the menu is cropped, scroll up | --- | --- |
| hide | Hide a menu and all sub menus | --- | --- |
| swap | Swap 2 items | both items | --- |
| move | Move an item | the item, the new idx | --- |
| remove | Remove the item | the item | --- |
| append | Append an existing (but unused) item | the item | --- |
| 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 | --- |
| Name | Description | Arguments | Return |
| -------------------- | -------------------------------------------- | --------------------- | ------ |
| add_item | Add new item to a menu | array of options | item |
| add_items | Add new items to a menu | array of items arrays | array |
| add_widget | Add a new widget instead of an item | a widget, args | --- |
| add_widgets | Add new widgets | array of widgets | --- |
| add_embeded_menu | Add an inline menu to another menu | an "embed" menu | --- |
| add_key_binding | Add a global key binding to a menu | mod array, key | --- |
| add_key_hook | Add a callback when a key is pressed | mod, key, event, func | --- |
| clear | Remove all items | --- | --- |
| scroll_down | If the menu is cropped, scroll down | --- | --- |
| scroll_up | If the menu is cropped, scroll up | --- | --- |
| hide | Hide a menu and all sub menus | --- | --- |
| swap | Swap 2 items | both items | --- |
| move | Move an item | the item, the new idx | --- |
| remove | Remove the item | the item | --- |
| append | Append an existing (but unused) item | the item | --- |
| 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_colors_namespace | Use prefixed colors from beautiful | the namespace name | --- |
###Signals

View File

@ -283,9 +283,12 @@ local function add_embeded_menu(data,menu)
menu._embeded_parent = data
end
local function add_colors_namespace(data,namespace)
theme.add_colors_from_namespace(data,namespace)
end
local function add_key_binding(data,mod,key,func)
capi.root.keys(util.table.join(capi.root.keys(),aw_key(mod or {}, key, func and func() or function ()
print("bob")
data.visible = not data.visible
end)))
end
@ -369,8 +372,13 @@ local function new(args)
autogen_signals = true,
})
internal.private_data = private_data
-- Methods
data.add_item,data.add_widget,data.add_embeded_menu,data._internal,data.add_key_binding = add_item,add_widget,add_embeded_menu,internal,add_key_binding
data.add_prefix_widget,data.add_suffix_widget,data.add_items,data.add_widgets=add_prefix_widget,add_suffix_widget,add_items,add_widgets
data.add_colors_namespace = add_colors_namespace
-- Load colors
theme.setup_colors(data,args)
-- Getters

View File

@ -102,7 +102,7 @@ function module.layout_item(menu,args)
end
--TODO button 4 and 5
local item = menu:add_item{text=args.text,button1=toggle}
local item = menu:add_item{text=args.text,button1=toggle,tooltip=args.tooltip}
local function update()
local layout = awful.layout.getname(awful.layout.get(screen))

View File

@ -59,7 +59,7 @@ local function index_draw(self,w, cr, width, height)
end
local function create_item(t,s)
local menu,ib,original = instances[s],nil,tag.geticon(t)
local menu,ib,original = instances[s],nil,tag.geticon(t) or beautiful.taglist_default_icon
if not menu or not t then return end
local w = wibox.layout.fixed.horizontal()
if beautiful.taglist_disable_icon ~= true then

View File

@ -82,10 +82,14 @@ local function create_item(item,data,args)
subArrow:set_image( beautiful.menu_submenu_icon )
lr:add(subArrow)
end
bg.fit = function(box,w,h,...)
bg.fit = function(box,w,h)
-- args.y = data.height-h-data.margins.top --TODO dead code?
local f = data._internal.layout.item_fit or wibox.widget.background.fit
return f(data,item,box,w,h)
if data._internal.layout.item_fit then
return data._internal.layout.item_fit(data,item,box,w,h)
else
return wibox.widget.background.fit(box,w,h)
end
return 0,0
end
if item.checkable then
item.get_checked = function(data,item)
@ -116,6 +120,8 @@ local function create_item(item,data,args)
-- Setup events
horizontal.setup_event(data,item,bg)
item.widget = bg
return bg
end

View File

@ -10,6 +10,7 @@ local module = {
local function return_data(tab, key)
return tab._real_table[key]
end
local function change_data(tab, key,value)
if not value and key == rawget(tab,"_current_key") then
-- Loop the array to find a new current_key
@ -33,6 +34,7 @@ local function change_data(tab, key,value)
end
tab._real_table[key] = value
end
function module.init_state(item)
local mt = {__newindex = change_data,__index=return_data}
return setmetatable({_real_table={},_item=item},mt)
@ -74,5 +76,17 @@ function module.setup_item_colors(data,item,args)
end
end
--- Apply a set of background and foreground colors from beautiful to `data`
-- @arg data The menu
-- @arg namespace The beautiful prefix used for that set of values
function module.add_colors_from_namespace(data,namespace)
local priv = data._internal.private_data
for k,v in pairs(theme_colors) do
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["underlay_bg_"..k] = beautiful[namespace.."_underlay_bg_"..v.beautiful_name] or priv["underlay_bg_"..k]
end
end
return setmetatable(module, { __call = function(_, ...) return new(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on;