awesome-wm-widgets/BatteryWidget/battery.lua

57 lines
1.8 KiB
Lua
Raw Normal View History

2015-07-12 16:05:47 +02:00
local wibox = require("wibox")
local awful = require("awful")
local naughty = require("naughty")
function showBatteryWidgetPopup()
local save_offset = offset
naughty.notify({
text = awful.util.pread("acpi | cut -d, -f 2,3"),
title = "Battery status",
2015-07-18 10:11:36 +02:00
timeout = 5, hover_timeout = 0.5,
2015-07-12 16:05:47 +02:00
width = 160,
})
end
2015-07-18 10:11:36 +02:00
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",
2015-12-25 23:28:08 +01:00
bg = "#F06060",
fg = "#EEE9EF",
width = 200,
2015-07-18 10:11:36 +02:00
})
end
end
2015-07-12 16:05:47 +02:00
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
2015-07-18 10:11:36 +02:00
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
2015-07-12 16:05:47 +02:00
end
2015-07-18 10:11:36 +02:00
batteryIcon:set_image("/home/username/.config/awesome/battery-icons/" .. batteryType .. ".png")
2015-07-12 16:05:47 +02:00
end
batteryIcon = wibox.widget.imagebox()
showBatteryWidgetIcon()
2015-07-18 10:11:36 +02:00
batteryIcon:connect_signal("mouse::enter", function() showBatteryWidgetPopup() end)
2015-07-12 16:05:47 +02:00
-- timer to refresh battery icon
batteryWidgetTimer = timer({ timeout = 5 })
2015-07-18 10:11:36 +02:00
batteryWidgetTimer:connect_signal("timeout", function() showBatteryWidgetIcon() end)
batteryWidgetTimer:start()
2015-07-12 16:05:47 +02:00
2015-07-18 10:11:36 +02:00
-- timer to refresh battery warning
batteryWarningTimer = timer({ timeout = 50 })
batteryWarningTimer:connect_signal("timeout", function() showWarningWidgetPopup() end)
2015-12-25 23:28:08 +01:00
batteryWarningTimer:start()