Bug 497362 - Power & brightness settings are not applied on startup if state change happened while system was powered off
Summary: Power & brightness settings are not applied on startup if state change happen...
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Power management & brightness (show other bugs)
Version: 6.2.4
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: 1.0
Assignee: Jakob Petsovits
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2024-12-12 12:18 UTC by Coacher
Modified: 2025-01-16 22:44 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.3.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Coacher 2024-12-12 12:18:17 UTC
SUMMARY

Brightness and possibly other power profiles settings are not applied if AC<->battery switch happens while the laptop is powered off.

STEPS TO REPRODUCE
1. Configure power profiles to have 100% on AC and 85% brightness on battery.
2. Plug AC power and power off the laptop.
3. Unplug AC power while the laptop is off.
4. Power on the laptop and login into Plasma

OBSERVED RESULT
Brightness is at 100%

EXPECTED RESULT
Brightness is at 85%

SOFTWARE/OS VERSIONS
Operating System: Fedora Linux 41
KDE Plasma Version: 6.2.4
KDE Frameworks Version: 6.8.0
Qt Version: 6.8.0
Kernel Version: 6.11.11-300.fc41.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 8 × 11th Gen Intel® Core™ i7-1165G7 @ 2.80GHz
Memory: 15.3 GiB of RAM
Graphics Processor: Mesa Intel® Xe Graphics

ADDITIONAL INFORMATION

I have configured power profiles via systemsettings to have 100% brightness on AC and 85% brightness on battery. If I power off my laptop while it is on battery power with brightness set to 85%, then plug AC while the laptop is off, then power on the laptop, the brightness is at 85% instead of 100% after log in to Plasma.

The opposite is also true as described in the steps above.

Maybe relevant: power-profiles-daemon or tuned are not installed, power is managed via tlp.
Comment 1 Jakob Petsovits 2024-12-17 22:59:09 UTC
Can reproduce on Plasma 6.2.4, Qt 6.8.1, on Arch Linux. Using power-profiles-daemon, so TLP is not a factor.

Extra observation: When my display has incorrect brightness on battery (from before when it was plugged in) and I change *AC power* settings in System Settings, the brightness does come down then. So this looks like a case of some kind of change notification getting lost. We'll have to figure out where exactly.
Comment 2 Jakob Petsovits 2024-12-17 23:33:41 UTC
Okay, so I believe I misread your "powered off" for "sleeping (suspended to RAM)". It's funny that I reproduced with mere lid closure to put the laptop to sleep and wake up by propping the lid back open.

Coincidentally though, I think the underlying issue is the same. Judging by my logs, this is what I believe is happening:

1. The KWin/Wayland output for the laptop screen doesn't yet exist (on startup), or has disappeared prior to suspending upon closing the lid (when sleeping).
2. PowerDevil (re)loads the current profile with custom brightness level, tries to set the brightness, but there is no display to assign it to.
3. The laptop display appears, but the profile change has already passed, so nothing gets set.
4. Whenever the next profile change happens, then all the displays are present and brightness gets set correctly.

It would seem like the right fix would involve the `ScreenBrightnessControl` action listening for `ScreenBrightnessController::displayAdded()` signals and re-running the logic that's currently sitting inside `ScreenBrightnessControl::onProfileLoad()`. I'm not 100% sure if doing this might cause any unexpected behavior for users whose first advertised display is their external monitor before the internal display appears.

This likely won't affect X11 because the initial display detection will recognize the laptop display before any profiles get loaded, and then will keep its display object around even if the screen gets disabled.
Comment 3 agry 2025-01-11 05:46:15 UTC
Hi, I have similar problem and the way to reproduce the problem is almost the same. And I've been testing this on few version of powerdevil.

STEPS TO REPRODUCE
1. Configure power profiles (for me 50% on AC and 10% brightness on battery).
2. Unplug AC power (the brightness will set to 10%) and shutdown the laptop.
3. Plug the AC power while the laptop is off.
4. Power on the laptop and login into Plasma

SOFTWARE/OS VERSIONS
Operating System: EndeavourOS 
KDE Plasma Version: 6.2.5
KDE Frameworks Version: 6.9.0
Qt Version: 6.8.1
Kernel Version: 6.12.8-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 12 × 11th Gen Intel® Core™ i5-11400H @ 2.70GHz
Memory: 15.3 GiB of RAM
Graphics Processor: Mesa Intel® UHD Graphics

powerdevil 6.2.5-1 (plasma)
kwin 6.2.5-1 (plasma)

TEMPORARY FIX
I've been testing this with few version of powerdevil (6.2.5-1, 6.2.4-1, 6.2.0-1, 6.1.5-1, and 6.1.4-1) and what I get is this problem is not happening on version 6.1.5-1 and 6.1.4-1. So I guess this problem starting happening on version after 6.1.5-1.

