{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 pairs = pairs
local setmetatable = setmetatable
local capi = { widget = widget, button = button }
local capi = { button = button }
local layout = require("awful.widget.layout")
local util = require("awful.util")
local imagebox = require("wibox.widget.imagebox")
local textbox = require("wibox.widget.textbox")
local common = {}
-- Private structures
tagwidgets = setmetatable({}, { __mode = 'k' })
-- Recursively processes a template, replacing the tables representing the icon and
-- the title with the widgets ib and 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
t[i] = ib
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
else
replace_in_template(v, ib, tb)
@ -39,7 +34,7 @@ local function replace_in_template(t, ib, tb)
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,
-- it's w.len since __len meta does not work on table until Lua 5.2.
-- Otherwise it's standard #w.
@ -53,24 +48,22 @@ function common.list_update(w, buttons, label, data, template, objects)
end
-- update the widgets, creating them if needed
w:reset()
for i, o in ipairs(objects) do
local ib, tb
if w[i] then
ib = w[i].icon
tb = w[i].title
else
ib = capi.widget({ type = "imagebox" })
tb = capi.widget({ type = "textbox" })
w[i] = util.table.clone(template)
replace_in_template(w[i], ib, tb)
w[i].icon = ib
w[i].title = tb
if type(o) == "tag" then
tagwidgets[ib] = o
tagwidgets[tb] = o
end
end
local ib, tb, bgb, l
ib = wibox.widget.imagebox()
tb = wibox.widget.textbox()
bgb = wibox.widget.background()
local m = wibox.layout.margin()
m:set_left(4)
m:set_right(4)
m:set_widget(tb)
bgb:set_widget(m)
l = wibox.layout.fixed.horizontal()
l:fill_space(true)
l:add(ib)
l:add(bgb)
w:add(l)
if buttons then
-- 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
end
end
ib:buttons(btns)
tb:buttons(btns)
l:buttons(btns)
end
local text, bg, bg_image, icon = label(o)
tb.text, tb.bg, tb.bg_image = text, bg, bg_image
ib.bg, ib.image = bg, icon
if not tb.text then
tb.visible = false
else
tb.visible = true
end
if not ib.image then
ib.visible = false
else
ib.visible = true
end
tb:set_markup(text)
bgb:set_bg(bg)
bgb:set_bgimage(bg_image)
ib:set_image(icon)
end
end

View File

@ -18,7 +18,7 @@ local common = require("awful.widget.common")
local util = require("awful.util")
local tag = require("awful.tag")
local beautiful = require("beautiful")
local layout = require("awful.widget.layout")
local flex = require("wibox.layout.flex")
--- Taglist widget module for awful
module("awful.widget.taglist")
@ -94,7 +94,7 @@ function taglist_label(t, args)
return text, bg_color, bg_image, icon
end
local function taglist_update(s, w, buttons, filter, data, style, template)
local function taglist_update(s, w, buttons, filter, data, style)
local tags = {}
for k, t in ipairs(capi.screen[s]:tags()) do
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
common.list_update(w, buttons, label, data, template, tags)
common.list_update(w, buttons, label, data, tags)
end
--- 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_resize Optional: true or false to resize squares.
-- font The font.
-- @param template The template to use for each item.
-- The default template:<br/>
-- <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
}
function new(screen, filter, buttons, style)
local w = flex.horizontal()
local data = setmetatable({}, { __mode = 'vk' })
local u = function (s)
if s == screen then
taglist_update(s, w, buttons, filter, data, style, template)
taglist_update(s, w, buttons, filter, data, style)
end
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 util = require("awful.util")
local tag = require("awful.tag")
local layout = require("awful.widget.layout")
local flex = require("wibox.layout.flex")
--- Tasklist widget module for awful
module("awful.widget.tasklist")
@ -64,7 +64,7 @@ local function tasklist_label(c, args)
return text, bg, nil, c.icon
end
local function tasklist_update(s, w, buttons, filter, data, style, template)
local function tasklist_update(s, w, buttons, filter, data, style)
local clients = {}
for k, c in ipairs(capi.client.get()) do
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
common.list_update(w, buttons, label, data, template, clients)
common.list_update(w, buttons, label, data, clients)
end
--- Create a new tasklist widget.
@ -92,47 +92,11 @@ end
-- fg_minimize The foreground color for minimized clients.
-- floating_icon The icon for flating clients.
-- font The font.
-- @param template The template to use for each item.
-- The default template:<br/>
-- <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
}
function new(screen, filter, buttons, style)
local w = flex.horizontal()
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)
tag.attached_connect_signal(screen, "property::selected", u)
capi.client.connect_signal("property::urgent", u)