Search code examples
luaawesome-wm

Display a widget with a timeout in Awesome Wm with Lua


I want to display a wibox in awesome when a combinaison of keys are pressed and I want that this wibox disappears after 3 seconds for example. I don't want to use naughty or popup because the wibox will have widgets inside.

I have already a solution but I don't know if this solution is a standard one or if there is another way to do this:

function taglist_wibox_show_hide(box)
  local show = timer({ timeout = 0 })
  show:connect_signal("timeout", function ()
                                      print("show")
                                      box.visible=true
                                      show:stop() end)
  show:start()
  local hide = timer({ timeout = 2 })
  hide:connect_signal("timeout", function ()
                                       print("hide")
                                       box.visible=false
                                       hide:stop() end)
  hide:start()
end

Then I add this shortcut:

awful.key({ modkey, "Control" },"y",function() 
                                     taglist_wibox_show_hide(box[mouse.screen])
                                    end),

Solution

  • As far as I know there's no other way. However I think your first timer is not necessary.

    function taglist_wibox_show_hide(box)
    
      print("show")
      box.visible=true
    
      local hide = timer({ timeout = 2 })
      hide:connect_signal("timeout", function ()
                                           print("hide")
                                           box.visible=false
                                           hide:stop() end)
      hide:start()
    end
    

    Should work just as well.

    Cheers