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:
parent
7b071fb7d1
commit
1257ac228e
39
README.md
39
README.md
|
@ -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
|
All menus provide a bunch of methods. Most of them have been coverred above, but
|
||||||
here is the list:
|
here is the list:
|
||||||
|
|
||||||
| Name | Description | Arguments | Return |
|
| Name | Description | Arguments | Return |
|
||||||
| ----------------- | -------------------------------------------- | --------------------- | ------ |
|
| -------------------- | -------------------------------------------- | --------------------- | ------ |
|
||||||
| add_item | Add new item to a menu | array of options | item |
|
| 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_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_widget | Add a new widget instead of an item | a widget, args | --- |
|
||||||
| add_widgets | Add new widgets | array of widgets | --- |
|
| add_widgets | Add new widgets | array of widgets | --- |
|
||||||
| add_embeded_menu | Add an inline menu to another menu | an "embed" menu | --- |
|
| 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_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 | --- |
|
| add_key_hook | Add a callback when a key is pressed | mod, key, event, func | --- |
|
||||||
| clear | Remove all items | --- | --- |
|
| clear | Remove all items | --- | --- |
|
||||||
| scroll_down | If the menu is cropped, scroll down | --- | --- |
|
| scroll_down | If the menu is cropped, scroll down | --- | --- |
|
||||||
| scroll_up | If the menu is cropped, scroll up | --- | --- |
|
| scroll_up | If the menu is cropped, scroll up | --- | --- |
|
||||||
| hide | Hide a menu and all sub menus | --- | --- |
|
| hide | Hide a menu and all sub menus | --- | --- |
|
||||||
| swap | Swap 2 items | both items | --- |
|
| swap | Swap 2 items | both items | --- |
|
||||||
| move | Move an item | the item, the new idx | --- |
|
| move | Move an item | the item, the new idx | --- |
|
||||||
| remove | Remove the item | the item | --- |
|
| remove | Remove the item | the item | --- |
|
||||||
| append | Append an existing (but unused) 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_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 | --- |
|
||||||
|
|
||||||
|
|
||||||
###Signals
|
###Signals
|
||||||
|
|
10
base.lua
10
base.lua
|
@ -283,9 +283,12 @@ local function add_embeded_menu(data,menu)
|
||||||
menu._embeded_parent = data
|
menu._embeded_parent = data
|
||||||
end
|
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)
|
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 ()
|
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
|
data.visible = not data.visible
|
||||||
end)))
|
end)))
|
||||||
end
|
end
|
||||||
|
@ -369,8 +372,13 @@ local function new(args)
|
||||||
autogen_signals = true,
|
autogen_signals = true,
|
||||||
})
|
})
|
||||||
internal.private_data = private_data
|
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_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_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)
|
theme.setup_colors(data,args)
|
||||||
|
|
||||||
-- Getters
|
-- Getters
|
||||||
|
|
|
@ -102,7 +102,7 @@ function module.layout_item(menu,args)
|
||||||
end
|
end
|
||||||
|
|
||||||
--TODO button 4 and 5
|
--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 function update()
|
||||||
local layout = awful.layout.getname(awful.layout.get(screen))
|
local layout = awful.layout.getname(awful.layout.get(screen))
|
||||||
|
|
|
@ -59,7 +59,7 @@ local function index_draw(self,w, cr, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_item(t,s)
|
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
|
if not menu or not t then return end
|
||||||
local w = wibox.layout.fixed.horizontal()
|
local w = wibox.layout.fixed.horizontal()
|
||||||
if beautiful.taglist_disable_icon ~= true then
|
if beautiful.taglist_disable_icon ~= true then
|
||||||
|
|
|
@ -82,10 +82,14 @@ local function create_item(item,data,args)
|
||||||
subArrow:set_image( beautiful.menu_submenu_icon )
|
subArrow:set_image( beautiful.menu_submenu_icon )
|
||||||
lr:add(subArrow)
|
lr:add(subArrow)
|
||||||
end
|
end
|
||||||
bg.fit = function(box,w,h,...)
|
bg.fit = function(box,w,h)
|
||||||
-- args.y = data.height-h-data.margins.top --TODO dead code?
|
-- args.y = data.height-h-data.margins.top --TODO dead code?
|
||||||
local f = data._internal.layout.item_fit or wibox.widget.background.fit
|
if data._internal.layout.item_fit then
|
||||||
return f(data,item,box,w,h)
|
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
|
end
|
||||||
if item.checkable then
|
if item.checkable then
|
||||||
item.get_checked = function(data,item)
|
item.get_checked = function(data,item)
|
||||||
|
@ -115,6 +119,8 @@ local function create_item(item,data,args)
|
||||||
|
|
||||||
-- Setup events
|
-- Setup events
|
||||||
horizontal.setup_event(data,item,bg)
|
horizontal.setup_event(data,item,bg)
|
||||||
|
|
||||||
|
item.widget = bg
|
||||||
|
|
||||||
return bg
|
return bg
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ local module = {
|
||||||
local function return_data(tab, key)
|
local function return_data(tab, key)
|
||||||
return tab._real_table[key]
|
return tab._real_table[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function change_data(tab, key,value)
|
local function change_data(tab, key,value)
|
||||||
if not value and key == rawget(tab,"_current_key") then
|
if not value and key == rawget(tab,"_current_key") then
|
||||||
-- Loop the array to find a new current_key
|
-- Loop the array to find a new current_key
|
||||||
|
@ -33,6 +34,7 @@ local function change_data(tab, key,value)
|
||||||
end
|
end
|
||||||
tab._real_table[key] = value
|
tab._real_table[key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
function module.init_state(item)
|
function module.init_state(item)
|
||||||
local mt = {__newindex = change_data,__index=return_data}
|
local mt = {__newindex = change_data,__index=return_data}
|
||||||
return setmetatable({_real_table={},_item=item},mt)
|
return setmetatable({_real_table={},_item=item},mt)
|
||||||
|
@ -74,5 +76,17 @@ function module.setup_item_colors(data,item,args)
|
||||||
end
|
end
|
||||||
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 })
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
||||||
-- kate: space-indent on; indent-width 2; replace-tabs on;
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|
Loading…
Reference in New Issue