feat: wire up buttons for tag list
This commit is contained in:
parent
4ac05d48a6
commit
fdcffa9650
@ -3,77 +3,107 @@ local dpi = require("beautiful").xresources.apply_dpi
|
|||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
local clickable_container = require("widget.clickable-container")
|
local clickable_container = require("widget.clickable-container")
|
||||||
|
|
||||||
function list_update(w, buttons, label, data, objects)
|
local capi = {button = _G.button}
|
||||||
-- 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()
|
|
||||||
|
|
||||||
-- All of this is added in a fixed widget
|
function create_buttons(buttons, object)
|
||||||
l:fill_space(true)
|
if buttons then
|
||||||
l:add(ibm)
|
local btns = {}
|
||||||
-- l:add(tbm)
|
for _, b in ipairs(buttons) do
|
||||||
bg_clickable:set_widget(l)
|
-- Create a proxy button object: it will receive the real
|
||||||
|
-- press and release events, and will propagate them to the
|
||||||
-- And all of this gets a background
|
-- button object the user provided, but with the object as
|
||||||
-- bgb:set_widget(l)
|
-- argument.
|
||||||
bgb:set_widget(bg_clickable)
|
local btn = capi.button {modifiers = b.modifiers, button = b.button}
|
||||||
|
btn:connect_signal(
|
||||||
bgb:buttons(common.create_buttons(buttons, o))
|
'press',
|
||||||
|
function()
|
||||||
data[o] = {
|
b:emit_signal('press', object)
|
||||||
ib = ib,
|
|
||||||
tb = tb,
|
|
||||||
bgb = bgb,
|
|
||||||
tbm = tbm,
|
|
||||||
ibm = ibm,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
local text, bg, bg_image, icon, args = label(o, tb)
|
|
||||||
args = args or {}
|
|
||||||
|
|
||||||
-- 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
|
||||||
end
|
)
|
||||||
bgb:set_bg(bg)
|
btn:connect_signal(
|
||||||
if type(bg_image) == "function" then
|
'release',
|
||||||
-- TODO: Why does this pass nil as an argument?
|
function()
|
||||||
bg_image = bg_image(tb,o,nil,objects,i)
|
b:emit_signal('release', object)
|
||||||
end
|
end
|
||||||
bgb:set_bgimage(bg_image)
|
)
|
||||||
if icon then
|
btns[#btns + 1] = btn
|
||||||
ib:set_image(icon)
|
end
|
||||||
else
|
|
||||||
ibm:set_margins(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
bgb.shape = args.shape
|
return btns
|
||||||
bgb.shape_border_width = args.shape_border_width
|
end
|
||||||
bgb.shape_border_color = args.shape_border_color
|
end
|
||||||
|
|
||||||
w:add(bgb)
|
function list_update(w, buttons, label, data, objects)
|
||||||
|
-- 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()
|
||||||
|
|
||||||
|
-- All of this is added in a fixed widget
|
||||||
|
l:fill_space(true)
|
||||||
|
l:add(ibm)
|
||||||
|
-- l:add(tbm)
|
||||||
|
bg_clickable:set_widget(l)
|
||||||
|
|
||||||
|
-- And all of this gets a background
|
||||||
|
-- bgb:set_widget(l)
|
||||||
|
bgb:set_widget(bg_clickable)
|
||||||
|
|
||||||
|
bgb:buttons(create_buttons(buttons, o))
|
||||||
|
|
||||||
|
data[o] = {
|
||||||
|
ib = ib,
|
||||||
|
tb = tb,
|
||||||
|
bgb = bgb,
|
||||||
|
tbm = tbm,
|
||||||
|
ibm = ibm,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local text, bg, bg_image, icon, args = label(o, tb)
|
||||||
|
args = args or {}
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
|
||||||
|
bgb.shape = args.shape
|
||||||
|
bgb.shape_border_width = args.shape_border_width
|
||||||
|
bgb.shape_border_color = args.shape_border_color
|
||||||
|
|
||||||
|
w:add(bgb)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
(local awful (require :awful))
|
(local awful (require :awful))
|
||||||
(local beautiful (require :beautiful))
|
(local beautiful (require :beautiful))
|
||||||
|
(local gears (require :gears))
|
||||||
(local wibox (require :wibox))
|
(local wibox (require :wibox))
|
||||||
(local common (require :awful.widget.common))
|
(local common (require :awful.widget.common))
|
||||||
(local dpi (. (require :beautiful) :xresources :apply_dpi))
|
(local dpi (. (require :beautiful) :xresources :apply_dpi))
|
||||||
|
|
||||||
|
(local button (. (require :lib.keys) :button))
|
||||||
(local std (require :lib.std))
|
(local std (require :lib.std))
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
@ -93,7 +95,11 @@
|
|||||||
(awful.widget.taglist
|
(awful.widget.taglist
|
||||||
s
|
s
|
||||||
awful.widget.taglist.filter.all
|
awful.widget.taglist.filter.all
|
||||||
{}
|
(gears.table.join
|
||||||
|
(button [] 1 (lambda [t] (: t :view_only)))
|
||||||
|
(button [] 3 (lambda [t] (when _G.client.focus (: _G.client.focus :move_to_tag t))))
|
||||||
|
(button [] 4 (lambda [t] (awful.tag.viewnext t.screen)))
|
||||||
|
(button [] 5 (lambda [t] (awful.tag.viewprev t.screen))))
|
||||||
{:font (.. beautiful.font " Bold 10")
|
{:font (.. beautiful.font " Bold 10")
|
||||||
:spacing 2}
|
:spacing 2}
|
||||||
;; update-tag-list
|
;; update-tag-list
|
||||||
|
Loading…
Reference in New Issue
Block a user