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
4 * (c) 2013, Luke Bonham
8 local helpers = require("lain.helpers")
9 local markup = require("lain.util.markup")
10 local awful = require("awful")
11 local naughty = require("naughty")
13 local os = { date = os.date }
14 local string = { format = string.format,
17 local tonumber = tonumber
18 local setmetatable = setmetatable
20 -- Calendar notification
21 -- lain.widget.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)
31 local f, offs = nil, inc_offset or 0
33 calendar.notification_preset.screen = scr or (calendar.followtag and awful.screen.focused()) or 1
34 calendar.offset = calendar.offset + offs
36 local current_month = (offs == 0 or calendar.offset == 0)
38 if current_month then -- today highlighted
40 calendar.icon = calendar.icons:len() > 0 and string.format("%s%s.png", calendar.icons, tonumber(os.date("%d")))
42 else -- no current month showing, no day to highlight
43 local month = tonumber(os.date("%m"))
44 local year = tonumber(os.date("%Y"))
46 month = month + calendar.offset
59 f = string.format("%s %s %s", calendar.cal, month, year)
62 helpers.async(f, function(ws)
63 local fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg
64 calendar.notification_preset.text = ws:gsub("%c%[%d+[m]?%s?%d+%c%[%d+[m]?",
65 markup.bold(markup.color(bg, fg, os.date("%e")))):gsub("\n*$", "")
67 local widget_focused = true
69 if t_out == 0 and mouse.current_widgets then
70 widget_focused = false
71 for i, widget in ipairs(calendar.attach_to) do
72 for _,v in ipairs(mouse.current_widgets) do
81 if widget_focused then
83 calendar.notification = naughty.notify({
84 preset = calendar.notification_preset,
86 timeout = t_out or calendar.notification_preset.timeout or 5
92 function calendar.hover_on() calendar.show(0) end
93 function calendar.hover_off() calendar.hide() end
94 function calendar.prev() calendar.show(0, -1) end
95 function calendar.next() calendar.show(0, 1) end
97 function calendar.attach(widget)
98 widget:connect_signal("mouse::enter", calendar.hover_on)
99 widget:connect_signal("mouse::leave", calendar.hover_off)
100 widget:buttons(awful.util.table.join(
101 awful.button({}, 1, calendar.prev),
102 awful.button({}, 3, calendar.next),
103 awful.button({}, 2, calendar.hover_on),
104 awful.button({}, 4, calendar.prev),
105 awful.button({}, 5, calendar.next)))
108 local function factory(args)
109 local args = args or {}
110 calendar.cal = args.cal or "/usr/bin/cal"
111 calendar.attach_to = args.attach_to or {}
112 calendar.followtag = args.followtag or false
113 calendar.icons = args.icons or helpers.icons_dir .. "cal/white/"
114 calendar.notification_preset = args.notification_preset
116 if not calendar.notification_preset then
117 calendar.notification_preset = {
118 font = "Monospace 10",
124 for i, widget in ipairs(calendar.attach_to) do calendar.attach(widget) end
127 return setmetatable(calendar, { __call = function(_, ...) return factory(...) end })