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.
3 Licensed under GNU General Public License v2
8 local helpers = require("lain.helpers")
9 local markup = require("lain.util.markup")
10 local awful = require("awful")
11 local naughty = require("naughty")
12 local floor = math.floor
16 local tconcat = table.concat
17 local tonumber = tonumber
18 local tostring = tostring
20 -- Calendar notification
22 local function factory(args)
25 weekStart = args.weekStart or 2,
26 attach_to = args.attach_to or {},
27 followtag = args.followtag or false,
28 icons = args.icons or helpers.icons_dir .. "cal/white/",
29 notification_preset = args.notification_preset or {
30 font = "Monospace 10", fg = "#FFFFFF", bg = "#000000"
35 if not cal.notification then return end
36 naughty.destroy(cal.notification)
37 cal.notification = nil
40 function cal.show(timeout, month, year)
41 local current_month, current_year = tonumber(os.date("%m")), tonumber(os.date("%Y"))
42 local is_current_month = (not month or not year) or (month == current_month and year == current_year)
43 local today = is_current_month and tonumber(os.date("%d")) -- otherwise nil and not highlighted
44 local t = os.time { year = year or current_year, month = month and month+1 or current_month+1, day = 0 }
45 local d = os.date("*t", t)
46 local mthDays, stDay, cmonth = d.day, (d.wday-d.day-cal.weekStart+1)%7, os.date("%B %Y", t)
47 local notifytable = { [1] = string.format("%s%s\n", string.rep(" ", floor((28 - cmonth:len())/2)), markup.bold(cmonth)) }
48 for x = 0,6 do notifytable[#notifytable+1] = os.date("%a ", os.time { year=2006, month=1, day=x+cal.weekStart }) end
49 notifytable[#notifytable] = string.format("%s\n%s", notifytable[#notifytable]:sub(1, -2), string.rep(" ", stDay*4))
51 local strx = x ~= today and x or markup.bold(markup.color(cal.notification_preset.bg, cal.notification_preset.fg, x) .. " ")
52 strx = string.format("%s%s", string.rep(" ", 3 - tostring(x):len()), strx)
53 notifytable[#notifytable+1] = string.format("%-4s%s", strx, (x+stDay)%7==0 and x ~= mthDays and "\n" or "")
56 cal.notification_preset.text = tconcat(notifytable)
58 cal.notification = naughty.notify {
59 preset = cal.notification_preset,
61 timeout = timeout or cal.notification_preset.timeout or 5
63 cal.month, cal.year = d.month, d.year
66 function cal.hover_on() cal.show(0) end
67 function cal.hover_off() cal.hide() end
69 cal.month = cal.month - 1
70 if cal.month == 0 then
72 cal.year = cal.year - 1
74 cal.show(0, cal.month, cal.year)
77 cal.month = cal.month + 1
78 if cal.month == 13 then
80 cal.year = cal.year + 1
82 cal.show(0, cal.month, cal.year)
85 function cal.attach(widget)
86 widget:connect_signal("mouse::enter", cal.hover_on)
87 widget:connect_signal("mouse::leave", cal.hover_off)
88 widget:buttons(awful.util.table.join(
89 awful.button({}, 1, cal.prev),
90 awful.button({}, 3, cal.next),
91 awful.button({}, 2, cal.hover_on),
92 awful.button({}, 5, cal.prev),
93 awful.button({}, 4, cal.next)))
96 for _, widget in ipairs(cal.attach_to) do cal.attach(widget) end