summaryrefslogtreecommitdiff
path: root/BatteryWidget/battery.lua
diff options
context:
space:
mode:
Diffstat (limited to 'BatteryWidget/battery.lua')
-rw-r--r--BatteryWidget/battery.lua44
1 files changed, 27 insertions, 17 deletions
diff --git a/BatteryWidget/battery.lua b/BatteryWidget/battery.lua
index 09e0ed6..3e9dd9a 100644
--- a/BatteryWidget/battery.lua
+++ b/BatteryWidget/battery.lua
@@ -7,39 +7,49 @@ function showBatteryWidgetPopup()
naughty.notify({
text = awful.util.pread("acpi | cut -d, -f 2,3"),
title = "Battery status",
- timeout = 2, hover_timeout = 0.5,
+ timeout = 5, hover_timeout = 0.5,
width = 160,
})
end
+function showWarningWidgetPopup()
+ local charge = tonumber(awful.util.pread("acpi | cut -d, -f 2 | egrep -o '[0-9]{1,3}'"))
+ if (charge < 15) then
+ naughty.notify({
+ text = "Huston, we have a problem",
+ title = "Battery dying",
+ timeout = 5, hover_timeout = 0.5,
+ position = "bottom_right",
+ bg = "#ff1122",
+ width = 160,
+ })
+ end
+end
+
function showBatteryWidgetIcon()
local charge = tonumber(awful.util.pread("acpi | cut -d, -f 2 | egrep -o '[0-9]{1,3}'"))
local batteryType
if (charge >= 0 and charge < 20) then batteryType=20
- elseif (charge >= 20 and charge < 40) then batteryType=40
- elseif (charge >= 40 and charge < 60) then batteryType=60
- elseif (charge >= 60 and charge < 80) then batteryType=80
- elseif (charge >= 80 and charge < 100) then batteryType=100
+ elseif (charge >= 20 and charge < 40) then batteryType=40
+ elseif (charge >= 40 and charge < 60) then batteryType=60
+ elseif (charge >= 60 and charge < 80) then batteryType=80
+ elseif (charge >= 80 and charge <= 100) then batteryType=100
end
- batteryIcon:set_image("/home/pashik/.config/awesome/battery-icons/" .. batteryType .. ".png")
+ batteryIcon:set_image("/home/username/.config/awesome/battery-icons/" .. batteryType .. ".png")
end
batteryIcon = wibox.widget.imagebox()
showBatteryWidgetIcon()
-batteryIcon:connect_signal("mouse::enter",
- function()
- showBatteryWidgetPopup()
- end
-)
+batteryIcon:connect_signal("mouse::enter", function() showBatteryWidgetPopup() end)
-- timer to refresh battery icon
batteryWidgetTimer = timer({ timeout = 5 })
-batteryWidgetTimer:connect_signal("timeout",
- function()
- showBatteryWidgetIcon()
- end
-)
+batteryWidgetTimer:connect_signal("timeout", function() showBatteryWidgetIcon() end)
+batteryWidgetTimer:start()
-batteryWidgetTimer:start() \ No newline at end of file
+-- timer to refresh battery warning
+batteryWarningTimer = timer({ timeout = 50 })
+batteryWarningTimer:connect_signal("timeout", function() showWarningWidgetPopup() end)
+batteryWarningTimer:start() \ No newline at end of file