From 9e8081d4f12f64903c59de70b541737e811642b3 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 25 Jun 2018 09:39:04 +0200 Subject: awesome update --- config/awesome/countdown.lua | 78 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 config/awesome/countdown.lua (limited to 'config/awesome/countdown.lua') 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) +)) -- cgit v1.2.3