mirror of
https://github.com/elenapan/dotfiles.git
synced 2026-01-15 11:08:00 +08:00
evil daemon system, dependency list update, README improvements.
Former-commit-id: db310f8e49
Former-commit-id: 4f25f9200c3ac9f9385daca5a68378249ff0329e
Former-commit-id: 69fa3954e5738446a59b409b7e326233e7c3ef55
Former-commit-id: 673176f7857e39f3455f4ccb426eef2789c0e891
51 lines
1.4 KiB
Lua
51 lines
1.4 KiB
Lua
-- Provides:
|
|
-- evil::battery
|
|
-- percentage (integer)
|
|
-- evil::charger
|
|
-- plugged (boolean)
|
|
--
|
|
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 '
|
|
acpi_listen | grep --line-buffered ac_adapter
|
|
']]
|
|
|
|
-- 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)
|
|
status = tonumber(out)
|
|
if status == 1 then
|
|
awesome.emit_signal("evil::charger", true)
|
|
else
|
|
awesome.emit_signal("evil::charger", false)
|
|
end
|
|
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)
|