Reno is the second iteration of the AWMTK-powered AwesomeWM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

75 lines
3.5 KiB

-- This file is part of Reno desktop.
--
-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
--
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
-- Powerman X - second generation of the power management module
local awful = require("awful")
local sysctl = require("syscontrol")
local naughty = require("naughty")
local gears = require("gears")
local batteries = sysctl.power_supply.enumerate()
local state_tracking = {}
-- Configuration variables
local cfg = config.powerman or {}
local quality_min = cfg.battery_quality_min or 33
local capacity_min = cfg.battery_capacity_min or 15
local on_low_battery = cfg.on_low_battery or ""
local on_charged_battery = cfg.on_charged_battery
local on_critical_condition = cfg.on_critical_condition
-- Main loop
gears.timer({
timeout = 2,
autostart = true,
callback = function()
for _,v in pairs(batteries) do
local data,_ = sysctl.power_supply.read_attribs(v)
state_tracking[v] = state_tracking[v] or {}
if data.type == "Battery" then
if (tonumber(data.quality) < quality_min) and
(not state_tracking[v].quality_notification) then
naughty.notify({
title = "Critical battery condition",
text = "Battery "..data.name.." has reached critically low condition, seek a suitable replacement"
})
state_tracking[v].quality_notification = true
if on_critical_condition then
awful.spawn(on_critical_condition)
end
end
if (tonumber(data.capacity) <= capacity_min) and
(not data.charging) and
(not state_tracking[v].capacity_notification) then
naughty.notify({
title = "Battery capacity low",
text = "Battery "..data.name.." capacity is at "..tostring(data.capacity).."%"
})
state_tracking[v].capacity_notification = true
if on_low_battery then
awful.spawn(on_low_battery)
end
end
if (tonumber(data.capacity) > capacity_min) then
state_tracking[v].capacity_notification = false
end
if (data.capacity == "100") and
(data.charging) and
(not state_tracking[v].charged_notification) then
naughty.notify({
title = "Battery is completely charged",
text = "Disconnect the charger from the power grid to avoid passive electricity usage."
})
if on_charged_battery then
awful.spawn(on_charged_battery)
end
end
if (not data.charging) then
state_tracking[v].charged_notification = false
end
end
end
end
})