awful.widget: store buttons in tasklist

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-12-04 20:20:16 +01:00
parent b0090950a0
commit f36cb984e3
1 changed files with 73 additions and 64 deletions

View File

@ -8,6 +8,7 @@
local ipairs = ipairs
local pairs = pairs
local table = table
local otable = otable
local capi =
{
screen = screen,
@ -159,12 +160,7 @@ function taglist.label.noempty(t, args)
end
end
--- Create a new tasklist widget.
-- @param label Label function to use.
-- @param buttons A table with buttons binding to set.
function tasklist.new(label, buttons)
local w = {}
local function tasklist_update ()
local function tasklist_update(w, buttons, label, data)
local clients = capi.client.get()
local shownclients = {}
for k, c in ipairs(clients) do
@ -194,16 +190,19 @@ function tasklist.new(label, buttons)
-- Update widgets text
for k = 1, #clients * 2, 2 do
if buttons then
local c = clients[(k + 1) / 2]
if not data[c] then
data[c] = {}
-- Replace press function by a new one calling with tags as
-- argument
local mbuttons = {}
for kb, b in ipairs(buttons) do
-- Copy object
mbuttons[kb] = capi.button(b)
mbuttons[kb].press = function () b.press(clients[(k + 1) / 2]) end
data[c][kb] = capi.button(b)
data[c][kb].press = function () b.press(c) end
end
w[k]:buttons(mbuttons)
w[k + 1]:buttons(mbuttons)
end
w[k]:buttons(data[c])
w[k + 1]:buttons(data[c])
end
w[k + 1].text, w[k].bg = label(clients[(k + 1) / 2])
if w[k + 1].text then
@ -221,21 +220,31 @@ function tasklist.new(label, buttons)
end
end
end
hooks.arrange.register(tasklist_update)
hooks.clients.register(tasklist_update)
hooks.tagged.register(tasklist_update)
hooks.focus.register(tasklist_update)
hooks.unfocus.register(tasklist_update)
--- Create a new tasklist widget.
-- @param label Label function to use.
-- @param buttons A table with buttons binding to set.
function tasklist.new(label, buttons)
local w = {}
local data = otable()
local u = function () tasklist_update(w, buttons, label, data) end
hooks.arrange.register(u)
hooks.clients.register(u)
hooks.tagged.register(u)
hooks.focus.register(u)
hooks.unfocus.register(u)
hooks.property.register(function (c, prop)
if prop == "urgent"
or prop == "floating"
or prop == "icon"
or prop == "name"
or prop == "icon_name" then
tasklist_update()
u()
end
end)
tasklist_update()
u()
-- Free data on unmanage
hooks.unmanage.register(function (c) data[c] = nil end)
return w
end