ice-wm / icewm

IceWM releases only, see Wiki
https://github.com/ice-wm/icewm/releases
Other
289 stars 16 forks source link

"Dynamic" battery status monitor on task bar when removing/reinserting battery #117

Closed T-3B closed 1 year ago

T-3B commented 1 year ago

With my laptop, I'm used to remove the battery when I'm working home.

But if I reinsert it, the taskbar won't show the battery monitor on the taskbar.

I tried icesh -T restore, which obviously did not change anything.

So now I set TaskBarShowAPMStatus=1, which will force the battery monitor to be displayed even if there is no battery.

From what I saw:

Since the expected behaviour happens when starting icewm with a battery, I suppose (and hope) the fix is not that difficult.

Code7R commented 1 year ago

And you are running which OS? Linux? Which kernel?

If Linux: please run "find /sys/class/power_supply/*" with and without battery and compare the results.

T-3B commented 1 year ago

ArchLinux, latest stable kernel (6.1.6-arch1-1).

There is no problem with /sys/class/power_supply/BAT0, it shows when the battery is (re)inserted. The iceWM monitor battery does not follow that sys file existance when it was started without a battery (thus only /sys/class/power_supply/AC).

gijsbers commented 1 year ago

Contrary to your supposition, it is difficult and a lot of work. Consider this article. An event needs to be listened for. These techniques and library calls need to be shoehorned into the existing infrastructure. Ports to OpenBSD and FreeBSD need to be made. Maybe it needs to be documented and explained to users. People may discover bugs, which need to be investigated, solved and released. Why don't you just icewm -r?

Code7R commented 1 year ago

I was about to write the same. Could not figure out any sensible way without using lots of sysctls and without being root. Maybe apply a very dumb scheme and run a glob() on that folder every 30 seconds?

EDIT:

Possible workarounds: write own udevadm-like client functionality which observes all events (pro: most native Linux solution, contra: Linux-specific, porting to BSD et al. hard, receives lots of events, needs to be polled in additional to main X loop); OR use a helper: add udev rules config which executes some action, like creating a file which icewm observes, or sending some event using icesh (pro: probably easiest to implement, maybe easier to port to BSD; contra: requires additional integration efforts on the system, requires some reliable permission/session traversal scheme). Still nothing trivial, just different levels of suckinness.

Probably the easiest solution would be to have a guessing check, i.e. it would always stat on /sys/class/power_supply/BAT0 permanently, and if this already exists then also on /sys/class/power_supply/BAT1, etc.

T-3B commented 1 year ago

Did not that icewm -r don't kill any app running, and for my use I think it is sufficient.

Thank you for your fast answers!