]> git.rmz.io Git - dotfiles.git/commitdiff
awesome: calendar widget
authorSamir Benmendil <samir.benmendil@gmail.com>
Wed, 10 Dec 2014 00:09:28 +0000 (00:09 +0000)
committerSamir Benmendil <samir.benmendil@gmail.com>
Wed, 10 Dec 2014 06:33:39 +0000 (06:33 +0000)
that silly lain widget just didn't work way I wanted it to. Importing
and modifying it to my needs

awesome/rc.lua
awesome/topbar.lua
awesome/widgets/calendar.lua [new file with mode: 0644]

index b91d41cd33e3a1bf444595c2a48d7ca30faa804b..1bf335e48c47df1833c73e6e636dd42dd5256db8 100644 (file)
@@ -1,4 +1,4 @@
--- Standard awesome library {{{1
+-- Awesome libraries {{{1
 gears = require("gears")
 awful = require("awful")
 awful.rules = require("awful.rules")
index b945d80193a7dd846dd4c5ffd579344168ca8cec..638e9675edae866cf4048e4254dbf4310619d0d8 100644 (file)
@@ -5,7 +5,6 @@ local utils = require("utils")
 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>')
 
@@ -97,7 +96,7 @@ for s = 1, screen.count() do
         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)
diff --git a/awesome/widgets/calendar.lua b/awesome/widgets/calendar.lua
new file mode 100644 (file)
index 0000000..cdf58ae
--- /dev/null
@@ -0,0 +1,97 @@
+--[[
+
+     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