1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2008-2009 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 -- Grab environment we need
13 local setmetatable
= setmetatable
14 local capi
= { button
= button
}
15 local util
= require("awful.util")
16 local wibox
= require("wibox")
17 local imagebox
= require("wibox.widget.imagebox")
18 local textbox
= require("wibox.widget.textbox")
20 --- Common utilities for awful widgets
23 -- Recursively processes a template, replacing the tables representing the icon and
24 -- the title with the widgets ib and tb
25 local function replace_in_template(t
, ib
, tb
)
26 for i
, v
in ipairs(t
) do
27 if type(t
[i
]) == "table" then
28 if v
.item
== "icon" then
30 elseif v
.item
== "title" then
33 replace_in_template(v
, ib
, tb
)
39 function common
.list_update(w
, buttons
, label
, data
, objects
)
40 -- update the widgets, creating them if needed
42 for i
, o
in ipairs(objects
) do
44 local ib
, tb
, bgb
, m
, l
50 ib
= wibox
.widget
.imagebox()
51 tb
= wibox
.widget
.textbox()
52 bgb
= wibox
.widget
.background()
53 m
= wibox
.layout
.margin(tb
, 4, 4)
54 l
= wibox
.layout
.fixed
.horizontal()
56 -- All of this is added in a fixed widget
61 -- And all of this gets a background
66 for kb
, b
in ipairs(buttons
) do
67 -- Create a proxy button object: it will receive the real
68 -- press and release events, and will propagate them the the
69 -- button object the user provided, but with the object as
71 local btn
= capi
.button
{ modifiers
= b
.modifiers
, button
= b
.button
}
72 btn
:connect_signal("press", function () b
:emit_signal("press", o
) end)
73 btn
:connect_signal("release", function () b
:emit_signal("release", o
) end)
86 local text
, bg
, bg_image
, icon
= label(o
)
87 -- The text might be invalid, so use pcall
88 if not pcall(tb
.set_markup
, tb
, text
) then
89 tb
:set_markup("<i><Invalid text></i>")
92 bgb
:set_bgimage(bg_image
)
100 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80