{task,tag}list: Port to new widget system

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-10-06 14:23:36 +02:00
parent 05c49a3a2b
commit 97ed5e70b8
3 changed files with 36 additions and 116 deletions

View File

@ -10,15 +10,14 @@ local type = type
local ipairs = ipairs local ipairs = ipairs
local pairs = pairs local pairs = pairs
local setmetatable = setmetatable local setmetatable = setmetatable
local capi = { widget = widget, button = button } local capi = { button = button }
local layout = require("awful.widget.layout") local layout = require("awful.widget.layout")
local util = require("awful.util") local util = require("awful.util")
local imagebox = require("wibox.widget.imagebox")
local textbox = require("wibox.widget.textbox")
local common = {} local common = {}
-- Private structures
tagwidgets = setmetatable({}, { __mode = 'k' })
-- Recursively processes a template, replacing the tables representing the icon and -- Recursively processes a template, replacing the tables representing the icon and
-- the title with the widgets ib and tb -- the title with the widgets ib and tb
local function replace_in_template(t, ib, tb) local function replace_in_template(t, ib, tb)
@ -27,10 +26,6 @@ local function replace_in_template(t, ib, tb)
if v.item == "icon" then if v.item == "icon" then
t[i] = ib t[i] = ib
elseif v.item == "title" then elseif v.item == "title" then
tb.align = v.align or "left"
tb:margin(v.margin or {})
tb.bg_resize = v.bg_resize or false
tb.bg_align = v.bg_align or ""
t[i] = tb t[i] = tb
else else
replace_in_template(v, ib, tb) replace_in_template(v, ib, tb)
@ -39,7 +34,7 @@ local function replace_in_template(t, ib, tb)
end end
end end
function common.list_update(w, buttons, label, data, template, objects) function common.list_update(w, buttons, label, data, objects)
-- Hack: if it has been registered as a widget in a wibox, -- Hack: if it has been registered as a widget in a wibox,
-- it's w.len since __len meta does not work on table until Lua 5.2. -- it's w.len since __len meta does not work on table until Lua 5.2.
-- Otherwise it's standard #w. -- Otherwise it's standard #w.
@ -53,24 +48,22 @@ function common.list_update(w, buttons, label, data, template, objects)
end end
-- update the widgets, creating them if needed -- update the widgets, creating them if needed
w:reset()
for i, o in ipairs(objects) do for i, o in ipairs(objects) do
local ib, tb local ib, tb, bgb, l
if w[i] then ib = wibox.widget.imagebox()
ib = w[i].icon tb = wibox.widget.textbox()
tb = w[i].title bgb = wibox.widget.background()
else local m = wibox.layout.margin()
ib = capi.widget({ type = "imagebox" }) m:set_left(4)
tb = capi.widget({ type = "textbox" }) m:set_right(4)
w[i] = util.table.clone(template) m:set_widget(tb)
replace_in_template(w[i], ib, tb) bgb:set_widget(m)
w[i].icon = ib l = wibox.layout.fixed.horizontal()
w[i].title = tb l:fill_space(true)
l:add(ib)
if type(o) == "tag" then l:add(bgb)
tagwidgets[ib] = o w:add(l)
tagwidgets[tb] = o
end
end
if buttons then if buttons then
-- Use a local variable so that the garbage collector doesn't strike -- Use a local variable so that the garbage collector doesn't strike
@ -90,23 +83,14 @@ function common.list_update(w, buttons, label, data, template, objects)
btns[#btns + 1] = btn btns[#btns + 1] = btn
end end
end end
ib:buttons(btns) l:buttons(btns)
tb:buttons(btns)
end end
local text, bg, bg_image, icon = label(o) local text, bg, bg_image, icon = label(o)
tb.text, tb.bg, tb.bg_image = text, bg, bg_image tb:set_markup(text)
ib.bg, ib.image = bg, icon bgb:set_bg(bg)
if not tb.text then bgb:set_bgimage(bg_image)
tb.visible = false ib:set_image(icon)
else
tb.visible = true
end
if not ib.image then
ib.visible = false
else
ib.visible = true
end
end end
end end

View File

@ -18,7 +18,7 @@ local common = require("awful.widget.common")
local util = require("awful.util") local util = require("awful.util")
local tag = require("awful.tag") local tag = require("awful.tag")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local layout = require("awful.widget.layout") local flex = require("wibox.layout.flex")
--- Taglist widget module for awful --- Taglist widget module for awful
module("awful.widget.taglist") module("awful.widget.taglist")
@ -94,7 +94,7 @@ function taglist_label(t, args)
return text, bg_color, bg_image, icon return text, bg_color, bg_image, icon
end end
local function taglist_update(s, w, buttons, filter, data, style, template) local function taglist_update(s, w, buttons, filter, data, style)
local tags = {} local tags = {}
for k, t in ipairs(capi.screen[s]:tags()) do for k, t in ipairs(capi.screen[s]:tags()) do
if not tag.getproperty(t, "hide") and filter(t) then if not tag.getproperty(t, "hide") and filter(t) then
@ -104,7 +104,7 @@ local function taglist_update(s, w, buttons, filter, data, style, template)
local function label(c) return taglist_label(c, style) end local function label(c) return taglist_label(c, style) end
common.list_update(w, buttons, label, data, template, tags) common.list_update(w, buttons, label, data, tags)
end end
--- Get the tag object the given widget appears on. --- Get the tag object the given widget appears on.
@ -127,41 +127,13 @@ end
-- squares_unsel Optional: a user provided image for unselected squares. -- squares_unsel Optional: a user provided image for unselected squares.
-- squares_resize Optional: true or false to resize squares. -- squares_resize Optional: true or false to resize squares.
-- font The font. -- font The font.
-- @param template The template to use for each item. function new(screen, filter, buttons, style)
-- The default template:<br/> local w = flex.horizontal()
-- <code>
--{<br/>
--&nbsp; {<br/>
--&nbsp; &nbsp; item = "icon"<br/>
--&nbsp; },<br/>
--&nbsp; {<br/>
--&nbsp; &nbsp; item = "title",<br/>
--&nbsp; &nbsp; bg_resize = true,<br/>
--&nbsp; },<br/>
--&nbsp; layout = layout.horizontal.leftright<br/>
--}<br/>
-- </code>
function new(screen, filter, buttons, style, template)
local w = {
layout = layout.horizontal.leftright
}
template = template or {
{
item = "icon"
},
{
item = "title",
margin = { left = 4, right = 4 },
bg_resize = true,
},
layout = layout.horizontal.leftright
}
local data = setmetatable({}, { __mode = 'vk' }) local data = setmetatable({}, { __mode = 'vk' })
local u = function (s) local u = function (s)
if s == screen then if s == screen then
taglist_update(s, w, buttons, filter, data, style, template) taglist_update(s, w, buttons, filter, data, style)
end end
end end
local uc = function (c) return u(c.screen) end local uc = function (c) return u(c.screen) end

View File

@ -15,7 +15,7 @@ local beautiful = require("beautiful")
local client = require("awful.client") local client = require("awful.client")
local util = require("awful.util") local util = require("awful.util")
local tag = require("awful.tag") local tag = require("awful.tag")
local layout = require("awful.widget.layout") local flex = require("wibox.layout.flex")
--- Tasklist widget module for awful --- Tasklist widget module for awful
module("awful.widget.tasklist") module("awful.widget.tasklist")
@ -64,7 +64,7 @@ local function tasklist_label(c, args)
return text, bg, nil, c.icon return text, bg, nil, c.icon
end end
local function tasklist_update(s, w, buttons, filter, data, style, template) local function tasklist_update(s, w, buttons, filter, data, style)
local clients = {} local clients = {}
for k, c in ipairs(capi.client.get()) do for k, c in ipairs(capi.client.get()) do
if not (c.skip_taskbar or c.hidden if not (c.skip_taskbar or c.hidden
@ -76,7 +76,7 @@ local function tasklist_update(s, w, buttons, filter, data, style, template)
local function label(c) return tasklist_label(c, style) end local function label(c) return tasklist_label(c, style) end
common.list_update(w, buttons, label, data, template, clients) common.list_update(w, buttons, label, data, clients)
end end
--- Create a new tasklist widget. --- Create a new tasklist widget.
@ -92,47 +92,11 @@ end
-- fg_minimize The foreground color for minimized clients. -- fg_minimize The foreground color for minimized clients.
-- floating_icon The icon for flating clients. -- floating_icon The icon for flating clients.
-- font The font. -- font The font.
-- @param template The template to use for each item. function new(screen, filter, buttons, style)
-- The default template:<br/> local w = flex.horizontal()
-- <code>
-- {<br/>
-- &nbsp; {<br/>
-- &nbsp; &nbsp; item = "icon"<br/>
-- &nbsp; },<br/>
-- &nbsp; {<br/>
-- &nbsp; &nbsp; {<br/>
-- &nbsp; &nbsp; &nbsp; item = "title",<br/>
-- &nbsp; &nbsp; &nbsp; margin = { left = 2, right = 2 },<br/>
-- &nbsp; &nbsp; &nbsp; bg_resize = true,<br/>
-- &nbsp; &nbsp; &nbsp; bg_align = "right"<br/>
-- &nbsp; &nbsp; },<br/>
-- &nbsp; &nbsp; layout = layout.horizontal.flex<br/>
-- &nbsp; },<br/>
-- &nbsp; layout = layout.horizontal.leftright<br/>
-- }<br/>
-- </code>
function new(screen, filter, buttons, style, template)
local w = {
layout = layout.horizontal.flex
}
template = template or {
{
item = "icon"
},
{
{
item = "title",
margin = { left = 2, right = 2 },
bg_resize = true,
bg_align = "right"
},
layout = layout.horizontal.flex
},
layout = layout.horizontal.leftright
}
local data = setmetatable({}, { __mode = 'kv' }) local data = setmetatable({}, { __mode = 'kv' })
local u = function () tasklist_update(screen, w, buttons, filter, data, style, template) end local u = function () tasklist_update(screen, w, buttons, filter, data, style) end
capi.screen[screen]:connect_signal("tag::detach", u) capi.screen[screen]:connect_signal("tag::detach", u)
tag.attached_connect_signal(screen, "property::selected", u) tag.attached_connect_signal(screen, "property::selected", u)
capi.client.connect_signal("property::urgent", u) capi.client.connect_signal("property::urgent", u)