local tea = {}
tea.widget = widget({ type = "textbox" })
tea.timer = timer { timeout = 1 }
function tea:settime(t)
if t >= 3600 then -- more than one hour!
t = os.date("%X", t-3600)
else
t = os.date("%M:%S", t)
end
self.widget.text = string.format("Time for Tea: <b>%s</b>", t)
end
tea:settime(0)
function tea:countdown(time)
self.left = time
self.last_time = os.time()
self:settime(time)
self.timer:start()
end
tea.widget:buttons(awful.util.table.join(
awful.button({ }, 1, function()
awful.prompt.run({ prompt = "Set tea timer: " }, mypromptbox[mouse.screen].widget,
function (t)
local total_time = 0
for time, unit in t:gmatch("(%d+)([dhms]?)") do
time = tonumber(time)
if unit == "d" then
time = time * 86400
elseif unit == "h" then
time = time * 3600
elseif unit == "m" then
time = time * 60
end
total_time = total_time + time
end
tea:countdown(total_time)
end)
end),
awful.button({ }, 3, function()
tea.timer:stop()
tea:settime(0)
end)
))
tea.timer:add_signal("timeout", function()
local now = os.time()
tea.left = tea.left - (now - tea.last_time)
tea.last_time = now
if tea.left > 0 then
tea:settime(tea.left)
else
naughty.notify {
title = "It's me, the Tea timer.",
text = "Hey guy, your time is over!",
timeout = 5 }
tea:settime(0)
tea.timer:stop()
end
end)
There wasn't something until you asked for it. Add this code to your
rc.lua and the widget tea.widget to mywibox or what ever you use.
On a left click the promptbox will popup and ask for a time.
On a right click the timer is reseted.
The default unit is sec but it also accept a format like "12h 25m".
Currently it doesn't display left days correctly, but I hope you not
depend on this feature.
It use desktop notification to inform the user.
Acoustically feedback is possible if you use something like
awful.util.spawn("aplay /path/to/audio.wave")
If you like it, feel free to post it on the wiki.