mirror of
https://github.com/streetturtle/awesome-wm-widgets.git
synced 2024-11-17 07:49:09 +01:00
Battery widget for awesome
This commit is contained in:
parent
afad5c9d8f
commit
336a88219b
6 changed files with 45 additions and 0 deletions
BIN
battery-icons/100.png
Normal file
BIN
battery-icons/100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
battery-icons/20.png
Normal file
BIN
battery-icons/20.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
battery-icons/40.png
Normal file
BIN
battery-icons/40.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
battery-icons/60.png
Normal file
BIN
battery-icons/60.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
battery-icons/80.png
Normal file
BIN
battery-icons/80.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
45
battery.lua
Normal file
45
battery.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
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",
|
||||
timeout = 2, hover_timeout = 0.5,
|
||||
width = 160,
|
||||
})
|
||||
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
|
||||
end
|
||||
|
||||
batteryIcon:set_image("/home/pashik/.config/awesome/battery-icons/" .. batteryType .. ".png")
|
||||
end
|
||||
|
||||
batteryIcon = wibox.widget.imagebox()
|
||||
showBatteryWidgetIcon()
|
||||
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:start()
|
Loading…
Reference in a new issue