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 }
17 local tonumber = tonumber
19 local setmetatable = setmetatable
21 -- Calendar notification
22 -- lain.widgets.calendar
24 local cal_notification = nil
26 function calendar:hide()
27 if cal_notification ~= nil then
28 naughty.destroy(cal_notification)
29 cal_notification = nil
33 function calendar:show(t_out, inc_offset, scr)
36 local offs = inc_offset or 0
37 local tims = t_out or 0
39 local today = tonumber(os.date('%d'))
40 local init_t = calendar.cal .. ' | sed -r -e "s/_\\x08//g" | sed -r -e "s/(^| )('
42 calendar.offset = calendar.offset + offs
44 if offs == 0 or calendar.offset == 0
45 then -- current month showing, today highlighted
47 calendar.notify_icon = calendar.icons .. today .. ".png"
49 -- bg and fg inverted to highlight today
50 f = io.popen( init_t .. today ..
51 ')($| )/\\1<b><span foreground=\\"'
55 '\\">\\2<\\/span><\\/b>\\3/"' )
57 else -- no current month showing, no day to highlight
58 local month = tonumber(os.date('%m'))
59 local year = tonumber(os.date('%Y'))
61 month = month + calendar.offset
77 calendar.notify_icon = nil
79 f = io.popen(calendar.cal .. ' ' .. month .. ' ' .. year)
82 c_text = "<tt><span font='" .. calendar.font .. " "
83 .. calendar.font_size .. "'><b>"
84 .. f:read() .. "</b>\n\n"
86 .. f:read("*a"):gsub("\n*$", "")
90 cal_notification = naughty.notify({
92 icon = calendar.notify_icon,
93 position = calendar.position,
101 function calendar:attach(widget, args)
102 local args = args or {}
103 calendar.cal = args.cal or "/usr/bin/cal"
104 calendar.icons = args.icons or icons_dir .. "cal/white/"
105 calendar.font = args.font or beautiful.font:sub(beautiful.font:find(""),
106 beautiful.font:find(" "))
107 calendar.font_size = tonumber(args.font_size) or 11
108 calendar.fg = args.fg or beautiful.fg_normal or "#FFFFFF"
109 calendar.bg = args.bg or beautiful.bg_normal or "#FFFFFF"
110 calendar.position = args.position or "top_right"
111 calendar.scr_pos = args.scr_pos or 1
114 calendar.notify_icon = nil
116 widget:connect_signal("mouse::enter", function () calendar:show(0, 0, scr_pos) end)
117 widget:connect_signal("mouse::leave", function () calendar:hide() end)
118 widget:buttons(awful.util.table.join( awful.button({ }, 1, function ()
119 calendar:show(0, -1, scr_pos) end),
120 awful.button({ }, 3, function ()
121 calendar:show(0, 1, scr_pos) end),
122 awful.button({ }, 4, function ()
123 calendar:show(0, -1, scr_pos) end),
124 awful.button({ }, 5, function ()
125 calendar:show(0, 1, scr_pos) end)))
128 return setmetatable(calendar, { __call = function(_, ...) return create(...) end })