diff --git a/README.md b/README.md index cf03aa9..dc5b4ae 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,8 @@ A simple widget that can be attached to the `textclock` to show a monthly calendar. -This widget is a simple wrapper around: - -- the `cal` utility if you are using **4.0** <= Awesome < **4.2** -- `awful.widget.calendar_popup` if you are using Awesome >= **4.2** +This widget is a simple wrapper around `awful.widget.calendar_popup` available +in Awesome >= **4.2** Once the widget is attached to the `textclock` (or any other widget really), moving the mouse over the `textclock` will show a monthly calendar. The mouse @@ -18,8 +16,6 @@ is quite quick to load. # Installation -0. If you are using Awesome **4.x** less than **4.2**, ensure that the `cal` - utility from `util-linux` is available. 1. Copy `calendar.lua` in your `~/.config/awesome/` folder (e.g. by cloning this repository) 3. Restart Awesome (e.g. press `modkey + Control` or run `awesome-client diff --git a/calendar.lua b/calendar.lua index 7202be7..fef91bc 100644 --- a/calendar.lua +++ b/calendar.lua @@ -19,10 +19,8 @@ --[[ A simple tooltip that shows the calendar that can be attached to a widget. - Supported Awesome Version: 4.x + Supported Awesome Version >= 4.2 - If used with Awesome Version < 4.2 it requires the `cal` program from - `util-linux`, otherwise it will use the nicer awful.widget.calendar_popup Remember to `require` the widget **after** `beautiful.init` to ensure that the widget's style matches the theme. ]] @@ -35,127 +33,36 @@ local awful = require("awful") local calendar -if awful.widget.calendar_popup then - calendar = awful.widget.calendar_popup.month({position="tr"}) - function calendar:register(widget) - widget:connect_signal( - "mouse::enter", - function () - self:toggle() - end) - widget:connect_signal( - "mouse::leave", - function () - self:toggle() - end) - widget:buttons(awful.util.table.join( - awful.button({}, 1, function () - self:call_calendar(-1) - end), - awful.button({}, 4, function () - self:call_calendar(-1) - end), - awful.button({}, 2, function () - self:call_calendar(0) - end), - awful.button({}, 3, function () - self:call_calendar(1) - end), - awful.button({}, 5, function () - self:call_calendar(1) - end) - )) - end - -else - - calendar = awful.tooltip({}) - - local cached_date = { - day = tonumber(os.date("%d")), - month = tonumber(os.date("%m")), - year = tonumber(os.date("%Y")) - } - - function calendar:update() - local cmd = string.format( - "cal --color=never -m %s %s %s", - cached_date.day, cached_date.month, cached_date.year) - - awful.spawn.easy_async( - cmd, - function (stdout, stderr, _, exitcode) - if exitcode == 0 then - self:set_markup( - string.format( - '%s', - stdout)) - else - self:set_text( - string.format( - 'An error occurred while calling "%s":\n\n%s', - cmd, - stderr)) - end - end) - - end - - local function this_month(cal) - cached_date = {day = tonumber(os.date("%d")), - month = tonumber(os.date("%m")), - year = tonumber(os.date("%Y"))} - cal:update() - end - - local function next_month(cal) - local nm = cached_date.month + 1 - if nm > 12 then - cached_date.month = 1 - cached_date.year = cached_date.year + 1 - else - cached_date.month = nm - end - cal:update() - end - - local function prev_month(cal) - local nm = cached_date.month - 1 - if nm == 0 then - cached_date.month = 12 - cached_date.year = cached_date.year - 1 - else - cached_date.month = nm - end - cal:update() - end - - function calendar:register(widget) - self:add_to_object(widget) - widget:connect_signal( - "mouse::enter", - function () - this_month(self) - end) - widget:buttons(awful.util.table.join( - awful.button({}, 1, function () - next_month(self) - end), - awful.button({}, 4, function () - next_month(self) - end), - awful.button({}, 2, function () - this_month(self) - end), - awful.button({}, 3, function () - prev_month(self) - end), - awful.button({}, 5, function () - prev_month(self) - end) - )) - end +calendar = awful.widget.calendar_popup.month({position="tr"}) +function calendar:register(widget) + widget:connect_signal( + "mouse::enter", + function () + self:toggle() + end) + widget:connect_signal( + "mouse::leave", + function () + self:toggle() + end) + widget:buttons(awful.util.table.join( + awful.button({}, 1, function () + self:call_calendar(-1) + end), + awful.button({}, 4, function () + self:call_calendar(-1) + end), + awful.button({}, 2, function () + self:call_calendar(0) + end), + awful.button({}, 3, function () + self:call_calendar(1) + end), + awful.button({}, 5, function () + self:call_calendar(1) + end) + )) end return calendar