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 string = { format = string.format,
20 local tonumber = tonumber
22 local setmetatable = setmetatable
24 -- Calendar notification
25 -- lain.widgets.calendar
27 local cal_notification = nil
29 function calendar.hide()
30 if cal_notification ~= nil then
31 naughty.destroy(cal_notification)
32 cal_notification = nil
36 function calendar.show(t_out, inc_offset, scr)
40 local offs = inc_offset or 0
41 local tims = t_out or 0
42 local today = tonumber(os.date('%d'))
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 = string.format("%s%s.png", calendar.icons, today)
51 -- bg and fg inverted to highlight today
52 f = io.popen(calendar.cal_format(today))
53 else -- no current month showing, no day to highlight
54 local month = tonumber(os.date('%m'))
55 local year = tonumber(os.date('%Y'))
57 month = month + calendar.offset
69 calendar.notify_icon = nil
70 f = io.popen(string.format('%s %s %s', calendar.cal, month, year))
73 c_text = "<tt><span font='" .. calendar.font .. " "
74 .. calendar.font_size .. "'><b>"
75 .. f:read() .. "</b>\n\n"
77 .. f:read("*all"):gsub("\n*$", "")
81 if calendar.followtag then
82 scrp = awful.screen.focused()
84 scrp = scr or calendar.scr_pos
87 cal_notification = naughty.notify({
89 icon = calendar.notify_icon,
90 position = calendar.position,
98 function calendar.attach(widget, args)
99 local args = args or {}
101 calendar.cal = args.cal or "/usr/bin/cal"
102 calendar.cal_format = args.cal_format or function(today)
103 return string.format("%s | sed -r -e 's/_\\x08//g' -e '0,/(^| )%d($| )/ s/(^| )%d($| )/\\1<b><span foreground=\"%s\" background=\"%s\">%d<\\/span><\\/b>\\2/'",
104 calendar.cal, today, today, calendar.bg, calendar.fg, today)
106 calendar.icons = args.icons or icons_dir .. "cal/white/"
107 calendar.font = args.font or beautiful.font:gsub(" %d.*", "")
108 calendar.font_size = tonumber(args.font_size) or 11
109 calendar.fg = args.fg or beautiful.fg_normal or "#FFFFFF"
110 calendar.bg = args.bg or beautiful.bg_normal or "#000000"
111 calendar.position = args.position or "top_right"
112 calendar.scr_pos = args.scr_pos or 1
113 calendar.followtag = args.followtag or false
116 calendar.notify_icon = nil
118 widget:connect_signal("mouse::enter", function () calendar.show(0, 0, calendar.scr_pos) end)
119 widget:connect_signal("mouse::leave", function () calendar.hide() end)
120 widget:buttons(awful.util.table.join(awful.button({ }, 1, function ()
121 calendar.show(0, -1, calendar.scr_pos) end),
122 awful.button({ }, 3, function ()
123 calendar.show(0, 1, calendar.scr_pos) end),
124 awful.button({ }, 4, function ()
125 calendar.show(0, -1, calendar.scr_pos) end),
126 awful.button({ }, 5, function ()
127 calendar.show(0, 1, calendar.scr_pos) end)))
130 return setmetatable(calendar, { __call = function(_, ...) return create(...) end })