1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2008-2009 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 -- Grab environment we need
12 local setmetatable
= setmetatable
13 local capi
= { button
= button
}
14 local layout
= require("awful.widget.layout")
15 local util
= require("awful.util")
16 local imagebox
= require("wibox.widget.imagebox")
17 local textbox
= require("wibox.widget.textbox")
21 -- Recursively processes a template, replacing the tables representing the icon and
22 -- the title with the widgets ib and tb
23 local function replace_in_template(t
, ib
, tb
)
24 for i
, v
in ipairs(t
) do
25 if type(t
[i
]) == "table" then
26 if v
.item
== "icon" then
28 elseif v
.item
== "title" then
31 replace_in_template(v
, ib
, tb
)
37 function common
.list_update(w
, buttons
, label
, data
, objects
)
38 -- Hack: if it has been registered as a widget in a wibox,
39 -- it's w.len since __len meta does not work on table until Lua 5.2.
40 -- Otherwise it's standard #w.
41 local len
= (w
.len
or #w
)
43 -- Remove excessive widgets
44 if len
> #objects
then
45 for i
= #objects
, len
do
50 -- update the widgets, creating them if needed
52 for i
, o
in ipairs(objects
) do
53 local ib
= wibox
.widget
.imagebox()
54 local tb
= wibox
.widget
.textbox()
55 local bgb
= wibox
.widget
.background()
56 local m
= wibox
.layout
.margin()
57 local l
= wibox
.layout
.fixed
.horizontal()
59 -- The textbox gets a margin to look better
64 -- All of this is added in a fixed widget
69 -- And all of this gets a background
74 -- Use a local variable so that the garbage collector doesn't strike
75 -- between now and the :buttons() call.
80 for kb
, b
in ipairs(buttons
) do
81 -- Create a proxy button object: it will receive the real
82 -- press and release events, and will propagate them the the
83 -- button object the user provided, but with the object as
85 local btn
= capi
.button
{ modifiers
= b
.modifiers
, button
= b
.button
}
86 btn
:connect_signal("press", function () b
:emit_signal("press", o
) end)
87 btn
:connect_signal("release", function () b
:emit_signal("release", o
) end)
94 local text
, bg
, bg_image
, icon
= label(o
)
97 bgb
:set_bgimage(bg_image
)
104 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80