Created
November 28, 2015 23:04
-
-
Save blueyed/dcc121cbcfcdc9a67019 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Battery widget(s) per battery (there might be BAT0 and BAT1). Interval: 61. {{{ | |
local batwidgets = {} | |
for _, batnr in ipairs({'0', '1'}) do | |
local bat = "BAT" .. batnr | |
local batwidget_notification = {} | |
local notification_dismissed | |
local notification_percent = 20 | |
local notification_always_percent = 5 | |
local batwidget = mybasewidget(awful.widget.progressbar()) | |
batwidgets[#batwidgets+1] = batwidget | |
batwidget:set_width(8) | |
batwidget:set_vertical(true) | |
local f = io.open('/sys/class/power_supply/' .. bat) | |
-- TODO: "if not f | return" instead. | |
if f then | |
f:close() | |
my_vicious_register(batwidget, vicious.widgets.bat, function(widget, args) | |
local unpack = unpack or table.unpack -- Lua 5.3: table.unpack | |
local state, percent, time, wear = unpack(args) | |
if state == "⌁" then -- "Unknown" | |
widget:set_width(0) | |
elseif state == "↯" then -- "Charged" | |
-- Hide it only for != BAT0 (usually the only battery then). | |
widget:set_width(0) | |
else | |
widget:set_width(8) | |
if bat == "BAT0" and state == "−" and percent <= notification_percent then -- "Discharging" | |
if not notification_dismissed or percent <= notification_always_percent then | |
batwidget_notification = naughty.notify({ | |
preset = naughty.config.presets.critical, | |
title = "Battery level is critical!", | |
text = "Battery is at "..percent.." percent.", | |
run = function(notification) | |
notification_dismissed = percent | |
notification.die(naughty.notificationClosedReason.dismissedByUser) | |
end, | |
replaces_id = batwidget_notification.id}) | |
end | |
elseif batwidget_notification.id then | |
naughty.destroy(batwidget_notification) | |
notification_dismissed = false | |
end | |
if percent <= 25 then | |
widget:set_color(bat == "BAT0" and "#FF5656" or "#AA5656") | |
else | |
widget:set_color("#AECF96") | |
end | |
end | |
return percent, function() | |
return bat .. ": " .. state .. " " .. percent .. "%, time:" .. time .. ", wear: " .. wear | |
end | |
end, 61, bat) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment