2019-01-15 15:14:29 +11:00
|
|
|
local common = require("awful.widget.common")
|
|
|
|
local dpi = require("beautiful").xresources.apply_dpi
|
|
|
|
local wibox = require("wibox")
|
|
|
|
local clickable_container = require("widget.clickable-container")
|
|
|
|
|
2019-01-18 10:30:58 +11:00
|
|
|
local capi = {button = _G.button}
|
|
|
|
|
|
|
|
function create_buttons(buttons, object)
|
|
|
|
if buttons then
|
|
|
|
local btns = {}
|
|
|
|
for _, b in ipairs(buttons) do
|
|
|
|
-- Create a proxy button object: it will receive the real
|
|
|
|
-- press and release events, and will propagate them to the
|
|
|
|
-- button object the user provided, but with the object as
|
|
|
|
-- argument.
|
|
|
|
local btn = capi.button {modifiers = b.modifiers, button = b.button}
|
|
|
|
btn:connect_signal(
|
|
|
|
'press',
|
|
|
|
function()
|
|
|
|
b:emit_signal('press', object)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
btn:connect_signal(
|
|
|
|
'release',
|
|
|
|
function()
|
|
|
|
b:emit_signal('release', object)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
btns[#btns + 1] = btn
|
|
|
|
end
|
|
|
|
|
|
|
|
return btns
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-15 15:14:29 +11:00
|
|
|
function list_update(w, buttons, label, data, objects)
|
2019-01-18 10:30:58 +11:00
|
|
|
-- update the widgets, creating them if needed
|
|
|
|
w:reset()
|
|
|
|
for i, o in ipairs(objects) do
|
|
|
|
local cache = data[o]
|
|
|
|
local ib, tb, bgb, tbm, ibm, l
|
|
|
|
if cache then
|
|
|
|
ib = cache.ib
|
|
|
|
tb = cache.tb
|
|
|
|
bgb = cache.bgb
|
|
|
|
tbm = cache.tbm
|
|
|
|
ibm = cache.ibm
|
|
|
|
else
|
|
|
|
ib = wibox.widget.imagebox()
|
|
|
|
tb = wibox.widget.textbox()
|
|
|
|
bgb = wibox.container.background()
|
|
|
|
tbm = wibox.container.margin(tb, dpi(4), dpi(4))
|
|
|
|
ibm = wibox.container.margin(ib, dpi(10), dpi(8), dpi(8), dpi(8))
|
|
|
|
-- ibm = wibox.container.margin(ib, dpi(4))
|
|
|
|
l = wibox.layout.fixed.horizontal()
|
|
|
|
bg_clickable = clickable_container()
|
2019-01-15 15:14:29 +11:00
|
|
|
|
2019-01-18 10:30:58 +11:00
|
|
|
-- All of this is added in a fixed widget
|
|
|
|
l:fill_space(true)
|
|
|
|
l:add(ibm)
|
|
|
|
-- l:add(tbm)
|
|
|
|
bg_clickable:set_widget(l)
|
2019-01-15 15:14:29 +11:00
|
|
|
|
2019-01-18 10:30:58 +11:00
|
|
|
-- And all of this gets a background
|
|
|
|
-- bgb:set_widget(l)
|
|
|
|
bgb:set_widget(bg_clickable)
|
2019-01-15 15:14:29 +11:00
|
|
|
|
2019-01-18 10:30:58 +11:00
|
|
|
bgb:buttons(create_buttons(buttons, o))
|
2019-01-15 15:14:29 +11:00
|
|
|
|
2019-01-18 10:30:58 +11:00
|
|
|
data[o] = {
|
|
|
|
ib = ib,
|
|
|
|
tb = tb,
|
|
|
|
bgb = bgb,
|
|
|
|
tbm = tbm,
|
|
|
|
ibm = ibm,
|
|
|
|
}
|
|
|
|
end
|
2019-01-15 15:14:29 +11:00
|
|
|
|
2019-01-18 10:30:58 +11:00
|
|
|
local text, bg, bg_image, icon, args = label(o, tb)
|
|
|
|
args = args or {}
|
2019-01-15 15:14:29 +11:00
|
|
|
|
2019-01-18 10:30:58 +11:00
|
|
|
-- The text might be invalid, so use pcall.
|
|
|
|
if text == nil or text == "" then
|
|
|
|
tbm:set_margins(0)
|
|
|
|
else
|
|
|
|
if not tb:set_markup_silently(text) then
|
|
|
|
tb:set_markup("<i><Invalid text></i>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
bgb:set_bg(bg)
|
|
|
|
if type(bg_image) == "function" then
|
|
|
|
-- TODO: Why does this pass nil as an argument?
|
|
|
|
bg_image = bg_image(tb,o,nil,objects,i)
|
|
|
|
end
|
|
|
|
bgb:set_bgimage(bg_image)
|
|
|
|
if icon then
|
|
|
|
ib:set_image(icon)
|
|
|
|
else
|
|
|
|
ibm:set_margins(0)
|
|
|
|
end
|
2019-01-15 15:14:29 +11:00
|
|
|
|
2019-01-18 10:30:58 +11:00
|
|
|
bgb.shape = args.shape
|
|
|
|
bgb.shape_border_width = args.shape_border_width
|
|
|
|
bgb.shape_border_color = args.shape_border_color
|
2019-01-15 15:14:29 +11:00
|
|
|
|
2019-01-18 10:30:58 +11:00
|
|
|
w:add(bgb)
|
2019-01-15 15:14:29 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return list_update
|