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")
16 local tonumber = tonumber
17 local setmetatable = setmetatable
19 -- Calendar notification
20 -- lain.widget.calendar
21 local calendar = { offset = 0 }
23 function calendar.hide()
24 if not calendar.notification then return end
25 naughty.destroy(calendar.notification)
26 calendar.notification = nil
29 function calendar.show(t_out, inc_offset, scr)
30 local f, offs = nil, inc_offset or 0
32 calendar.notification_preset.screen = scr or (calendar.followtag and awful.screen.focused()) or 1
33 calendar.offset = calendar.offset + offs
35 local current_month = (offs == 0 or calendar.offset == 0)
37 if current_month then -- today highlighted
39 calendar.icon = calendar.icons:len() > 0 and string.format("%s%s.png", calendar.icons, tonumber(os.date("%d")))
41 else -- no current month showing, no day to highlight
42 local year = tonumber(os.date("%Y"))
43 local month = tonumber(os.date("%m")) + calendar.offset
56 f = string.format("%s %s %s", calendar.cal, month, year)
59 helpers.async(f, function(ws)
60 local fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg
61 calendar.notification_preset.text = ws:gsub("%c%[%d+[m]?%s?%d+%c%[%d+[m]?",
62 markup.bold(markup.color(bg, fg, os.date("%e")))):gsub("[\n%s]*$", "")
64 local widget_focused = true
66 if t_out == 0 and mouse.current_widgets then
67 widget_focused = false
68 for i, widget in ipairs(calendar.attach_to) do
69 for _,v in ipairs(mouse.current_widgets) do
78 if widget_focused then
80 calendar.notification = naughty.notify({
81 preset = calendar.notification_preset,
83 timeout = t_out or calendar.notification_preset.timeout or 5
89 function calendar.hover_on() calendar.show(0) end
90 function calendar.hover_off() calendar.hide() end
91 function calendar.prev() calendar.show(0, -1) end
92 function calendar.next() calendar.show(0, 1) end
94 function calendar.attach(widget)
95 widget:connect_signal("mouse::enter", calendar.hover_on)
96 widget:connect_signal("mouse::leave", calendar.hover_off)
97 widget:buttons(awful.util.table.join(
98 awful.button({}, 1, calendar.prev),
99 awful.button({}, 3, calendar.next),
100 awful.button({}, 2, calendar.hover_on),
101 awful.button({}, 4, calendar.prev),
102 awful.button({}, 5, calendar.next)))
105 local function factory(args)
106 local args = args or {}
107 calendar.cal = args.cal or "/usr/bin/cal"
108 calendar.attach_to = args.attach_to or {}
109 calendar.followtag = args.followtag or false
110 calendar.icons = args.icons or helpers.icons_dir .. "cal/white/"
111 calendar.notification_preset = args.notification_preset
113 if not calendar.notification_preset then
114 calendar.notification_preset = {
115 font = "Monospace 10",
121 for i, widget in ipairs(calendar.attach_to) do calendar.attach(widget) end
124 return setmetatable(calendar, { __call = function(_, ...) return factory(...) end })