local wibox = require("wibox")
-- Create a textclock widget
-mytextclock = awful.widget.textclock(" %a %b %d, %k:%M ", 10)
separator = wibox.widget.textbox()
separator:set_markup('<span font="Symbola 10" color="#404040">│</span>')
right_layout:add(require("widgets/battery_widget"))
end
right_layout:add(separator)
- right_layout:add(mytextclock)
+ right_layout:add(require("widgets/calendar"))
right_layout:add(mylayoutbox[s])
-- Now bring it all together (with the tasklist in the middle)
--- /dev/null
+--[[
+
+ Licensed under GNU General Public License v2
+ * (c) 2014-, Samir Benmendil
+ * (c) -2013, Luke Bonham (lain)
+
+--]]
+
+local awful = require("awful")
+local beautiful = require("beautiful")
+local naughty = require("naughty")
+
+local io = { popen = io.popen }
+local os = { date = os.date }
+local tonumber = tonumber
+
+local calendar = {}
+calendar.cal = "/usr/bin/cal --color=always"
+calendar.font = "monospace 10"
+calendar.fg = beautiful.fg_normal or "#FFFFFF"
+calendar.bg = beautiful.bg_normal or "#FFFFFF"
+calendar.position = "top_right"
+calendar.offset = 0
+
+local calwidget = awful.widget.textclock(" %a %b %d, %k:%M ", 10)
+
+calwidget:connect_signal("mouse::enter", function () calendar:show(0) end)
+calwidget:connect_signal("mouse::leave", function () calendar:hide() end)
+calwidget:buttons(awful.util.table.join(
+ awful.button({ }, 1, function () calendar:show(-1) end),
+ awful.button({ }, 3, function () calendar:show( 1) end),
+ awful.button({ }, 4, function () calendar:show(-1) end),
+ awful.button({ }, 5, function () calendar:show( 1) end)))
+
+-- Calendar notification
+local cal_notification = nil
+
+function calendar:hide()
+ if cal_notification ~= nil then
+ naughty.destroy(cal_notification)
+ cal_notification = nil
+ end
+end
+
+function calendar:show(inc_offset)
+ calendar:hide()
+
+ local offs = inc_offset or 0
+
+ calendar.offset = calendar.offset + offs
+
+ local today = tonumber(os.date('%d'))
+ local month = tonumber(os.date('%m'))
+ local year = tonumber(os.date('%Y'))
+
+ if offs ~= 0 or calendar.offset ~= 0
+ then -- no current month showing, no day to highlight
+ month = month + calendar.offset
+
+ if month > 12 then
+ month = month % 12
+ year = year + 1
+ if month <= 0 then
+ month = 12
+ end
+ elseif month < 1 then
+ month = month + 12
+ year = year - 1
+ if month <= 0 then
+ month = 1
+ end
+ end
+ end
+
+ local f = io.popen(calendar.cal .. ' ' .. month .. ' ' .. year)
+
+ local text = string.format("<span font='%s'><b>%s</b>\n%s</span>",
+ calendar.font,
+ f:read(),
+ f:read("*a"):gsub("%s\n","\n"):gsub("%s+$", ""))
+ f:close()
+
+ text = text:gsub("\e%[7m","<b><span "
+ .. "foreground='"..calendar.bg .. "' "
+ .. "background='"..calendar.fg .. "'>")
+ text = text:gsub("\e%[27m", "</span></b>")
+
+ cal_notification = naughty.notify({
+ text = text,
+ position = calendar.position,
+ fg = calendar.fg,
+ bg = calendar.bg,
+ screen = mouse.screen
+ })
+end
+
+return calwidget