From 44a9da16e7c52f64cf2a073011905734f9cde5c0 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 1 Feb 2013 12:18:26 +0100 Subject: [PATCH] awesome: Show email counts in first wibox --- .config/awesome/rc.lua | 53 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index 565023c..d09593f 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua @@ -8,10 +8,13 @@ local beautiful = require("beautiful") -- Notification library local naughty = require("naughty") local menubar = require("menubar") +local lfs = require("lfs") awful.rules = require("awful.rules") require("awful.autofocus") +local maildir_base = os.getenv("HOME") .. "/documents/mail/" + function ror(program, cls) local rorfunc = function () local matcher = function (c) @@ -31,6 +34,25 @@ function ror_combo(mod, key, program, class) function () awful.util.spawn(program) end)) end +function new_mail(maildir) + local count = 0 + + for file in lfs.dir(maildir_base .. maildir .. "/new") do + if file ~= "." and file ~= ".." then + count = count + 1 + end + end + + for file in lfs.dir(maildir_base .. maildir .. "/cur") do + if string.sub(file, -1) ~= "S" and file ~= "." + and file ~= ".." then + count = count + 1 + end + end + + return count +end + ----- Error handling -- Check if awesome encountered an error during startup and fell back -- to another config (This code will only ever execute for the @@ -135,12 +157,32 @@ mypromptbox = {} mylayoutbox = {} mytaglist = {} mytasklist = {} +mymaillist = wibox.widget.textbox() +mymaillist:set_text( + string.format(" ryu: %d gmail: %d aethon: %d 9f: %d", + new_mail('ryuslash.org/inbox'), + new_mail('gmail/inbox'), + new_mail('aethon/inbox'), + new_mail('ninthfloor/inbox'))) +mymaillisttimer = timer({ timeout = 60 }) +mymaillisttimer:connect_signal( + "timeout", + function () + mymaillist:set_text( + string.format(" ryu: %d gmail: %d aethon: %d 9f: %d", + new_mail('ryuslash.org/inbox'), + new_mail('gmail/inbox'), + new_mail('aethon/inbox'), + new_mail('ninthfloor/inbox'))) + end) +mymaillisttimer:start() for s = 1, screen.count() do -- Create a promptbox for each screen mypromptbox[s] = awful.widget.prompt() - -- Create an imagebox widget which will contains an icon indicating which layout we're using. - -- We need one layoutbox per screen. + -- Create an imagebox widget which will contains an icon + -- indicating which layout we're using. We need one layoutbox per + -- screen. mylayoutbox[s] = awful.widget.layoutbox(s) -- Create a taglist widget mytaglist[s] = awful.widget.taglist( @@ -161,7 +203,10 @@ for s = 1, screen.count() do -- Widgets that are aligned to the right local right_layout = wibox.layout.fixed.horizontal() - if s == 1 then right_layout:add(wibox.widget.systray()) end + if s == 1 then + right_layout:add(mymaillist) + right_layout:add(wibox.widget.systray()) + end right_layout:add(mytextclock) right_layout:add(mylayoutbox[s]) @@ -251,7 +296,7 @@ globalkeys = awful.util.table.join( ror_combo({ modkey }, "c", 'urxvt', 'URxvt'), ror_combo({ modkey }, "w", 'conkeror', 'Conkeror'), awful.key({ "Control", "Mod1" }, "l", - function () awful.util.spawn('i3lock -c 000000') end)) + function () awful.util.spawn('i3lock -c 000000') end)) clientkeys = awful.util.table.join( awful.key({ modkey, }, "f",