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")
16 local os = { date = os.date }
17 local tonumber = tonumber
19 local setmetatable = setmetatable
21 -- Calendar notification
22 -- lain.widgets.calendar
24 local notification = nil
26 local function create(foreground, background)
28 calendar.icons_dir = icons_dir .. "cal/white/" -- default
29 calendar.notify_icon = nil
30 calendar.font_size = 12
31 calendar.bg = background or beautiful.bg_normal or "#FFFFFF"
32 calendar.fg = foreground or beautiful.fg_focus or "#FFFFFF"
35 function calendar:hide()
36 if notification ~= nil then
37 naughty.destroy(notification)
42 function calendar:show(t_out, inc_offset)
45 local offs = inc_offset or 0
46 local tims = t_out or 0
48 local today = tonumber(os.date('%d'))
49 local init_t = '/usr/bin/cal | sed -r -e "s/(^| )( '
50 -- let's take font only, font size is set in calendar table
51 local font = beautiful.font:sub(beautiful.font:find(""),
52 beautiful.font:find(" "))
55 then -- current month showing, today highlighted
58 init_t = '/usr/bin/cal | sed -r -e "s/(^| )('
62 calendar.notify_icon = calendar.icons_dir .. today .. ".png"
64 -- bg and fg inverted to highlight today
65 f = io.popen( init_t .. today ..
66 ')($| )/\\1<b><span foreground=\\"'
70 '\\">\\2<\\/span><\\/b>\\3/"' )
72 else -- no current month showing, no day to highlight
73 local month = tonumber(os.date('%m'))
74 local year = tonumber(os.date('%Y'))
76 calendar.offset = calendar.offset + offs
77 month = month + calendar.offset
93 calendar.notify_icon = nil
95 f = io.popen('/usr/bin/cal ' .. month .. ' ' .. year)
99 c_text = "<tt><span font='" .. font .. " "
100 .. calendar.font_size .. "'><b>"
101 .. f:read() .. "</b>\n\n"
103 .. f:read("*all"):gsub("\n*$", "")
107 notification = naughty.notify({ text = c_text,
108 icon = calendar.notify_icon,
114 function calendar:attach(widget, foreground, background)
115 create(foreground, background)
116 widget:connect_signal("mouse::enter", function () calendar:show() 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) end),
120 awful.button({ }, 3, function ()
121 calendar:show(0, 1) end) ))
124 return setmetatable(calendar, { __call = function(_, ...) return create(...) end })