From 1257ac228eeaf567a0119f398751b83b5bafd89d Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 30 Dec 2014 17:27:57 -0500 Subject: [PATCH] Add a color namespace helper method This will allow implementations to use their own colors without redefining them by hand --- README.md | 39 ++++++++++++++++++++------------------- base.lua | 10 +++++++++- impl/common/tag.lua | 2 +- impl/taglist/init.lua | 2 +- item/layout/icon.lua | 12 +++++++++--- theme/init.lua | 14 ++++++++++++++ 6 files changed, 54 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 8ba80e9..fa67748 100644 --- a/README.md +++ b/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 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 diff --git a/base.lua b/base.lua index 5a72ce4..94dfcb9 100644 --- a/base.lua +++ b/base.lua @@ -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 diff --git a/impl/common/tag.lua b/impl/common/tag.lua index bd6f9e9..67e93f5 100644 --- a/impl/common/tag.lua +++ b/impl/common/tag.lua @@ -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)) diff --git a/impl/taglist/init.lua b/impl/taglist/init.lua index 43e6e19..693511d 100644 --- a/impl/taglist/init.lua +++ b/impl/taglist/init.lua @@ -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 diff --git a/item/layout/icon.lua b/item/layout/icon.lua index 66f4705..ecdd510 100644 --- a/item/layout/icon.lua +++ b/item/layout/icon.lua @@ -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) @@ -115,6 +119,8 @@ local function create_item(item,data,args) -- Setup events horizontal.setup_event(data,item,bg) + + item.widget = bg return bg end diff --git a/theme/init.lua b/theme/init.lua index 9eb4bbd..2ff37a0 100644 --- a/theme/init.lua +++ b/theme/init.lua @@ -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; \ No newline at end of file