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 icons_dir = require("lain.helpers").icons_dir
11 local awful = require("awful")
12 local beautiful = require("beautiful")
13 local naughty = require("naughty")
15 local io = { popen = io.popen }
16 local os = { date = os.date }
18 local string = { format = string.format,
21 local tonumber = tonumber
23 local setmetatable = setmetatable
25 -- Calendar notification
28 local cal_notification = nil
30 function calendar:hide()
31 if cal_notification ~= nil then
32 naughty.destroy(cal_notification)
33 cal_notification = nil
37 function calendar:show(t_out, inc_offset, scr)
41 local offs = inc_offset or 0
42 local tims = t_out or 0
43 local today = tonumber(os.date('%d'))
44 local init_t = string.format("%s %s | sed -e 's/[\b]\\{3\\}//g'",
45 calendar.cal, calendar.post_cal)
47 calendar.offset = calendar.offset + offs
49 if offs == 0 or calendar.offset == 0
50 then -- current month showing, today highlighted
52 calendar.notify_icon = calendar.icons .. today .. ".png"
54 -- bg and fg inverted to highlight today
55 f = io.popen(string.format("%s -e '0,/%d/ s/%d/<b><span foreground=\"%s\" background=\"%s\">%d<\\/span><\\/b>/'",
56 init_t, today, today, calendar.bg, calendar.fg, today))
58 else -- no current month showing, no day to highlight
59 local month = tonumber(os.date('%m'))
60 local year = tonumber(os.date('%Y'))
62 month = month + calendar.offset
78 calendar.notify_icon = nil
80 f = io.popen(string.format('%s %s %s %s', calendar.cal, month, year, calendar.post_cal))
83 c_text = " <tt><span font='" .. calendar.font .. " "
84 .. calendar.font_size .. "'><b>"
85 .. f:read() .. "</b>\n\n"
87 .. f:read("*all"):gsub("\n*$", "")
91 if calendar.followmouse then
94 scrp = scr or calendar.scr_pos
97 cal_notification = naughty.notify({
99 icon = calendar.notify_icon,
100 position = calendar.position,
108 function calendar:attach(widget, args)
109 local args = args or {}
111 calendar.cal = args.cal or "/usr/bin/cal"
112 calendar.post_cal = args.post_cal or ""
113 calendar.icons = args.icons or icons_dir .. "cal/white/"
114 calendar.font = args.font or beautiful.font:gsub(" %d.*", "")
115 calendar.font_size = tonumber(args.font_size) or 11
116 calendar.fg = args.fg or beautiful.fg_normal or "#FFFFFF"
117 calendar.bg = args.bg or beautiful.bg_normal or "#000000"
118 calendar.position = args.position or "top_right"
119 calendar.scr_pos = args.scr_pos or 1
120 calendar.followmouse = args.followmouse or false
122 calendar.fg = string.sub(calendar.fg, 1, 7)
123 calendar.bg = string.sub(calendar.bg, 1, 7)
126 calendar.notify_icon = nil
128 widget:connect_signal("mouse::enter", function () calendar:show(0, 0, calendar.scr_pos) end)
129 widget:connect_signal("mouse::leave", function () calendar:hide() end)
130 widget:buttons(awful.util.table.join(awful.button({ }, 1, function ()
131 calendar:show(0, -1, calendar.scr_pos) end),
132 awful.button({ }, 3, function ()
133 calendar:show(0, 1, calendar.scr_pos) end),
134 awful.button({ }, 4, function ()
135 calendar:show(0, -1, calendar.scr_pos) end),
136 awful.button({ }, 5, function ()
137 calendar:show(0, 1, calendar.scr_pos) end)))
140 return setmetatable(calendar, { __call = function(_, ...) return create(...) end })