diff options
author | Mike Crute <mike@crute.us> | 2022-08-27 21:59:25 -0700 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2022-08-27 21:59:25 -0700 |
commit | 5c9c88f1f481236866273c7f84e5bda6a6c54fd5 (patch) | |
tree | 3abfd1e02d83d9136ebc5c06c943d2cd6dae58a9 /.config | |
parent | 488054f9fe6e2195e90881f65b4870ac8409861f (diff) | |
download | dotfiles-5c9c88f1f481236866273c7f84e5bda6a6c54fd5.tar.bz2 dotfiles-5c9c88f1f481236866273c7f84e5bda6a6c54fd5.tar.xz dotfiles-5c9c88f1f481236866273c7f84e5bda6a6c54fd5.zip |
Add calendar widget
Diffstat (limited to '.config')
-rw-r--r-- | .config/awesome/calendar.lua | 253 | ||||
-rw-r--r-- | .config/awesome/mcrute.lua | 15 |
2 files changed, 267 insertions, 1 deletions
diff --git a/.config/awesome/calendar.lua b/.config/awesome/calendar.lua new file mode 100644 index 0000000..4bb637f --- /dev/null +++ b/.config/awesome/calendar.lua | |||
@@ -0,0 +1,253 @@ | |||
1 | ------------------------------------------------- | ||
2 | -- Calendar Widget for Awesome Window Manager | ||
3 | -- Shows the current month and supports scroll up/down to switch month | ||
4 | -- More details could be found here: | ||
5 | -- https://github.com/streetturtle/awesome-wm-widgets/tree/master/calendar-widget | ||
6 | |||
7 | -- @author Pavel Makhov | ||
8 | -- @copyright 2019 Pavel Makhov | ||
9 | ------------------------------------------------- | ||
10 | |||
11 | local awful = require("awful") | ||
12 | local beautiful = require("beautiful") | ||
13 | local wibox = require("wibox") | ||
14 | local gears = require("gears") | ||
15 | local naughty = require("naughty") | ||
16 | |||
17 | local calendar_widget = {} | ||
18 | |||
19 | local function worker(user_args) | ||
20 | |||
21 | local calendar_themes = { | ||
22 | nord = { | ||
23 | bg = '#2E3440', | ||
24 | fg = '#D8DEE9', | ||
25 | focus_date_bg = '#88C0D0', | ||
26 | focus_date_fg = '#000000', | ||
27 | weekend_day_bg = '#3B4252', | ||
28 | weekday_fg = '#88C0D0', | ||
29 | header_fg = '#E5E9F0', | ||
30 | border = '#4C566A' | ||
31 | }, | ||
32 | outrun = { | ||
33 | bg = '#0d0221', | ||
34 | fg = '#D8DEE9', | ||
35 | focus_date_bg = '#650d89', | ||
36 | focus_date_fg = '#2de6e2', | ||
37 | weekend_day_bg = '#261447', | ||
38 | weekday_fg = '#2de6e2', | ||
39 | header_fg = '#f6019d', | ||
40 | border = '#261447' | ||
41 | }, | ||
42 | dark = { | ||
43 | bg = '#000000', | ||
44 | fg = '#ffffff', | ||
45 | focus_date_bg = '#ffffff', | ||
46 | focus_date_fg = '#000000', | ||
47 | weekend_day_bg = '#444444', | ||
48 | weekday_fg = '#ffffff', | ||
49 | header_fg = '#ffffff', | ||
50 | border = '#333333' | ||
51 | }, | ||
52 | light = { | ||
53 | bg = '#ffffff', | ||
54 | fg = '#000000', | ||
55 | focus_date_bg = '#000000', | ||
56 | focus_date_fg = '#ffffff', | ||
57 | weekend_day_bg = '#AAAAAA', | ||
58 | weekday_fg = '#000000', | ||
59 | header_fg = '#000000', | ||
60 | border = '#CCCCCC' | ||
61 | }, | ||
62 | monokai = { | ||
63 | bg = '#272822', | ||
64 | fg = '#F8F8F2', | ||
65 | focus_date_bg = '#AE81FF', | ||
66 | focus_date_fg = '#ffffff', | ||
67 | weekend_day_bg = '#75715E', | ||
68 | weekday_fg = '#FD971F', | ||
69 | header_fg = '#F92672', | ||
70 | border = '#75715E' | ||
71 | }, | ||
72 | naughty = { | ||
73 | bg = beautiful.notification_bg or beautiful.bg, | ||
74 | fg = beautiful.notification_fg or beautiful.fg, | ||
75 | focus_date_bg = beautiful.notification_fg or beautiful.fg, | ||
76 | focus_date_fg = beautiful.notification_bg or beautiful.bg, | ||
77 | weekend_day_bg = beautiful.bg_focus, | ||
78 | weekday_fg = beautiful.fg, | ||
79 | header_fg = beautiful.fg, | ||
80 | border = beautiful.border_normal | ||
81 | } | ||
82 | |||
83 | } | ||
84 | |||
85 | local args = user_args or {} | ||
86 | |||
87 | if args.theme ~= nil and calendar_themes[args.theme] == nil then | ||
88 | naughty.notify({ | ||
89 | preset = naughty.config.presets.critical, | ||
90 | title = 'Calendar Widget', | ||
91 | text = 'Theme "' .. args.theme .. '" not found, fallback to default'}) | ||
92 | args.theme = 'naughty' | ||
93 | end | ||
94 | |||
95 | local theme = args.theme or 'naughty' | ||
96 | local placement = args.placement or 'top' | ||
97 | local radius = args.radius or 8 | ||
98 | local next_month_button = args.next_month_button or 4 | ||
99 | local previous_month_button = args.previous_month_button or 5 | ||
100 | local start_sunday = args.start_sunday or false | ||
101 | |||
102 | local styles = {} | ||
103 | local function rounded_shape(size) | ||
104 | return function(cr, width, height) | ||
105 | gears.shape.rounded_rect(cr, width, height, size) | ||
106 | end | ||
107 | end | ||
108 | |||
109 | styles.month = { | ||
110 | padding = 4, | ||
111 | bg_color = calendar_themes[theme].bg, | ||
112 | border_width = 0, | ||
113 | } | ||
114 | |||
115 | styles.normal = { | ||
116 | markup = function(t) return t end, | ||
117 | shape = rounded_shape(4) | ||
118 | } | ||
119 | |||
120 | styles.focus = { | ||
121 | fg_color = calendar_themes[theme].focus_date_fg, | ||
122 | bg_color = calendar_themes[theme].focus_date_bg, | ||
123 | markup = function(t) return '<b>' .. t .. '</b>' end, | ||
124 | shape = rounded_shape(4) | ||
125 | } | ||
126 | |||
127 | styles.header = { | ||
128 | fg_color = calendar_themes[theme].header_fg, | ||
129 | bg_color = calendar_themes[theme].bg, | ||
130 | markup = function(t) return '<b>' .. t .. '</b>' end | ||
131 | } | ||
132 | |||
133 | styles.weekday = { | ||
134 | fg_color = calendar_themes[theme].weekday_fg, | ||
135 | bg_color = calendar_themes[theme].bg, | ||
136 | markup = function(t) return '<b>' .. t .. '</b>' end, | ||
137 | } | ||
138 | |||
139 | local function decorate_cell(widget, flag, date) | ||
140 | if flag == 'monthheader' and not styles.monthheader then | ||
141 | flag = 'header' | ||
142 | end | ||
143 | |||
144 | -- highlight only today's day | ||
145 | if flag == 'focus' then | ||
146 | local today = os.date('*t') | ||
147 | if not (today.month == date.month and today.year == date.year) then | ||
148 | flag = 'normal' | ||
149 | end | ||
150 | end | ||
151 | |||
152 | local props = styles[flag] or {} | ||
153 | if props.markup and widget.get_text and widget.set_markup then | ||
154 | widget:set_markup(props.markup(widget:get_text())) | ||
155 | end | ||
156 | -- Change bg color for weekends | ||
157 | local d = { year = date.year, month = (date.month or 1), day = (date.day or 1) } | ||
158 | local weekday = tonumber(os.date('%w', os.time(d))) | ||
159 | local default_bg = (weekday == 0 or weekday == 6) | ||
160 | and calendar_themes[theme].weekend_day_bg | ||
161 | or calendar_themes[theme].bg | ||
162 | local ret = wibox.widget { | ||
163 | { | ||
164 | { | ||
165 | widget, | ||
166 | halign = 'center', | ||
167 | widget = wibox.container.place | ||
168 | }, | ||
169 | margins = (props.padding or 2) + (props.border_width or 0), | ||
170 | widget = wibox.container.margin | ||
171 | }, | ||
172 | shape = props.shape, | ||
173 | shape_border_color = props.border_color or '#000000', | ||
174 | shape_border_width = props.border_width or 0, | ||
175 | fg = props.fg_color or calendar_themes[theme].fg, | ||
176 | bg = props.bg_color or default_bg, | ||
177 | widget = wibox.container.background | ||
178 | } | ||
179 | |||
180 | return ret | ||
181 | end | ||
182 | |||
183 | local cal = wibox.widget { | ||
184 | date = os.date('*t'), | ||
185 | font = beautiful.get_font(), | ||
186 | fn_embed = decorate_cell, | ||
187 | long_weekdays = true, | ||
188 | start_sunday = start_sunday, | ||
189 | widget = wibox.widget.calendar.month | ||
190 | } | ||
191 | |||
192 | local popup = awful.popup { | ||
193 | ontop = true, | ||
194 | visible = false, | ||
195 | shape = rounded_shape(radius), | ||
196 | offset = { y = 5 }, | ||
197 | border_width = 1, | ||
198 | border_color = calendar_themes[theme].border, | ||
199 | widget = cal | ||
200 | } | ||
201 | |||
202 | popup:buttons( | ||
203 | awful.util.table.join( | ||
204 | awful.button({}, next_month_button, function() | ||
205 | local a = cal:get_date() | ||
206 | a.month = a.month + 1 | ||
207 | cal:set_date(nil) | ||
208 | cal:set_date(a) | ||
209 | popup:set_widget(cal) | ||
210 | end), | ||
211 | awful.button({}, previous_month_button, function() | ||
212 | local a = cal:get_date() | ||
213 | a.month = a.month - 1 | ||
214 | cal:set_date(nil) | ||
215 | cal:set_date(a) | ||
216 | popup:set_widget(cal) | ||
217 | end) | ||
218 | ) | ||
219 | ) | ||
220 | |||
221 | function calendar_widget.toggle() | ||
222 | |||
223 | if popup.visible then | ||
224 | -- to faster render the calendar refresh it and just hide | ||
225 | cal:set_date(nil) -- the new date is not set without removing the old one | ||
226 | cal:set_date(os.date('*t')) | ||
227 | popup:set_widget(nil) -- just in case | ||
228 | popup:set_widget(cal) | ||
229 | popup.visible = not popup.visible | ||
230 | else | ||
231 | if placement == 'top' then | ||
232 | awful.placement.top(popup, { margins = { top = 30 }, parent = awful.screen.focused() }) | ||
233 | elseif placement == 'top_right' then | ||
234 | awful.placement.top_right(popup, { margins = { top = 30, right = 10}, parent = awful.screen.focused() }) | ||
235 | elseif placement == 'bottom_right' then | ||
236 | awful.placement.bottom_right(popup, { margins = { bottom = 30, right = 10}, | ||
237 | parent = awful.screen.focused() }) | ||
238 | else | ||
239 | awful.placement.top(popup, { margins = { top = 30 }, parent = awful.screen.focused() }) | ||
240 | end | ||
241 | |||
242 | popup.visible = true | ||
243 | |||
244 | end | ||
245 | end | ||
246 | |||
247 | return calendar_widget | ||
248 | |||
249 | end | ||
250 | |||
251 | return setmetatable(calendar_widget, { __call = function(_, ...) | ||
252 | return worker(...) | ||
253 | end }) | ||
diff --git a/.config/awesome/mcrute.lua b/.config/awesome/mcrute.lua index 8143abf..869b001 100644 --- a/.config/awesome/mcrute.lua +++ b/.config/awesome/mcrute.lua | |||
@@ -30,6 +30,7 @@ local capi = | |||
30 | -- transitively through this module. It makes our local customizations to | 30 | -- transitively through this module. It makes our local customizations to |
31 | -- rc.lua just a little easier to grep for. | 31 | -- rc.lua just a little easier to grep for. |
32 | local battery = require("battery") | 32 | local battery = require("battery") |
33 | local calendar = require("calendar") | ||
33 | local _cpu_widget = require("cpu-widget") | 34 | local _cpu_widget = require("cpu-widget") |
34 | 35 | ||
35 | local timezone = "America/Los_Angeles" | 36 | local timezone = "America/Los_Angeles" |
@@ -536,7 +537,19 @@ end | |||
536 | -- defaults but overrides the timezone to account for some oddities that I was | 537 | -- defaults but overrides the timezone to account for some oddities that I was |
537 | -- experiencing with Ubuntu when changing timezones. | 538 | -- experiencing with Ubuntu when changing timezones. |
538 | function get_clock() | 539 | function get_clock() |
539 | return wibox.widget.textclock(" %a %b %d, %H:%M ", 60, timezone) | 540 | local wi = wibox.widget.textclock(" %a %b %d, %H:%M ", 60, timezone) |
541 | |||
542 | local cw = calendar({ | ||
543 | placement = 'top_right', | ||
544 | start_sunday = true, | ||
545 | previous_month_button = 4, | ||
546 | next_month_button = 5, | ||
547 | }) | ||
548 | wi:connect_signal("button::press", function(_, _, _, button) | ||
549 | if button == 1 then cw.toggle() end | ||
550 | end) | ||
551 | |||
552 | return wi | ||
540 | end | 553 | end |
541 | 554 | ||
542 | -- default_display_handler configures an output to use it's default xrandr mode | 555 | -- default_display_handler configures an output to use it's default xrandr mode |