Created
August 19, 2011 14:30
-
-
Save nistude/1156933 to your computer and use it in GitHub Desktop.
Pomodoro Timer Widget for the Awesome Window Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- pomodoro timer widget | |
pomodoro = {} | |
-- tweak these values in seconds to your liking | |
pomodoro.pause_duration = 300 | |
pomodoro.work_duration = 1200 | |
pomodoro.pause_title = "Pause finished." | |
pomodoro.pause_text = "Get back to work!" | |
pomodoro.work_title = "Pomodoro finished." | |
pomodoro.work_text = "Time for a pause!" | |
pomodoro.working = true | |
pomodoro.left = pomodoro.work_duration | |
pomodoro.widget = widget({ type = "textbox" }) | |
pomodoro.timer = timer { timeout = 1 } | |
function pomodoro: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("Pomodoro: <b>%s</b>", t) | |
end | |
function pomodoro:notify(title, text, duration, working) | |
naughty.notify { | |
bg = "#ff0000", | |
fg = "#aaaaaa", | |
title = title, | |
text = text, | |
timeout = 10 | |
} | |
pomodoro.left = duration | |
pomodoro:settime(duration) | |
pomodoro.working = working | |
end | |
pomodoro:settime(pomodoro.work_duration) | |
pomodoro.widget:buttons( | |
awful.util.table.join( | |
awful.button({ }, 1, function() | |
pomodoro.last_time = os.time() | |
pomodoro.timer:start() | |
end), | |
awful.button({ }, 2, function() | |
pomodoro.timer:stop() | |
end), | |
awful.button({ }, 3, function() | |
pomodoro.timer:stop() | |
pomodoro.left = pomodoro.work_duration | |
pomodoro:settime(pomodoro.work_duration) | |
end) | |
)) | |
pomodoro.timer:add_signal("timeout", function() | |
local now = os.time() | |
pomodoro.left = pomodoro.left - (now - pomodoro.last_time) | |
pomodoro.last_time = now | |
if pomodoro.left > 0 then | |
pomodoro:settime(pomodoro.left) | |
else | |
if pomodoro.working then | |
pomodoro:notify(pomodoro.work_title, pomodoro.work_text, | |
pomodoro.pause_duration, false) | |
else | |
pomodoro:notify(pomodoro.pause_title, pomodoro.pause_text, | |
pomodoro.work_duration, true) | |
end | |
pomodoro.timer:stop() | |
end | |
end) | |
I took some ideas from here and https://github.com/francois2metz/pomodoro-awesome. You can find the resulting code here
Nice, thanks for sharing!
I added increment/decrement time with the mouse wheel. https://gist.github.com/4649383
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just what I was looking for to make my awesomerc complete :) Thanks a lot!