diff --git a/rc.lua b/rc.lua index 274a024..c9ebef7 100644 --- a/rc.lua +++ b/rc.lua @@ -39,6 +39,7 @@ widgets.mem = require("widgets.mem") widgets.net = require("widgets.net") widgets.spacer = require("widgets.spacer") widgets.volume = require("widgets.volume") +widgets.im = require("widgets.im") -- }}} -- {{{ Variable definitions @@ -122,10 +123,6 @@ end utils.rc.loadrc('menu') -- }}} --- {{{ Wibox -utils.rc.loadrc('wibox') --- }}} - -- {{{ Naughty utils.rc.loadrc('naughty') -- }}} @@ -134,6 +131,10 @@ utils.rc.loadrc('naughty') utils.rc.loadrc('im') -- }}} +-- {{{ Wibox +utils.rc.loadrc('wibox') +-- }}} + -- {{{ Programs to run at startup -- Disabled, managed by Xsession -- utils.rc.loadrc('startup') diff --git a/rc/im.lua b/rc/im.lua index b6ab7fb..9e91440 100644 --- a/rc/im.lua +++ b/rc/im.lua @@ -73,16 +73,4 @@ function mcabber_event_hook(kind, arg, jid, msg) end end - -function mcabber_get_unread_buffers() - local state_file = os.getenv("HOME") .. "/.mcabber/mcabber.state" - local f = io.open(state_file, "r") - local rows = 0 - for _ in f:lines() do - rows = rows + 1 - end - f:close() - return rows -end - -- vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/rc/wibox.lua b/rc/wibox.lua index acb8eb4..152a495 100644 --- a/rc/wibox.lua +++ b/rc/wibox.lua @@ -29,7 +29,9 @@ for s = 1, screen.count() do widgets.clock.widget(), s == 1 and widget({ type = "systray" }) or nil, widgets.spacer.widget(), - widgets.net.widget(), + widgets.im.widget(), + widgets.im.icon(), + -- widgets.net.widget(), utils.system.hasbattery() and widgets.spacer.widget() or nil, utils.system.hasbattery() and widgets.bat.widget(wide) or nil, utils.system.hasbattery() and widgets.bat.icon() or nil, diff --git a/themes/gits/icons/im.png b/themes/gits/icons/im.png new file mode 100644 index 0000000..9067483 Binary files /dev/null and b/themes/gits/icons/im.png differ diff --git a/themes/gits/theme.lua b/themes/gits/theme.lua index 4b6e0a6..01c1a7f 100644 --- a/themes/gits/theme.lua +++ b/themes/gits/theme.lua @@ -161,6 +161,7 @@ theme.widget_disk = themedir.."/icons/disk.png" theme.widget_mpd_play = themedir.."/icons/mpd_play.png" theme.widget_mpd_pause = themedir.."/icons/mpd_pause.png" theme.widget_mpd_stop = themedir.."/icons/mpd_stop.png" +theme.widget_im = themedir.."/icons/im.png" -- }}} return theme diff --git a/widgets/im.lua b/widgets/im.lua new file mode 100644 index 0000000..05008de --- /dev/null +++ b/widgets/im.lua @@ -0,0 +1,39 @@ +-- File system size widget definition +-- Module variables are : +-- +-- widget : the wiget itself +-- icon : the associated widget icon +-- +-- Note that he theme should have widget_disk attribute set + +local vicious = require("vicious") +local awful = require("awful") +local blingbling = require("blingbling") +local mcabber = require("widgets.vicious.mcabber") +local beautiful = beautiful +local widget_init = widget +local image = image +local mcabber_get_unread_buffers = mcabber_get_unread_buffers + +module("widgets.im") + +local _imicon = nil +local _imwidget = nil + +function icon() + if _imicon == nil then + _imicon = widget_init({ type = "imagebox" }) + _imicon.image = image(beautiful.widget_im) + end + return _imicon +end + +function widget() + if _imwidget == nil then + _imwidget = widget_init({ type = "textbox" }) + vicious.register(_imwidget, mcabber,'$1', 5) + end + return _imwidget +end + +-- vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/widgets/vicious/mcabber.lua b/widgets/vicious/mcabber.lua new file mode 100644 index 0000000..9c26568 --- /dev/null +++ b/widgets/vicious/mcabber.lua @@ -0,0 +1,61 @@ +--------------------------------------------------- +-- Licensed under the GNU General Public License v2 +-- * (c) 2010, Adrian C. +-- * (c) 2009, Lucas de Vries +--------------------------------------------------- + +-- {{{ Grab environment +local os = { getenv=os.getenv } +local io = { open=io.open, popen=io.popen } +local print = print +-- }}} + +-- Count: provides mcabber unread buffers count +local count = {} + + +-- {{{ Checks if mcabber is running +local function mcabber_get_unread_buffers() + local state_file = os.getenv("HOME") .. "/.mcabber/mcabber.state" + local f = io.open(state_file, "r") + local rows = 0 + for _ in f:lines() do + rows = rows + 1 + end + f:close() + return rows +end +-- }}} + + +-- {{{ Counts unread mcabber buffers +local function mcabber_running() + local fd = io.popen("pgrep mcabber") + local pid = fd:read('*a') + fd:close() + + if pid:len() > 0 then + return true + else + return false + end +end +-- }}} + + +-- {{{ Date widget type +local function worker(format, warg) + if not mcabber_running() then + return ' n/a ' + end + + local unread = mcabber_get_unread_buffers() + if unread > 0 then + return ' ' .. unread .. ' ' + else + return ' 0 ' + end +end +-- }}} + +return setmetatable(count, { __call = function(_, ...) return worker(...) end })