Skip to content

daemon: Reduce unwanted brightness change signals that we originated

Extracted from MR !466 (merged) with minor tweaks in logic and commit message. Makes it possible for us to apply a dimming animation without getting the laptop screen's baseline brightness reset through ScreenBrightnessController::onExternalBrightnessChangeObserved(). CC @zamundaaa, @nclarius (thanks in advance for any reviews)

Commit message

In BacklightBrightness::onDeviceChanged(), the externalBrightnessChangeObserved signal is emitted after filtering out udev events while the brightness animation is running. Unfortunately, these signals are received with a short delay compared to when the timer was started, possibly because the KAuth helper runs on a different timeline and definitely because udev device change notifications are not synchronous calls.

This commit introduces a more robust way of filtering out change events that BacklightBrightness itself was asking for.

In essence, we will now filter out events where the brightness moves toward the current animation target brightness (dubbed "executed brightness" as it's not always animated).

There is a rub, in that the brightness helper can still continue its animation e.g. toward higher values until it receives the message to turn around toward the lower value that the user has suddenly decided to request instead. In order to ignore these overshooting outliers, we also introduce an "expected min/max" pair of brightness values that gets initialized with the previous brightness target.

This isn't perfect, as change events from further back than the previous KAuth invocation could still emit an unexpected externalBrightnessChangeObserved signal. This only happens when you slide back and forth on the brightness slider really fast, though, and is unlikely to be encountered in normal use.

In addition to reducing unwanted change signals, this new method also allows BacklightBrightness to exactly track udev brightness values and will correctly detect external changes even during a brightness animation.

Testing

Restart powerdevil service with the patch applied, ideally under X11 where PowerDevil uses KAuth helper animations rather than getting each individual value from KWin. Enable verbose logging, then monitor powerdevil logs with:

journalctl --user-unit plasma-powerdevil.service -f

Then drag the brightness applet slider for "Built-in screen" and make sure you don't see this message:

[BacklightBrightness]: External brightness change observed: <current> / <max>

If you go back and forth like a zig-zagging hyperspeed maniac, you may still see a handful of these. For more in-depth debugging, I've uploaded my extra debug logging commit from a separately uploaded branch, for anyone to inspect the deeper workings in case it's necessary - mostly for personal reference, though.

Edited by Jakob Petsovits

Merge request reports

Loading