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 tonumber = tonumber
20 local setmetatable = setmetatable
22 -- Calendar notification
23 -- lain.widgets.calendar
25 local cal_notification = nil
27 function calendar:hide()
28 if cal_notification ~= nil then
29 naughty.destroy(cal_notification)
30 cal_notification = nil
34 function calendar:show(t_out, inc_offset, scr)
37 local offs = inc_offset or 0
38 local tims = t_out or 0
40 local today = tonumber(os.date('%d'))
41 local init_t = calendar.cal .. ' ' .. calendar.post_cal .. ' ' ..
42 ' | sed -r -e "s/_\\x08//g" | sed -r -e "s/(^| )('
44 calendar.offset = calendar.offset + offs
46 if offs == 0 or calendar.offset == 0
47 then -- current month showing, today highlighted
49 calendar.notify_icon = calendar.icons .. today .. ".png"
51 -- bg and fg inverted to highlight today
52 f = io.popen( init_t .. today ..
53 ')($| )/\\1<b><span foreground=\\"'
57 '\\">\\2<\\/span><\\/b>\\3/"' )
59 else -- no current month showing, no day to highlight
60 local month = tonumber(os.date('%m'))
61 local year = tonumber(os.date('%Y'))
63 month = month + calendar.offset
79 calendar.notify_icon = nil
81 f = io.popen(calendar.cal .. ' ' .. month .. ' ' .. year .. ' ' ..
85 c_text = "<tt><span font='" .. calendar.font .. " "
86 .. calendar.font_size .. "'><b>"
87 .. f:read() .. "</b>\n\n"
89 .. f:read("*all"):gsub("\n*$", "")
93 if calendar.followmouse then
96 scrp = scr or calendar.scr_pos
99 cal_notification = naughty.notify({
101 icon = calendar.notify_icon,
102 position = calendar.position,
110 function calendar:attach(widget, args)
111 local args = args or {}
113 calendar.cal = args.cal or "/usr/bin/cal"
114 calendar.post_cal = args.post_cal or ""
115 calendar.icons = args.icons or icons_dir .. "cal/white/"
116 calendar.font = args.font or beautiful.font:gsub(" %d.*", "")
117 calendar.font_size = tonumber(args.font_size) or 11
118 calendar.fg = args.fg or beautiful.fg_normal or "#FFFFFF"
119 calendar.bg = args.bg or beautiful.bg_normal or "#000000"
120 calendar.position = args.position or "top_right"
121 calendar.scr_pos = args.scr_pos or 1
122 calendar.followmouse = args.followmouse or false
124 calendar.fg = string.sub(calendar.fg, 1, 7)
125 calendar.bg = string.sub(calendar.bg, 1, 7)
128 calendar.notify_icon = nil
130 widget:connect_signal("mouse::enter", function () calendar:show(0, 0, calendar.scr_pos) end)
131 widget:connect_signal("mouse::leave", function () calendar:hide() end)
132 widget:buttons(awful.util.table.join(awful.button({ }, 1, function ()
133 calendar:show(0, -1, calendar.scr_pos) end),
134 awful.button({ }, 3, function ()
135 calendar:show(0, 1, calendar.scr_pos) end),
136 awful.button({ }, 4, function ()
137 calendar:show(0, -1, calendar.scr_pos) end),
138 awful.button({ }, 5, function ()
139 calendar:show(0, 1, calendar.scr_pos) end)))
142 return setmetatable(calendar, { __call = function(_, ...) return create(...) end })