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) 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[1].markup = string.format('<span size="xx-large">%s</span>',os.date("%H:%M"))
self.widget.children[2].markup = os.date("%Y-%m-%d") self.widget.children[2].markup = os.date("%Y-%m-%d")
end end
@ -56,7 +52,7 @@ function switcherpopup.new(s)
local function updateSwitcherpopup() local function updateSwitcherpopup()
clock:update() clock:update()
tagindex.markup = '<span size="xx-large" color="'..tostring(beautiful.bg_normal)..'">'..tostring(awful.screen.focused().selected_tag.name)..'</span>' 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) pcall(v.update, v)
end end
tasklistWidget:reset() tasklistWidget:reset()
@ -88,73 +84,78 @@ function switcherpopup.new(s)
end end
end end
screen.connect_signal("arrange",updateSwitcherpopup) 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({ local rc = wibox.container.constraint(wibox.widget({
widget=wibox.widget.imagebox, widget=wibox.widget.imagebox,
forced_width = switcherpopup.buttonSize, forced_width = switcherpopup.buttonSize,
forced_height = switcherpopup.buttonSize, forced_height = switcherpopup.buttonSize,
image = switcherpopup.iconPath .. "/" .. icon image = switcherpopup.iconPath .. "/" .. icon
}),nil,switcherpopup.buttonSize,switcherpopup.buttonSize) }),nil,switcherpopup.buttonSize,switcherpopup.buttonSize)
longpress.add(rc,fn,lfn)
return wibox.container.place(rc) return wibox.container.place(rc)
end end
local close_button = pictureButton("window-close.svg")
close_button:buttons(gears.table.join( local close_button = pictureButton("window-close.svg",
close_button:buttons(), function()
awful.button({}, 1, nil, function()
if s.clients[1] then if s.clients[1] then
s.clients[1]:kill() s.clients[1]:kill()
popup.visible = false popup.visible = false
end end
end) end
)) )
local create_tag_button = pictureButton("tag-create.svg") local create_tag_button = pictureButton("tag-create.svg",
create_tag_button:buttons(gears.table.join( function()
create_tag_button:buttons(),
awful.button({}, 1, nil, function()
awful.tag.add(switcherpopup.nextTagName(s), { awful.tag.add(switcherpopup.nextTagName(s), {
screen = s, screen = s,
layout = switcherpopup.defaultLayout layout = switcherpopup.defaultLayout
}):view_only() }):view_only()
popup.visible = false popup.visible = false
end) end
)) )
local destroy_tag_button = pictureButton("tag-destroy.svg",s.selected_tag.name) local destroy_tag_button = pictureButton("tag-destroy.svg",
destroy_tag_button:buttons(gears.table.join( function()
destroy_tag_button:buttons(),
awful.button({}, 1, nil, function()
if #s.tags > 1 then if #s.tags > 1 then
s.selected_tag:delete() s.selected_tag:delete()
popup.visible = false popup.visible = false
end 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 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}) 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_screen(s)
systray:set_horizontal(true) systray:set_horizontal(true)
@ -169,13 +170,20 @@ function switcherpopup.new(s)
function popup.show(self) function popup.show(self)
updateSwitcherpopup() updateSwitcherpopup()
self.visible = true self.visible = true
updateTimer:again()
end end
function popup.hide(self) function popup.hide(self)
self.visible = false self.visible = false
updateTimer:stop()
end end
function popup.toggle(self) function popup.toggle(self)
updateSwitcherpopup() updateSwitcherpopup()
self.visible = not self.visible self.visible = not self.visible
if self.visible then
updateTimer:again()
else
updateTimer:stop()
end
end end
return popup return popup
end end