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")
13 local os = { date = os.date }
14 local string = { format = string.format,
16 local tonumber = tonumber
18 -- Calendar notification
19 -- lain.widgets.calendar
20 local calendar = { offset = 0 }
22 function calendar.hide()
23 naughty.destroy(naughty.getById(calendar.id))
26 function calendar.show(t_out, inc_offset, scr)
29 local today = os.date("%d")
30 local offs = inc_offset or 0
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.notify_icon = string.format("%s%s.png", calendar.icons, today)
41 else -- no current month showing, no day to highlight
42 local month = tonumber(os.date("%m"))
43 local year = tonumber(os.date("%Y"))
45 month = month + calendar.offset
57 calendar.notify_icon = nil
58 f = string.format("%s %s %s", calendar.cal, month, year)
61 if calendar.followtag then
62 calendar.notification_preset.screen = awful.screen.focused()
64 calendar.notification_preset.screen = src or 1
67 helpers.async(f, function(ws)
68 fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg
69 ws = ws:gsub("%c%[%d+[m]?%d+%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today)))
70 calendar.id = naughty.notify({
71 replaces_id = calendar.id,
72 preset = calendar.notification_preset,
73 text = ws:gsub("\n*$", ""),
74 icon = calendar.notify_icon,
75 timeout = t_out or calendar.notification.preset.timeout or 5
80 function calendar.attach(widget, args)
81 local args = args or {}
82 calendar.cal = args.cal or "/usr/bin/cal --color=always"
83 calendar.followtag = args.followtag or false
84 calendar.icons = args.icons or helpers.icons_dir .. "cal/white/"
85 calendar.notification_preset = args.notification_preset
87 if not calendar.notification_preset then
88 calendar.notification_preset = {
89 font = "Monospace 10",
96 widget:connect_signal("mouse::enter", function () calendar.show(0) end)
97 widget:connect_signal("mouse::leave", function () calendar.hide() end)
98 widget:buttons(awful.util.table.join(awful.button({ }, 1, function ()
99 calendar.show(0, -1, calendar.scr_pos) end),
100 awful.button({ }, 3, function ()
101 calendar.show(0, 1, calendar.scr_pos) end),
102 awful.button({ }, 4, function ()
103 calendar.show(0, -1, calendar.scr_pos) end),
104 awful.button({ }, 5, function ()
105 calendar.show(0, 1, calendar.scr_pos) end)))