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

#2 2025-02-21 23:25:44

bth
Member
Registered: 2025-02-04
Posts: 2

Re: Updating status bar (i3blocks) with udev rules

Necroposting maybe, but I ended up here looking for something similar. Your approach is probably fine, but there's also just this simpler, direct option: bind a key in sway to send a generic refresh signal shared by any block you want.

bindsym $mod+i exec "pkill -SIGRTMIN+5 i3blocks"

and then in i3blocks/config something like:

[bluetooth]
command=./bluetooth.sh
interval=once
signal=5

[battery]
command=./battery.sh
interval=60
signal=5

Offline

Board footer

Powered by FluxBB