From 3bbe7c6b3e95ca32e4bc653bb57e89b4333407b9 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 7 May 2015 21:59:55 +0200 Subject: add battery widget --- rc.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'rc.lua') diff --git a/rc.lua b/rc.lua index 3efde64..8119cf9 100644 --- a/rc.lua +++ b/rc.lua @@ -11,6 +11,7 @@ require("naughty") require("debian.menu") -- Load my modules +require("vicious") require("widgets.volume") require("widgets.cal") @@ -93,6 +94,31 @@ myvolumeicon = widget({ type = "imagebox" }) myvolumeicon.image = image(beautiful.widget_vol) myvolumeicon:buttons (myvolume:buttons ()) +mybat = widget({ type = "textbox" }) +mybaticon = widget({ type = "imagebox" }) +mybaticon.image = image(beautiful.widget_bat) +vicious.register(mybat, vicious.widgets.bat, function (widget, args) + -- If unknown, hide widget completely + if args[1] == "⌁" then + mybaticon.visible = false + mybat.visible = false + else + mybaticon.visible = true + mybat.visible = true + end + -- change color according to battery level + if args[2] < 20 then + color = beautiful.fg_bat_lo_widget + else + if args[2] > 80 then + color = beautiful.fg_bat_hi_widget + else + color = beautiful.fg_bat_mi_widget + end + end + return string.format('%d%%', color, args[2]) +end, 60, "BAT0") + myseparator = widget({ type = "imagebox" }) myseparator.image = image(beautiful.widget_sep) @@ -166,6 +192,7 @@ for s = 1, screen.count() do }, mylayoutbox[s], myvolume, myvolumeicon, + mybat, mybaticon, myseparator, mytextclock, s == 1 and mysystray or nil, -- cgit v1.2.3