Skip to content

Instantly share code, notes, and snippets.

@Virako
Forked from nistude/pomodoro.lua
Last active January 10, 2017 18:56
Show Gist options
  • Save Virako/4649383 to your computer and use it in GitHub Desktop.
Save Virako/4649383 to your computer and use it in GitHub Desktop.
Add increment/decrement time with mouse wheel.
-- 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),
awful.button({ }, 4, function() |582 end
pomodoro.timer:stop() |583 end),
pomodoro:settime(pomodoro.work_duration+60) |584
pomodoro.work_duration = pomodoro.work_duration+60 |585 -- Standard program
pomodoro.left = pomodoro.work_duration |586 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
end), |587 awful.key({ modkey, "Shift" }, "f", function () awful.util.spawn("pcmanfm") end),
awful.button({ }, 5, function() |588 awful.key({ modkey, "Control" }, "r", awesome.restart),
pomodoro.timer:stop() |589 awful.key({ modkey, "Shift" }, "q", awesome.quit),
if pomodoro.work_duration > 60 then |590
pomodoro:settime(pomodoro.work_duration-60) |591 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
pomodoro.work_duration = pomodoro.work_duration-60 |592 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
pomodoro.left = pomodoro.work_duration |593 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment