maximbaz / wluma

Automatic brightness adjustment based on screen contents and ALS
ISC License
641 stars 28 forks source link

[Feature request]: Support monitor disconnect #88

Open riley-martin opened 1 year ago

riley-martin commented 1 year ago

Please describe your feature request

When my laptop screen times out and turns off, wluma crashes with this error:
thread 'predictor-eDP-1' panicked at 'Frame was cancelled due to a permanent error. If you just disconnected screen, this is not implemented yet.', src/frame/capturer/wlroots.rs:142:25. I understand that this is currently expected, however, it would be nice to not have to restart wluma each time the display is powered on again.

If this is not feasible, that's fine; but if it is, I would be willing to try to submit a PR. I have some experience with rust, but I have done almost no graphics work so I might need some pointers there.

BTW, thanks for this great tool!

maximbaz commented 1 year ago

I think it's very feasible, just not been prioritized because I'm using my laptop without any external screens :sweat_smile: PR would be most appreciated!

You are more than welcome to have a look at the code, and then if you want we can talk about the approach, hopefully that can help you get onboarded and save some time.

One important thing to consider (for me in particular :sweat_smile:), is this PR: https://github.com/maximbaz/wluma/pull/86

This harmless idea to upgrade deps blew out of proportion, as I've seen that wlroots library has changed a lot in the way you are supposed to use it. I'm done somewhat, but I think it would be most valuable to finish that PR, before building things on top, just because it might significantly impact the approach for detecting screen change.

riley-martin commented 1 year ago

just not been prioritized because I'm using my laptop without any external screens

I am as well, its just that wluma seems to think that the built-in screen is disconnected when it goes to sleep; or am I misunderstanding and this is a separate problem?

I'm done somewhat, but I think it would be most valuable to finish that PR, before building things on top, just because it might significantly impact the approach for detecting screen change.

Ok, makes sense.

maximbaz commented 1 year ago

I might be hiding the problem for myself by running wluma as a systemd service with Restart set to always, so even if it crashes on sleep, it just self restarts on resume and I never notice this 😄 How are you running it, manually starting the process?

riley-martin commented 1 year ago

running wluma as a systemd service with Restart set to always

I guess that would do it. I just exec wluma in my compositor's config file (I use Hyprland). I guess I'm just too lazy to write a systemd service 😄.

maximbaz commented 1 year ago

Not to worry, it's provided in this repo, and possibly in the wluma distro package as well 😄 https://github.com/maximbaz/wluma/blob/main/wluma.service

name-snrl commented 8 months ago

My swayidle config turned off all outputs after 6 min, and sends idlehint after 10 minutes, with IdleActionSec=10min in logind.conf this suspends my system after 20 minutes, which means only 6 minutes out of 20 my screen is on. This causes wluma to crash. So yeah, I think this is an important issue for anyone using swayidle with default settings or something like that.

Hopefully, work on #86 is nearing completion.

systemd service with Restart set to always

In my case it stops restarting after 6 attempts. There some logs - journalctl.log

The reason is the default values for the DefaultStartLimitIntervalSec and DefaultStartLimitBurst options:

https://www.freedesktop.org/software/systemd/man/latest/systemd-system.conf.html#DefaultStartLimitIntervalSec=

I think this can be solved with StartLimitIntervalSec and StartLimitBurst, but I don't see a single solution for all possible cases.

I solved my case with a small change in the swayidle configuration:

 # DPMS
-timeout 360 'swaymsg "output * power off"' resume 'swaymsg "output * power on"'
+timeout 360 'systemctl --user stop wluma.service; swaymsg "output * power off"' resume 'swaymsg "output * power on"; systemctl --user start wluma.service'
 # sleep
 before-sleep 'loginctl lock-session "$XDG_SESSION_ID"'
 idlehint 600 # +IdleActionSec in logind.conf
-after-resume 'swaymsg "output * power on"'
+after-resume 'swaymsg "output * power on"; systemctl --user start wluma.service'