You are not logged in.

#1 2024-01-13 12:19:58

ragoo
Member
Registered: 2023-03-26
Posts: 1

Updating status bar (i3blocks) with udev rules

Hello,
I use the sway window manager, with sway-bar and i3blocks to display the status bar. For the battery block I've written an admittedly rudimental python script that reads the capacity and status files in /sys/class/power_supply/BAT1/ and formats the output. I set i3blocks to call it every 100 seconds.

This interval is good enough to show the capacity, but for the battery status it means that it takes up to 100 seconds to update when I hook or unhook the plug. This bugs me.

Obviously, I can set the interval to 1, but it seems unreasonable.

Now, an i3blocks' block can also be updated upon signal reception, for example:

pkill -SIGRTMIN+10 i3blocks

So I thought that maybe I can use udev rules to update the battery status indicator as soon as the laptop is hooked to the outlet. I've defined these rules in /etc/udev/rules.d/power_supply.rules:

SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/bin/pkill -SIGRTMIN+10 i3blocks"
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/bin/pkill -SIGRTMIN+10 i3blocks"

It works as expected, but I'm wondering if this is a good idea or not. If it isn't, is there a better way to achieve this result?

Last edited by ragoo (2024-01-13 12:28:13)

Offline

Board footer

Powered by FluxBB