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 helpers = require("lain.helpers")
10 local markup = require("lain.util.markup")
11 local awful = require("awful")
12 local naughty = require("naughty")
14 local os = { date = os.date }
15 local string = { format = string.format,
18 local tonumber = tonumber
19 local setmetatable = setmetatable
21 -- Calendar notification
22 -- lain.widget.calendar
23 local calendar = { offset = 0 }
25 function calendar.hide()
26 if not calendar.notification then return end
27 naughty.destroy(calendar.notification)
28 calendar.notification = nil
31 function calendar.show(t_out, inc_offset, scr)
32 local f, offs = nil, inc_offset or 0
34 calendar.notification_preset.screen = scr or (calendar.followtag and awful.screen.focused()) or 1
35 calendar.offset = calendar.offset + offs
37 local current_month = (offs == 0 or calendar.offset == 0)
39 if current_month then -- today highlighted
41 calendar.icon = string.format("%s%s.png", calendar.icons, tonumber(os.date("%d")))
43 else -- no current month showing, no day to highlight
44 local month = tonumber(os.date("%m"))
45 local year = tonumber(os.date("%Y"))
47 month = month + calendar.offset
60 f = string.format("%s %s %s", calendar.cal, month, year)
63 helpers.async(f, function(ws)
64 local fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg
65 calendar.notification_preset.text = ws:gsub("%c%[%d+[m]?%s?%d+%c%[%d+[m]?",
66 markup.bold(markup.color(bg, fg, os.date("%e")))):gsub("\n*$", "")
68 local widget_focused = true
71 widget_focused = false
72 for i, widget in ipairs(calendar.attach_to) do
73 for _,v in ipairs(mouse.current_widgets) do
84 calendar.notification = naughty.notify({
85 preset = calendar.notification_preset,
87 timeout = (widget_focused and t_out) or calendar.notification_preset.timeout or 5
92 function calendar.attach(widget)
93 widget:connect_signal("mouse::enter", function () calendar.show(0) end)
94 widget:connect_signal("mouse::leave", function () calendar.hide() end)
95 widget:buttons(awful.util.table.join(awful.button({ }, 1, function () calendar.show(0, -1) end),
96 awful.button({ }, 3, function () calendar.show(0, 1) end),
97 awful.button({ }, 4, function () calendar.show(0, -1) end),
98 awful.button({ }, 5, function () calendar.show(0, 1) end)))
101 local function factory(args)
102 local args = args or {}
103 calendar.cal = args.cal or "/usr/bin/cal"
104 calendar.attach_to = args.attach_to or {}
105 calendar.followtag = args.followtag or false
106 calendar.icons = args.icons or helpers.icons_dir .. "cal/white/"
107 calendar.notification_preset = args.notification_preset
109 if not calendar.notification_preset then
110 calendar.notification_preset = {
111 font = "Monospace 10",
117 for i, widget in ipairs(calendar.attach_to) do calendar.attach(widget) end
120 return setmetatable(calendar, { __call = function(_, ...) return factory(...) end })