tooltip: delay_show: stop timer, handle (non-)stopped timers

This splits the logic for `delay_show` out of `show`/`hide`, and handles
an already stopped timer.  The timer gets also stopped after the tooltip
has been displayed.

Ref: https://github.com/awesomeWM/awesome/issues/371.
This commit is contained in:
Daniel Hahler 2015-07-29 18:55:22 +02:00
parent 9bcd87c727
commit 6880835c26
1 changed files with 25 additions and 12 deletions

View File

@ -202,21 +202,34 @@ tooltip.new = function(args)
}
-- private data
local delay_timeout
if args.delay_show then
local delay_timeout
delay_timeout = timer { timeout = args.delay_show }
delay_timeout:connect_signal("timeout", function () show(self) end)
delay_timeout:connect_signal("timeout", function ()
show(self)
delay_timeout:stop()
end)
data[self] = {
show = function()
if not delay_timeout.started then
delay_timeout:start()
end
end,
hide = function()
if delay_timeout.started then
delay_timeout:stop()
end
hide(self)
end,
}
else
data[self] = {
show = function() show(self) end,
hide = function() hide(self) end,
}
end
data[self] = {
show = function()
if delay_timeout then delay_timeout:start()
else show(self) end
end,
hide = function()
if delay_timeout then delay_timeout:stop() end
hide(self)
end,
}
-- export functions
self.set_text = tooltip.set_text