This repository has been archived on 2024-09-01. You can view files and clone it, but cannot push or open issues or pull requests.
al-skel/awesome-home/.config/awesome/archlabs-extras/battery_bar.lua

48 lines
1.3 KiB
Lua
Raw Normal View History

2019-08-25 12:48:40 -05:00
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require("beautiful")
local xresources = require("beautiful.xresources")
local dpi = xresources.apply_dpi
-- Set colors
local active_color = beautiful.battery_bar_active_color or "#5AA3CC"
local background_color = beautiful.battery_bar_background_color or "#222222"
-- Configuration
local update_interval = 30 -- in seconds
local battery_bar = wibox.widget{
max_value = 100,
value = 50,
forced_height = dpi(10),
margins = {
top = dpi(8),
bottom = dpi(8),
},
forced_width = dpi(200),
shape = gears.shape.rounded_bar,
bar_shape = gears.shape.rounded_bar,
color = active_color,
background_color = background_color,
border_width = 0,
border_color = beautiful.border_color,
widget = wibox.widget.progressbar,
}
local function update_widget(bat)
battery_bar.value = tonumber(bat)
end
local bat_script = [[
bash -c "
upower -i $(upower -e | grep BAT) | grep percentage | awk '{print $2}'
"]]
awful.widget.watch(bat_script, update_interval, function(widget, stdout)
local bat = stdout:gsub("%%", "")
update_widget(bat)
end)
return battery_bar