summaryrefslogtreecommitdiff
path: root/config/awesome/countdown.lua
diff options
context:
space:
mode:
Diffstat (limited to 'config/awesome/countdown.lua')
-rw-r--r--config/awesome/countdown.lua78
1 files changed, 78 insertions, 0 deletions
diff --git a/config/awesome/countdown.lua b/config/awesome/countdown.lua
new file mode 100644
index 0000000..92d2c99
--- /dev/null
+++ b/config/awesome/countdown.lua
@@ -0,0 +1,78 @@
+-- from https://awesomewm.org/recipes/countdown/
+-- on 2018-04-10
+-- slightly modified
+
+local gears = require("gears")
+local awful = require("awful")
+local wibox = require("wibox")
+local naughty = require("naughty")
+local beautiful = require("beautiful")
+
+countdown = {
+ widget = wibox.widget.textbox(),
+ checkbox = wibox.widget {
+ checked = false,
+ check_color = "#ff0000", -- customize
+ border_color = beautiful.fg_normal, -- customize
+ border_width = 2, -- customize
+ shape = gears.shape.circle,
+ widget = wibox.widget.checkbox
+ }
+}
+
+function countdown.set()
+ awful.prompt.run {
+ prompt = "Countdown minutes: ", -- floats accepted
+ textbox = awful.screen.focused().mypromptbox.widget,
+ exe_callback = function(timeout)
+ if countdown.timer and countdown.timer.started then
+ countdown.seconds = tonumber(timeout) * 60
+ return
+ end
+
+ countdown.seconds = tonumber(timeout)
+ if not countdown.seconds then return end
+ countdown.checkbox.checked = false
+ countdown.minute_t = countdown.seconds > 1 and "minutes" or "minute"
+ countdown.seconds = countdown.seconds * 60
+ countdown.timer = gears.timer({ timeout = 1 })
+ countdown.timer:connect_signal("timeout", function()
+ if countdown.seconds > 0 then
+ local minutes = math.floor(countdown.seconds / 60)
+ local seconds = math.fmod(countdown.seconds, 60)
+ countdown.widget:set_markup(string.format("%d:%02d", minutes, seconds))
+ countdown.seconds = countdown.seconds - 1
+ else
+ naughty.notify({
+ preset = naughty.config.presets.critical,
+ title = "Countdown",
+ text = string.format("%s %s timeout", timeout, countdown.minute_t),
+ timeout = 30,
+ position = "top_middle",
+ run = function(notification)
+ countdown.widget:set_markup("")
+ countdown.checkbox.checked = false
+ notification.die(naughty.notificationClosedReason.dismissedByUser)
+ end
+ })
+ countdown.widget:set_markup("")
+ countdown.checkbox.checked = true
+ countdown.timer:stop()
+ end
+ end)
+ countdown.timer:start()
+ end
+ }
+end
+
+countdown.checkbox:buttons(awful.util.table.join(
+ awful.button({}, 1, function() countdown.set() end), -- left click
+ awful.button({}, 3, function() -- right click
+ if countdown.timer and countdown.timer.started then
+ countdown.timer:stop()
+ naughty.notify({ title = "Countdown", text = "Timer stopped" })
+ end
+ countdown.widget:set_markup("")
+ countdown.checkbox.checked = false
+ end)
+))