fix widget updating, make all the picturebuttons go through one function and not define their own .buttons table

This commit is contained in:
Izaya 2022-09-12 15:45:22 +10:00
parent 39012655b9
commit 219324add9
1 changed files with 57 additions and 49 deletions

106
init.lua
View File

@ -40,10 +40,6 @@ function switcherpopup.new(s)
}
})
function clock.update(self)
local naughty = require("naughty")
for k,v in ipairs(self.widget.children[1]) do
naughty.notify({text=tostring(k)..": "..tostring(v.text)})
end
self.widget.children[1].markup = string.format('<span size="xx-large">%s</span>',os.date("%H:%M"))
self.widget.children[2].markup = os.date("%Y-%m-%d")
end
@ -56,7 +52,7 @@ function switcherpopup.new(s)
local function updateSwitcherpopup()
clock:update()
tagindex.markup = '<span size="xx-large" color="'..tostring(beautiful.bg_normal)..'">'..tostring(awful.screen.focused().selected_tag.name)..'</span>'
for k,v in ipairs(indicators) do
for k,v in ipairs(indicators.children) do
pcall(v.update, v)
end
tasklistWidget:reset()
@ -88,73 +84,78 @@ function switcherpopup.new(s)
end
end
screen.connect_signal("arrange",updateSwitcherpopup)
local function pictureButton(icon,text,fn,lfn)
local updateTimer = gears.timer{
timeout = 60,
callback = updateSwitcherpopup
}
local function pictureButton(icon,fn,lfn)
local rc = wibox.container.constraint(wibox.widget({
widget=wibox.widget.imagebox,
forced_width = switcherpopup.buttonSize,
forced_height = switcherpopup.buttonSize,
image = switcherpopup.iconPath .. "/" .. icon
}),nil,switcherpopup.buttonSize,switcherpopup.buttonSize)
longpress.add(rc,fn,lfn)
return wibox.container.place(rc)
end
local close_button = pictureButton("window-close.svg")
close_button:buttons(gears.table.join(
close_button:buttons(),
awful.button({}, 1, nil, function()
local close_button = pictureButton("window-close.svg",
function()
if s.clients[1] then
s.clients[1]:kill()
popup.visible = false
end
end)
))
local create_tag_button = pictureButton("tag-create.svg")
create_tag_button:buttons(gears.table.join(
create_tag_button:buttons(),
awful.button({}, 1, nil, function()
end
)
local create_tag_button = pictureButton("tag-create.svg",
function()
awful.tag.add(switcherpopup.nextTagName(s), {
screen = s,
layout = switcherpopup.defaultLayout
}):view_only()
popup.visible = false
end)
))
local destroy_tag_button = pictureButton("tag-destroy.svg",s.selected_tag.name)
destroy_tag_button:buttons(gears.table.join(
destroy_tag_button:buttons(),
awful.button({}, 1, nil, function()
end
)
local destroy_tag_button = pictureButton("tag-destroy.svg",
function()
if #s.tags > 1 then
s.selected_tag:delete()
popup.visible = false
end
end)
))
local prev_tag_button = pictureButton("go-previous.svg")
longpress.add(prev_tag_button, function()
awful.tag.viewprev(s)
popup.visible = false
end, function()
if s.clients[1] and s.selected_tag then
local nextTag = s.selected_tag.index-1
if nextTag < 1 then nextTag = #s.tags end
s.clients[1]:move_to_tag(s.tags[nextTag])
popup.visible = false
error("move attempted")
end
error("move failed?")
end)
)
local prev_tag_button = pictureButton("go-previous.svg",
function()
awful.tag.viewprev(s)
popup.visible = false
end,
function()
if s.clients[1] and s.selected_tag then
local nextTag = s.selected_tag.index-1
if nextTag < 1 then nextTag = #s.tags end
s.clients[1]:move_to_tag(s.tags[nextTag])
popup.visible = false
error("move attempted")
end
error("move failed?")
end
)
local next_tag_button = pictureButton("go-next.svg",
function()
awful.tag.viewnext(s)
popup.visible = false
end,
function()
if s.clients[1] and s.selected_tag then
local nextTag = s.selected_tag.index+1
if nextTag > #s.tags then nextTag = 1 end
s.clients[1]:move_to_tag(s.tags[nextTag])
popup.visible = false
end
end
)
local next_tag_button = pictureButton("go-next.svg")
longpress.add(next_tag_button, function()
awful.tag.viewnext(s)
popup.visible = false
end, function()
if s.clients[1] and s.selected_tag then
local nextTag = s.selected_tag.index+1
if nextTag > #s.tags then nextTag = 1 end
s.clients[1]:move_to_tag(s.tags[nextTag])
popup.visible = false
end
end)
local tagbuttons = wibox.widget({layout = wibox.layout.grid.horizontal, prev_tag_button,create_tag_button,wibox.widget{layout=wibox.layout.stack, destroy_tag_button, tagindex},next_tag_button,close_button})
systray:set_screen(s)
systray:set_horizontal(true)
@ -169,13 +170,20 @@ function switcherpopup.new(s)
function popup.show(self)
updateSwitcherpopup()
self.visible = true
updateTimer:again()
end
function popup.hide(self)
self.visible = false
updateTimer:stop()
end
function popup.toggle(self)
updateSwitcherpopup()
self.visible = not self.visible
if self.visible then
updateTimer:again()
else
updateTimer:stop()
end
end
return popup
end