diff options
author | Mike Crute <mike@crute.us> | 2020-03-24 00:11:40 -0700 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2020-03-24 00:12:46 -0700 |
commit | 0983e3db4567b9cf9d38624a6d47c5c5796b97c7 (patch) | |
tree | 92c1ac23e1a2b04b6aa3f7d770116e9ee8d1ee0e /.config | |
parent | 953cce0d5ddd7e7a129a7e8b2c7a50b151ff1c1b (diff) | |
download | dotfiles-0983e3db4567b9cf9d38624a6d47c5c5796b97c7.tar.bz2 dotfiles-0983e3db4567b9cf9d38624a6d47c5c5796b97c7.tar.xz dotfiles-0983e3db4567b9cf9d38624a6d47c5c5796b97c7.zip |
awesome: rewrite pomodoro timer
Diffstat (limited to '.config')
-rw-r--r-- | .config/awesome/mcrute.lua | 29 | ||||
-rw-r--r-- | .config/awesome/pomodoro.lua | 107 | ||||
-rw-r--r-- | .config/awesome/rc.lua | 4 |
3 files changed, 114 insertions, 26 deletions
diff --git a/.config/awesome/mcrute.lua b/.config/awesome/mcrute.lua index b605cea..7bc2f07 100644 --- a/.config/awesome/mcrute.lua +++ b/.config/awesome/mcrute.lua | |||
@@ -20,6 +20,7 @@ local dpi = require("beautiful.xresources").apply_dpi | |||
20 | local gears = require("gears") | 20 | local gears = require("gears") |
21 | local naughty = require("naughty") | 21 | local naughty = require("naughty") |
22 | local wibox = require("wibox") | 22 | local wibox = require("wibox") |
23 | local pomodoro = require("pomodoro") | ||
23 | 24 | ||
24 | -- Require this here because we customize it here but also so rc.lua can use it | 25 | -- Require this here because we customize it here but also so rc.lua can use it |
25 | -- transitively through this module. It makes our local customizations to | 26 | -- transitively through this module. It makes our local customizations to |
@@ -475,35 +476,11 @@ function get_clock() | |||
475 | return wibox.widget.textclock(" %a %b %d, %H:%M ", 60, timezone) | 476 | return wibox.widget.textclock(" %a %b %d, %H:%M ", 60, timezone) |
476 | end | 477 | end |
477 | 478 | ||
478 | -- pomodoro is a little pomodoro timer "app" that will show a notification on | ||
479 | -- all screens with a picture of a tomato after 25 minutes. It facilitates | ||
480 | -- using the pomodoro technique with nothing more than awesome. | ||
481 | function pomodoro() | ||
482 | local positions = {"bottom_right", "bottom_left", "bottom_right"} | ||
483 | |||
484 | gears.timer { | ||
485 | timeout = 25 * 60, | ||
486 | autostart = true, | ||
487 | single_shot = true, | ||
488 | callback = function() | ||
489 | for s = 1, screen.count() do | ||
490 | naughty.notify({ | ||
491 | icon=gears.filesystem.get_dir("config") .. "icons/pomodoro.png", | ||
492 | position=positions[s], | ||
493 | timeout=30, | ||
494 | screen=s, | ||
495 | title = "Pomodoro Over", | ||
496 | }) | ||
497 | end | ||
498 | end | ||
499 | } | ||
500 | end | ||
501 | |||
502 | -- default_display_handler configures an output to use it's default xrandr mode | 479 | -- default_display_handler configures an output to use it's default xrandr mode |
503 | -- and position it to the right of the laptop built-in display. This should be | 480 | -- and position it to the right of the laptop built-in display. This should be |
504 | -- good enough for most screens. | 481 | -- good enough for most screens. |
505 | function default_display_handler(card, edp_mode) | 482 | function default_display_handler(card, edp_mode) |
506 | awful.util.spawn("xrandr --output eDP-1 --mode ".. edp_mode .. " --output " .. card .. " --auto --right-of eDP-1") | 483 | awful.util.spawn("xrandr --output eDP-1 --mode " .. edp_mode .. " --output " .. card .. " --auto --right-of eDP-1") |
507 | end | 484 | end |
508 | 485 | ||
509 | -- get_displays uses a shell script helper (~/bin/enumerate-displays) to | 486 | -- get_displays uses a shell script helper (~/bin/enumerate-displays) to |
@@ -598,6 +575,7 @@ return { | |||
598 | get_clock = get_clock, | 575 | get_clock = get_clock, |
599 | get_layouts = get_layouts, | 576 | get_layouts = get_layouts, |
600 | battery = battery, | 577 | battery = battery, |
578 | pomodoro = pomodoro, | ||
601 | 579 | ||
602 | -- Public functions that are occasionally useful | 580 | -- Public functions that are occasionally useful |
603 | split_screen_vertical = split_screen_vertical, | 581 | split_screen_vertical = split_screen_vertical, |
@@ -606,5 +584,4 @@ return { | |||
606 | -- Public functions that are useful on import | 584 | -- Public functions that are useful on import |
607 | configure_displays = configure_displays, | 585 | configure_displays = configure_displays, |
608 | dump = dump, | 586 | dump = dump, |
609 | pomodoro = pomodoro, | ||
610 | } | 587 | } |
diff --git a/.config/awesome/pomodoro.lua b/.config/awesome/pomodoro.lua new file mode 100644 index 0000000..26ae2a0 --- /dev/null +++ b/.config/awesome/pomodoro.lua | |||
@@ -0,0 +1,107 @@ | |||
1 | local setmetatable = setmetatable | ||
2 | local math = math | ||
3 | local string = string | ||
4 | local gears = require("gears") | ||
5 | local naughty = require("naughty") | ||
6 | local textbox = require("wibox.widget.textbox") | ||
7 | local glib = require("lgi").GLib | ||
8 | local DateTime = glib.DateTime | ||
9 | local TimeZone = glib.TimeZone | ||
10 | |||
11 | local pomodoro = { mt = {} } | ||
12 | |||
13 | local work_time = 25 * 60 | ||
14 | local positions = {"bottom_right", "bottom_left", "bottom_right"} | ||
15 | |||
16 | -- pomodoro is a little pomodoro timer "app" that will show a notification on | ||
17 | -- all screens with a picture of a tomato after 25 minutes. It facilitates | ||
18 | -- using the pomodoro technique with nothing more than awesome. | ||
19 | |||
20 | function pomodoro:_timer_running() | ||
21 | return self._timer ~= nil and self._timer.data.source_id ~= nil | ||
22 | end | ||
23 | |||
24 | function pomodoro:_set_text(val) | ||
25 | self:set_markup("<span color='red' weight='bold'> " .. val .. " </span>") | ||
26 | end | ||
27 | |||
28 | function pomodoro:_clear_text() | ||
29 | self:set_markup("") | ||
30 | end | ||
31 | |||
32 | function pomodoro:stop() | ||
33 | self:_set_text("Pomodoro Stopped") | ||
34 | self._timer:stop() | ||
35 | self:_reset_text_later() | ||
36 | end | ||
37 | |||
38 | function pomodoro:_reset_text_later() | ||
39 | gears.timer { | ||
40 | timeout = 30, | ||
41 | autostart = true, | ||
42 | single_shot = true, | ||
43 | callback = function() | ||
44 | self:_clear_text() | ||
45 | end | ||
46 | } | ||
47 | end | ||
48 | |||
49 | function pomodoro:_notify_complete() | ||
50 | for s = 1, screen.count() do | ||
51 | naughty.notify({ | ||
52 | icon=gears.filesystem.get_dir("config") .. "icons/pomodoro.png", | ||
53 | position=positions[s], | ||
54 | timeout=30, | ||
55 | screen=s, | ||
56 | title = "Pomodoro Over", | ||
57 | }) | ||
58 | end | ||
59 | |||
60 | self:_set_text("Pomodoro Over") | ||
61 | end | ||
62 | |||
63 | function pomodoro:_update_callback() | ||
64 | local now = DateTime.new_now(TimeZone.new_local()):to_unix() | ||
65 | |||
66 | local time_left = work_time - (now - self._start_time) | ||
67 | |||
68 | local mins_left = math.floor(time_left / 60) | ||
69 | local secs_left = math.floor(time_left % 60) | ||
70 | |||
71 | if mins_left == 0 and secs_left == 0 then | ||
72 | self._timer:stop() | ||
73 | self:_notify_complete() | ||
74 | self:_reset_text_later() | ||
75 | return | ||
76 | end | ||
77 | |||
78 | self:_set_text(string.format("%02d:%02d", mins_left, secs_left)) | ||
79 | end | ||
80 | |||
81 | function pomodoro:start() | ||
82 | if self:_timer_running() then | ||
83 | return | ||
84 | end | ||
85 | |||
86 | self._start_time = DateTime.new_now(TimeZone.new_local()):to_unix() | ||
87 | |||
88 | self._timer = gears.timer { | ||
89 | timeout = 1, | ||
90 | autostart = true, | ||
91 | callback = function() | ||
92 | return self:_update_callback() | ||
93 | end | ||
94 | } | ||
95 | end | ||
96 | |||
97 | local function new() | ||
98 | local w = textbox() | ||
99 | gears.table.crush(w, pomodoro, true) | ||
100 | return w | ||
101 | end | ||
102 | |||
103 | function pomodoro.mt.__call(...) | ||
104 | return new(...) | ||
105 | end | ||
106 | |||
107 | return setmetatable(pomodoro, pomodoro.mt) | ||
diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index d56ddd6..029f4d4 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua | |||
@@ -80,6 +80,9 @@ mykeyboardlayout = awful.widget.keyboardlayout() | |||
80 | -- Create a textclock widget | 80 | -- Create a textclock widget |
81 | mytextclock = mcrute.get_clock() | 81 | mytextclock = mcrute.get_clock() |
82 | 82 | ||
83 | -- Create pomodoro timer | ||
84 | mypomodoro = mcrute.pomodoro() | ||
85 | |||
83 | -- Create a wibox for each screen and add it | 86 | -- Create a wibox for each screen and add it |
84 | local taglist_buttons = gears.table.join( | 87 | local taglist_buttons = gears.table.join( |
85 | awful.button({ }, 1, function(t) t:view_only() end), | 88 | awful.button({ }, 1, function(t) t:view_only() end), |
@@ -178,6 +181,7 @@ awful.screen.connect_for_each_screen(function(s) | |||
178 | s.mytasklist, -- Middle widget | 181 | s.mytasklist, -- Middle widget |
179 | { -- Right widgets | 182 | { -- Right widgets |
180 | layout = wibox.layout.fixed.horizontal, | 183 | layout = wibox.layout.fixed.horizontal, |
184 | mypomodoro, | ||
181 | wibox.widget.systray(), | 185 | wibox.widget.systray(), |
182 | mcrute.battery(), | 186 | mcrute.battery(), |
183 | mytextclock, | 187 | mytextclock, |