Progress towards fixing #38. As concluded in #38 (comment 1065728), we'll start out with just an API for temporary dimming adjustments, leaving profile-dependent brightness changes and ambient light sensors to keep using standard setBrightness()
calls for the time being. Depends on !470 and !475 which were originally part of this MR, but split out into separate MRs for easier merging.
Draft status for several reasons:
An annoying timing issue means that BUG: 452492 is still not fixed. Before merging, we should figure out how to move forward on this. More details below.- Fixed by the new upload, see !466 (comment 1077001).
No KWin/Wayland protocol for dimming at this time. It doesn't have to be part of this MR, but some design work might also help guide this.- Sufficient prototyping has been done in !469, libraries/plasma-wayland-protocols!90, libkscreen!208 and kwin!6861 (thanks @zamundaaa!) to make this seem viable.
More testing needed.Seems to work well enough, although the last two required an unreleased ddcutil 2.2.0-dev version from git to work:Tested regular use case for dimming (wait, dim, move mouse, undim) with X11 and KWin/Wayland, both work. Tested for BUG: 496513, could not reproduce. Dimmed just fine without manually applying settings. Switched into a parallel user session (different account), changed brightness, switched back, dimming still works. Set dimming timeout to 30s waited for the laptop to dim, unplugged the monitor while dimmed, plugged it back in. (Tested on X11 and Wayland.) - Without the ddcutil update, powerdevil logged
org.kde.powerdevil: [DDCutilDetector]: Failed to initialize callback
for libddcutil's monitor connectivity event updates for whatever reason. I'm pretty sure this used to work here on the same ddcutil version, perhaps a kernel update broke it? Anyway, this MR isn't responsible for that.
- Without the ddcutil update, powerdevil logged
Set dimming timeout to 30s and sleep to 1m, waited for the laptop to dim and sleep, unplugged the monitor, woke it up, plugged it back in. (Tested on X11 and Wayland.) - Same deal as above for the ddcutil issue: without getting update events, no connection/disconnection stuff can feasibly work before or after this MR.
In a nutshell, this change will restore non-dimmed brightness after reconnecting if the hardware brightness value is equal to brightness * dimmingRatio
which we had set before the display was removed earlier. If hardware brightness was not dimmed, or is set to any other value, nothing needs to be restored and dimming ratio remains at 1.0.