All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
9 local async = require("lain.helpers").async
10 local icons_dir = require("lain.helpers").icons_dir
11 local markup = require("lain.util.markup")
12 local awful = require("awful")
13 local naughty = require("naughty")
14 local os = { date = os.date }
15 local string = { format = string.format,
17 local tonumber = tonumber
18 local setmetatable = setmetatable
20 -- Calendar notification
21 -- lain.widgets.calendar
22 local calendar = { offset = 0 }
24 function calendar.hide()
25 if not calendar.notification then return end
26 naughty.destroy(calendar.notification)
27 calendar.notification = nil
30 function calendar.show(t_out, inc_offset, scr)
33 local today = os.date("%d")
34 local offs = inc_offset or 0
37 calendar.offset = calendar.offset + offs
39 local current_month = (offs == 0 or calendar.offset == 0)
41 if current_month then -- today highlighted
43 calendar.notify_icon = string.format("%s%s.png", calendar.icons, today)
45 else -- no current month showing, no day to highlight
46 local month = tonumber(os.date("%m"))
47 local year = tonumber(os.date("%Y"))
49 month = month + calendar.offset
61 calendar.notify_icon = nil
62 f = string.format("%s %s %s", calendar.cal, month, year)
65 if calendar.followtag then
66 calendar.notification_preset.screen = awful.screen.focused()
68 calendar.notification_preset.screen = src or 1
71 async(string.format("%s -c '%s'", awful.util.shell, f), function(ws)
72 fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg
73 ws = ws:gsub("%c%[7m%d+%c%[27m", markup.bold(markup.color(bg, fg, today)))
74 calendar.notification = naughty.notify({
75 preset = calendar.notification_preset,
76 text = ws:gsub("\n*$", ""),
77 icon = calendar.notify_icon,
78 timeout = t_out or calendar.notification.preset.timeout or 5
83 function calendar.attach(widget, args)
84 local args = args or {}
85 calendar.cal = args.cal or "/usr/bin/cal --color=always"
86 calendar.followtag = args.followtag or false
87 calendar.icons = args.icons or icons_dir .. "cal/white/"
88 calendar.notification_preset = args.notification_preset
90 if not calendar.notification_preset then
91 calendar.notification_preset = naughty.config.defaults
92 calendar.notification_preset.font = "Monospace 10"
93 calendar.notification_preset.fg = "#FFFFFF"
94 calendar.notification_preset.bg = "#000000"
97 widget:connect_signal("mouse::enter", function () calendar.show(0, 0, calendar.scr_pos) end)
98 widget:connect_signal("mouse::leave", function () calendar.hide() end)
99 widget:buttons(awful.util.table.join(awful.button({ }, 1, function ()
100 calendar.show(0, -1, calendar.scr_pos) end),
101 awful.button({ }, 3, function ()
102 calendar.show(0, 1, calendar.scr_pos) end),
103 awful.button({ }, 4, function ()
104 calendar.show(0, -1, calendar.scr_pos) end),
105 awful.button({ }, 5, function ()
106 calendar.show(0, 1, calendar.scr_pos) end)))
109 return setmetatable(calendar, { __call = function(_, ...) return create(...) end })