powerdevil version
6.2.5-1 = have this problem
6.2.4-1 = have this problem
6.2.0-1 = have this problem
6.1.5-1 = don't have this problem
6.1.4-1 = don't have this problem

ADDITIONAL INFORMATION
From my testing, you can downgrade powerdevil to 6.1.5-1 but from my testing it cause another problem which the brightness and battery indicator are missing and the way to bring that back is to reinstall the newer version like 6.2.4-1 or 6.2.5-1.

This is the video I took about this problem
https://www.youtube.com/watch?v=vyDZdNXBYTo

Hope this can help and sorry if I can’t explain well enough. Thank you.
Comment 4 Jakob Petsovits 2025-01-15 03:19:29 UTC
I looked into this more and came up with a set of changes to handle the displayAdded() signal in PowerDevil's ScreenBrightnessControl action. This will come in handy either way, but it turns out it wasn't the root of the problem and the theory from Comment #2 is ever so slightly off.

Here's what's actually happening:

1. The KWin/Wayland output for the laptop screen doesn't yet exist on startup. Therefore, PowerDevil::Core does not load the ScreenBrightnessControl action initially.
2. PowerDevil loads the current profile, still without the action being active. Other actions have their loadAction() and onProfileLoad() method called via PowerDevil::Core::loadProfile().
3. The laptop display appears, and the action now gets loaded in PowerDevil::Core::refreshActions().
4. However, refreshActions() does not call loadAction() and onProfileLoad() for newly supported (i.e. added) actions, neither directly nor by invoking Core::loadProfile(). Therefore, the brightness setting logic doesn't get executed until the power state actually changes.

So refreshActions() by itself is insufficient to handle the displayAdded/displayRemoved signals, it also needs to load any newly supported actions. Let me figure out how best to make that happen.
Comment 5 Bug Janitor Service 2025-01-15 17:31:18 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/494
Comment 6 Jakob Petsovits 2025-01-16 16:01:09 UTC
Git commit db79307fdc4fd3ba6ce9e05cf3a0114f2940e620 by Jakob Petsovits.
Committed on 16/01/2025 at 15:56.
Pushed by jpetso into branch 'master'.

daemon: Make sure to load newly supported actions after a refresh

This fixes applying display brightness from the current profile
configuration at startup. This had failed on Wayland since 6.2
when KWin brightness integration was added. Here's why.

In a Wayland session, the `ScreenBrightnessControl` action will not
initially announce itself as supported because KWin outputs are only
known after a brief asynchronous delay. Instead, it gets enabled
as a reaction to the first `displayAdded`/`displayIdsChanged` signal.

The `refreshActions()` slot that handles this would create and
register the action object, but the action's `loadAction()` and
`onProfileLoaded()` methods were not called. Because the profile
was already loaded earlier, these methods would not get called
until the next profile change (or wake-up from sleep).

We now take care to call these action methods, but only when the
profile is active. They won't be called during Core initialization,
and if the login session is currently inactive.

M  +30   -18   daemon/powerdevilcore.cpp
M  +3    -1    daemon/powerdevilcore.h

https://invent.kde.org/plasma/powerdevil/-/commit/db79307fdc4fd3ba6ce9e05cf3a0114f2940e620
Comment 7 Jakob Petsovits 2025-01-16 16:14:47 UTC
Git commit fbcbe0ccebea85a25a3a77dbb29a185a53d8c255 by Jakob Petsovits.
Committed on 16/01/2025 at 16:07.
Pushed by jpetso into branch 'Plasma/6.3'.

daemon: Make sure to load newly supported actions after a refresh

This fixes applying display brightness from the current profile
configuration at startup. This had failed on Wayland since 6.2
when KWin brightness integration was added. Here's why.

In a Wayland session, the `ScreenBrightnessControl` action will not
initially announce itself as supported because KWin outputs are only
known after a brief asynchronous delay. Instead, it gets enabled
as a reaction to the first `displayAdded`/`displayIdsChanged` signal.

The `refreshActions()` slot that handles this would create and
register the action object, but the action's `loadAction()` and
`onProfileLoaded()` methods were not called. Because the profile
was already loaded earlier, these methods would not get called
until the next profile change (or wake-up from sleep).

We now take care to call these action methods, but only when the
profile is active. They won't be called during Core initialization,
and if the login session is currently inactive.

M  +30   -18   daemon/powerdevilcore.cpp
M  +3    -1    daemon/powerdevilcore.h

https://invent.kde.org/plasma/powerdevil/-/commit/fbcbe0ccebea85a25a3a77dbb29a185a53d8c255