3 Licensed under GNU General Public License v2
4 * (c) 2014-, Samir Benmendil
5 * (c) -2013, Luke Bonham (lain)
9 local awful = require("awful")
10 local beautiful = require("beautiful")
11 local naughty = require("naughty")
13 local io = { popen = io.popen }
14 local os = { date = os.date }
15 local tonumber = tonumber
18 calendar.cal = "/usr/bin/cal --color=always"
19 calendar.font = "monospace 10"
20 calendar.fg = beautiful.fg_normal or "#FFFFFF"
21 calendar.bg = beautiful.bg_normal or "#FFFFFF"
22 calendar.position = "top_right"
25 local calwidget = awful.widget.textclock(" %a %b %d, %k:%M ", 10)
27 calwidget:connect_signal("mouse::enter", function () calendar:show(0) end)
28 calwidget:connect_signal("mouse::leave", function () calendar:hide() end)
29 calwidget:buttons(awful.util.table.join(
30 awful.button({ }, 1, function () calendar:show(-1) end),
31 awful.button({ }, 3, function () calendar:show( 1) end),
32 awful.button({ }, 4, function () calendar:show(-1) end),
33 awful.button({ }, 5, function () calendar:show( 1) end)))
35 -- Calendar notification
36 local cal_notification = nil
38 function calendar:hide()
39 if cal_notification ~= nil then
40 naughty.destroy(cal_notification)
41 cal_notification = nil
45 function calendar:show(inc_offset)
48 local offs = inc_offset or 0
50 calendar.offset = calendar.offset + offs
52 local today = tonumber(os.date('%d'))
53 local month = tonumber(os.date('%m'))
54 local year = tonumber(os.date('%Y'))
56 if offs ~= 0 or calendar.offset ~= 0
57 then -- no current month showing, no day to highlight
58 month = month + calendar.offset
75 local f = io.popen(calendar.cal .. ' ' .. month .. ' ' .. year)
77 local text = string.format("<span font='%s'><b>%s</b>\n%s</span>",
80 f:read("*a"):gsub("%s\n","\n"):gsub("%s+$", ""))
83 text = text:gsub("
\e%[7m","<b><span "
84 .. "foreground='"..calendar.bg .. "' "
85 .. "background='"..calendar.fg .. "'>")
86 text = text:gsub("
\e%[27m", "</span></b>")
88 cal_notification = naughty.notify({
90 position = calendar.position,