From e1656169a296147f8cdf09114da0d2536420e358 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 1 Apr 2014 23:42:02 -0400 Subject: [PATCH] Add partial support for taglist extensions (issue #25) --- impl/taglist/extensions.lua | 108 ++++++++++++++++++++++++++++++++++++ impl/taglist/init.lua | 19 ++++++- impl/taglist/tag_menu.lua | 4 ++ impl/taglist/tracker.lua | 2 +- 4 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 impl/taglist/extensions.lua diff --git a/impl/taglist/extensions.lua b/impl/taglist/extensions.lua new file mode 100644 index 0000000..112399f --- /dev/null +++ b/impl/taglist/extensions.lua @@ -0,0 +1,108 @@ +-- This file provide extensions + +local capi = { screen = screen, client=client} +local setmetatable = setmetatable +local ipairs,pairs = ipairs,pairs +local type = type +local radical = require( "radical" ) +local beautiful = require( "beautiful" ) +local awful = require( "awful" ) +local util = require( "awful.util" ) +local wibox = require( "wibox" ) +local taglist = nil + +local module = {} + +local current_client = nil + +local classes = {} +local global = {} + +local extension_list = {} + +local per_m,per_glob,per_this = nil +local function persistence_menu(ext) + if not taglist then + taglist = require("radical.impl.taglist") + end + if not per_m then + per_m = radical.context{} + per_glob = per_m:add_item{text= "All clients" ,checkable = true , button1 = function() + local i1 = taglist.item(current_client) + if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then + i1:add_suffix(ext(current_client)) + i1._internal.has_widget = i1._internal.has_widget or {} + i1._internal.has_widget[ext] = true + end + for k,v in ipairs(capi.client.get()) do + local i2 = taglist.item(v) + if i2 and (not i2._internal.has_widget or not i2._internal.has_widget[ext]) then + i2:add_suffix(ext(v)) + i2._internal.has_widget = i2._internal.has_widget or {} + i2._internal.has_widget[ext] = true + end + end + per_glob.checked = true + end} + per_this = per_m:add_item{text= "This client only" ,checkable = true, button1 = function() + local i1 = taglist.item(current_client) + if i1 and (not i1._internal.has_widget or not i1._internal.has_widget[ext]) then + i1:add_suffix(ext(current_client)) + i1._internal.has_widget = i1._internal.has_widget or {} + i1._internal.has_widget[ext] = true + end + per_this.checked = true + end} + end + + -- Check the checkboxes + local i1 = taglist.item(current_client) + if global[ext] then + per_glob.checked = true + per_this.checked = false + elseif classes[ext] and classes[ext][current_client.class] then + per_this.checked = false + per_glob.checked = false + elseif i1 and i1._internal.has_widget and i1._internal.has_widget[ext] then + per_this.checked = true + per_glob.checked = false + else + per_this.checked = false + per_glob.checked = false + end + + return per_m +end + +local ext_list_m = nil +local function extension_list_menu() + if not ext_list_m then + ext_list_m = radical.context{} + for k,v in pairs(extension_list) do + ext_list_m:add_item{text=k,sub_menu=function() return persistence_menu(v) end} + end + end + return ext_list_m +end + +local ext_m = nil +function module.extensions_menu(c) + current_client = c + if not ext_m then + ext_m = radical.context{} + ext_m:add_item{text="Overlay widget", sub_menu=extension_list_menu() } + ext_m:add_item{text="Prefix widget" , sub_menu=extension_list_menu() } + ext_m:add_item{text="Suffix widget" , sub_menu=extension_list_menu() } + end + return ext_m +end + +function module.add(name,f) + extension_list[name] = f + if ext_list_m then + ext_list_m:add_item{text=name,sub_menu=function() return persistence_menu(f) end} + 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 diff --git a/impl/taglist/init.lua b/impl/taglist/init.lua index 978a318..6da1627 100644 --- a/impl/taglist/init.lua +++ b/impl/taglist/init.lua @@ -34,7 +34,7 @@ local cache = setmetatable({}, { __mode = 'k' }) module.buttons = { [1] = awful.tag.viewonly, [2] = awful.tag.viewtoggle, [3] = function(q,w,e,r) - local menu = tag_menu() + local menu = tag_menu(q) menu.visible = true end, [4] = function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end, @@ -66,11 +66,21 @@ local function create_item(t,s) local index = tag.getidx(t) tw:set_markup(" "..(index).." ") w:add(tw) - local item = menu:add_item { text = t.name, prefix_widget = w} + local suf_w = wibox.layout.fixed.horizontal() + local item = menu:add_item { text = t.name, prefix_widget = w,suffix_widget=suf_w} item._internal.icon_w = ib -- item:connect_signal("index::changed",function(_,value) -- tw:set_markup(" "..(index).." ") -- end) + + item.add_suffix = function(_,w2) + suf_w:add(w2) + end + item.add_prefix = function(_,w2) + w:add(w2) + end + + item.tw = tw if tag.getproperty(t,"clone_of") then @@ -216,7 +226,6 @@ local function new(s) args["bg_"..v] = beautiful["taglist_bg_"..v] args["fg_"..v] = beautiful["taglist_fg_"..v] end - print("THAT",beautiful.taglist_bg_highlight) instances[s] = radical.bar(args) @@ -252,6 +261,10 @@ capi.tag.connect_signal("property::index2",function(t,i) end end) +function module.item(t) + return cache[t] +end + return setmetatable(module, { __call = function(_, ...) return new(...) end }) -- kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/impl/taglist/tag_menu.lua b/impl/taglist/tag_menu.lua index 27d1837..5a2e709 100644 --- a/impl/taglist/tag_menu.lua +++ b/impl/taglist/tag_menu.lua @@ -7,6 +7,7 @@ local menu = require( "radical.context" ) local com_tag = require( "radical.impl.common.tag" ) local awful = require("awful") local radical = require("radical") +local extensions = require("radical.impl.taglist.extensions") local capi = { screen = screen } local module = {} @@ -78,6 +79,9 @@ local function new(t) aTagMenu:add_item({text= "Flags", sub_menu = function() + end}) + aTagMenu:add_item({text= "Add widgets", sub_menu = function() + return extensions.extensions_menu(aTag) end}) return aTagMenu end diff --git a/impl/taglist/tracker.lua b/impl/taglist/tracker.lua index 7852588..943647e 100644 --- a/impl/taglist/tracker.lua +++ b/impl/taglist/tracker.lua @@ -20,7 +20,7 @@ local function reload(t,s) local new_tags = tag.gettags(s) for k,v in ipairs(new_tags) do if v ~= old_tags[k] then - print(v.name,k,s,tag.getscreen(v),tag.getidx(v)) +-- print(v.name,k,s,tag.getscreen(v),tag.getidx(v)) v:emit_signal("property::index2",k) screen_cache[v] = s end