diff options
| author | venomade <venomade@venomade.com> | 2026-02-11 11:42:58 +0000 |
|---|---|---|
| committer | venomade <venomade@venomade.com> | 2026-02-11 11:42:58 +0000 |
| commit | 0bd150185551b6d8835d022c15a5f6e832d51113 (patch) | |
| tree | 10bf3f3443df49a44eb47b328b73b7e76b0a4924 /.config/luastatus/battery.lua | |
| parent | 8d688d1107c46b6dfdcaf02fa5c9c4c8a4640e65 (diff) | |
Asahi
Soft reset of dotfiles specific to Asahi, Sway and Neovim.
Diffstat (limited to '.config/luastatus/battery.lua')
| -rw-r--r-- | .config/luastatus/battery.lua | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/.config/luastatus/battery.lua b/.config/luastatus/battery.lua new file mode 100644 index 0000000..459599e --- /dev/null +++ b/.config/luastatus/battery.lua @@ -0,0 +1,57 @@ +local function read(path) + local f = io.open(path) + if not f then return nil end + local v = tonumber(f:read('*l')) + f:close() + return v +end + +widget = { + plugin = 'timer', + opts = { period = 2 }, + cb = function() + local base = '/sys/class/power_supply/macsmc-battery/' + + local energy_now = read(base .. 'energy_now') + local energy_full = read(base .. 'energy_full') + local status_f = io.open(base .. 'status') + + if not energy_now or not energy_full or not status_f then + return { { full_text = 'bat ?' } } + end + + local status = status_f:read('*l') + status_f:close() + + local capacity = math.floor(energy_now / energy_full * 100 + 0.5) + + local text_color = '#ffffff' + local battery_symbol = ' ' + + if capacity < 30 then + text_color = '#ed8796' + battery_symbol = '' + elseif capacity > 70 then + text_color = '#a6da95' + battery_symbol = '' + else + text_color = '#eed49f' + battery_symbol = '' + end + + local symbol = ({ + Charging = '', + Discharging = battery_symbol, + })[status] or ' ' + + return { + { full_text = string.format('%s %2d%%', symbol, capacity), color = text_color } + } + end, + event = [[ + local t = ... + if t.button == 1 then + os.execute('~/.local/bin/rofi-ppd &') + end + ]], +} |
