Remove upower dependency from evil battery daemon

This commit is contained in:
elenapan 2020-04-08 15:32:15 +03:00
parent 70d7fad947
commit 40412adc34
3 changed files with 37 additions and 31 deletions

View file

@ -61,7 +61,7 @@ Here are the instructions you should follow to replicate my AwesomeWM setup.
- **Ubuntu** 18.04 or newer (and all Ubuntu-based distributions)
```shell
sudo apt install rofi lm-sensors upower acpid jq fortune-mod redshift mpd mpc maim feh pulseaudio inotify-tools
sudo apt install rofi lm-sensors acpid jq fortune-mod redshift mpd mpc maim feh pulseaudio inotify-tools
# install light, which is not in the official ubuntu repositories
wget https://github.com/haikarainen/light/releases/download/v1.2/light_1.2_amd64.deb
@ -73,7 +73,7 @@ Here are the instructions you should follow to replicate my AwesomeWM setup.
*Assuming your AUR helper is* `yay`
```shell
yay -S rofi lm_sensors upower acpid jq fortune-mod redshift mpd mpc maim feh light-git pulseaudio inotify-tools
yay -S rofi lm_sensors acpid jq fortune-mod redshift mpd mpc maim feh light-git pulseaudio inotify-tools
```
3. Install needed fonts

View file

@ -8,12 +8,6 @@ local awful = require("awful")
local update_interval = 30
local battery_script = [[
sh -c "
upower -i $(upower -e | grep BAT) | grep percentage | awk '{print $2}'
"
]]
-- Subscribe to power supply status changes with acpi_listen
local charger_script = [[
sh -c '
@ -21,29 +15,36 @@ local charger_script = [[
'
]]
-- Periodically get battery info
awful.widget.watch(battery_script, update_interval, function(widget, stdout)
local battery = stdout:gsub("%%", "")
awesome.emit_signal("evil::battery", tonumber(battery))
end)
local emit_charger_info = function()
awful.spawn.easy_async_with_shell("cat /sys/class/power_supply/*/online", function (out)
local status = tonumber(out) == 1
awesome.emit_signal("evil::charger", status)
-- First get battery file path
-- If there are multiple, only get the first one
-- TODO support multiple batteries
awful.spawn.easy_async_with_shell("find /sys/class/power_supply/BAT?/capacity | head -1", function (battery_file)
-- Periodically get battery info
awful.widget.watch("cat "..battery_file, update_interval, function(_, stdout)
awesome.emit_signal("evil::battery", tonumber(stdout))
end)
end
-- Run once to initialize widgets
emit_charger_info()
-- Kill old acpi_listen process
awful.spawn.easy_async_with_shell("ps x | grep \"acpi_listen\" | grep -v grep | awk '{print $1}' | xargs kill", function ()
-- Update charger status with each line printed
awful.spawn.with_line_callback(charger_script, {
stdout = function(_)
emit_charger_info()
end
})
end)
-- First get charger file path
awful.spawn.easy_async_with_shell("find /sys/class/power_supply/*/online | head -1", function (charger_file)
-- Then initialize function that emits charger info
local emit_charger_info = function()
awful.spawn.easy_async_with_shell("cat "..charger_file, function (out)
local status = tonumber(out) == 1
awesome.emit_signal("evil::charger", status)
end)
end
-- Run once to initialize widgets
emit_charger_info()
-- Kill old acpi_listen process
awful.spawn.easy_async_with_shell("ps x | grep \"acpi_listen\" | grep -v grep | awk '{print $1}' | xargs kill", function ()
-- Update charger status with each line printed
awful.spawn.with_line_callback(charger_script, {
stdout = function(_)
emit_charger_info()
end
})
end)
end)

View file

@ -5,6 +5,7 @@ local notifications = require("notifications")
-- Helper variables
local charger_first_time = true
local battery_first_time = true
local charger_plugged = true
local battery_full_already_notified = true
local battery_low_already_notified = false
@ -18,6 +19,10 @@ awesome.connect_signal("evil::battery", function(battery)
local icon
local timeout
battery_current = battery
if battery_first_time then
battery_first_time = false
return
end
if not charger_plugged then
icon = icons.battery
if battery <= user.battery_threshold_critical and not battery_critical_already_notified then