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

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. -- This file is part of Reno desktop.
  2. --
  3. -- 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.
  4. --
  5. -- 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.
  6. --
  7. -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
  8. -- Powerman X - second generation of the power management module
  9. local awful = require("awful")
  10. local sysctl = require("syscontrol")
  11. local naughty = require("naughty")
  12. local gears = require("gears")
  13. local batteries = sysctl.power_supply.enumerate()
  14. local state_tracking = {}
  15. -- Configuration variables
  16. local cfg = config.powerman or {}
  17. local quality_min = cfg.battery_quality_min or 33
  18. local capacity_min = cfg.battery_capacity_min or 15
  19. local on_low_battery = cfg.on_low_battery or ""
  20. local on_charged_battery = cfg.on_charged_battery
  21. local on_critical_condition = cfg.on_critical_condition
  22. -- Main loop
  23. gears.timer({
  24. timeout = 2,
  25. autostart = true,
  26. callback = function()
  27. for _,v in pairs(batteries) do
  28. local data,_ = sysctl.power_supply.read_attribs(v)
  29. state_tracking[v] = state_tracking[v] or {}
  30. if data.type == "Battery" then
  31. if (tonumber(data.quality) < quality_min) and
  32. (not state_tracking[v].quality_notification) then
  33. naughty.notify({
  34. title = "Critical battery condition",
  35. text = "Battery "..data.name.." has reached critically low condition, seek a suitable replacement"
  36. })
  37. state_tracking[v].quality_notification = true
  38. if on_critical_condition then
  39. awful.spawn(on_critical_condition)
  40. end
  41. end
  42. if (tonumber(data.capacity) <= capacity_min) and
  43. (not data.charging) and
  44. (not state_tracking[v].capacity_notification) then
  45. naughty.notify({
  46. title = "Battery capacity low",
  47. text = "Battery "..data.name.." capacity is at "..tostring(data.capacity).."%"
  48. })
  49. state_tracking[v].capacity_notification = true
  50. if on_low_battery then
  51. awful.spawn(on_low_battery)
  52. end
  53. end
  54. if (tonumber(data.capacity) > capacity_min) then
  55. state_tracking[v].capacity_notification = false
  56. end
  57. if (data.capacity == "100") and
  58. (data.charging) and
  59. (not state_tracking[v].charged_notification) then
  60. naughty.notify({
  61. title = "Battery is completely charged",
  62. text = "Disconnect the charger from the power grid to avoid passive electricity usage."
  63. })
  64. if on_charged_battery then
  65. awful.spawn(on_charged_battery)
  66. end
  67. end
  68. if (not data.charging) then
  69. state_tracking[v].charged_notification = false
  70. end
  71. end
  72. end
  73. end
  74. })