From 219324add9d28a98723a02ea4d42367ea677a9f7 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Mon, 12 Sep 2022 15:45:22 +1000 Subject: [PATCH] fix widget updating, make all the picturebuttons go through one function and not define their own .buttons table --- init.lua | 106 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 49 deletions(-) diff --git a/init.lua b/init.lua index ff192bb..7c7d372 100644 --- a/init.lua +++ b/init.lua @@ -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('%s',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 = ''..tostring(awful.screen.focused().selected_tag.name)..'' - 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