Bug 476962 - Screen does not respect "when locked, turn off after X seconds" setting
Summary: Screen does not respect "when locked, turn off after X seconds" setting
Status: RESOLVED FIXED
Alias: None
Product: Powerdevil
Classification: Plasma
Component: general (show other bugs)
Version: master
Platform: Neon Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords: qt6
Depends on:
Blocks:
 
Reported: 2023-11-13 21:39 UTC by Patrick Silva
Modified: 2024-01-13 01:01 UTC (History)
7 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Silva 2023-11-13 21:39:48 UTC
SUMMARY
Can reproduce on both Arch Linux running Plasma 6 alpha and neon unstable.

STEPS TO REPRODUCE
1. open "Energy Saving" KCM
2. set "When locked, turn off the screen" to "after 0 sec"
3. apply the change
4, lock the screen

OBSERVED RESULT
the screen is locked but it does not turn off

EXPECTED RESULT
the screen is locked and then immediately turned off

SOFTWARE/OS VERSIONS
Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.81.0
KDE Frameworks Version: 5.245.0
Qt Version: 6.6.0
Graphics Platform: Wayland
Comment 1 Nate Graham 2023-11-15 21:53:44 UTC
Can reproduce.
Comment 2 Jakob Petsovits 2023-12-02 01:43:59 UTC
Can reproduce as well.

If I set the value to 10 seconds however, or even just 1 second, the feature works and the reproduction steps result in a turned-off screen. There must be some kind of race condition where locking the screen triggers a user activity signal and the turn-off timer doesn't get reset, or something of that sort.
Comment 3 Jakob Petsovits 2023-12-02 02:02:46 UTC
The fix was simple, removing the check for > 0s in the code (https://invent.kde.org/plasma/powerdevil/-/blob/3de931d603796c8d245f775a50f5e178e0564d93/daemon/actions/bundled/dpms.cpp#L191) will do the trick. This made the screen turn off immediately after locking.

Plot twist: When I wanted to unlock the screen, I wasn't able to anymore because PowerDevil would immediately activate the dim-and-turn-off effect, which apparently also prevents input and caused lots of flickering when I just wanted to enter my password. Maybe it's not such a great idea to let people configure immediate turn-off? Should we assign a non-zero lower bound?
Comment 4 Natalie Clarius 2023-12-04 23:42:15 UTC
Imo ideally it should be possible to configure immediate turn off when the screen goes from unlocked to locked, but not have the turning off fire when the screen already is locked and now receiving input.
Comment 5 Jakob Petsovits 2023-12-04 23:53:59 UTC
So... two different settings? Or keep one setting, but we apply a hardcoded lower bound (say, 10s) for the "already locked, woken up on user input" case? I guess we probably only want to expose one timeout value, to avoid bombarding the user with mostly unnecessary information. (Exposing both regular and "when locked" timeouts is arguably on the more overkill side of things already.)
Comment 6 Natalie Clarius 2023-12-05 00:00:30 UTC
Why do you think we need two different settings? Imo setting it to 0s should turn it off immediately when going unlocked -> locked but also turn on again immediately once there is input in already locked state.
Comment 7 Jakob Petsovits 2023-12-05 02:39:16 UTC
(In reply to Natalie Clarius from comment #6)
> Why do you think we need two different settings? Imo setting it to 0s should
> turn it off immediately when going unlocked -> locked but also turn on again
> immediately once there is input in already locked state.

Let's say that 0s is the configured timeout for sleeping when the system transitions from unlocked to locked. So it goes to sleep immediately after locking. We have also established that we can't (shouldn't) use 0s as a timeout after user input when already locked. I think it's also clear that if the user stops typing / doesn't manage to log in, there should still be a timeout (>0s) for putting the system back to sleep. We can call this a "setting" or anything else, and it doesn't have to be user-configurable, but it seems clear that another timeout value is needed apart from the original (0s) configured one.
Comment 8 Jakob Petsovits 2023-12-05 02:41:31 UTC
And sorry for conflating "sleeping" with "turning off screen" in the comment above. I meant the latter. Same idea though.
Comment 9 Natalie Clarius 2023-12-05 03:08:06 UTC
Ah, I see the problem. Yeah, it probably makes sense to go back to screen off after some idle time after input in locked state, though I don't think we'd need to make this timeout configurable. I think just setting it to 1 minute in that case would capture the users's intentions well enough.
Comment 10 fanzhuyifan 2023-12-05 06:47:56 UTC
Alternately, how about having a separate checkbox saying immediately turn screen off after lock?
Comment 11 Bug Janitor Service 2023-12-26 20:13:57 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/301
Comment 12 Jakob Petsovits 2024-01-05 02:03:13 UTC
Git commit c58085b4ca3cf5456dd7cdfa4189d06b38a3e488 by Jakob Petsovits.
Committed on 05/01/2024 at 02:39.
Pushed by jpetso into branch 'master'.

actions/bundled/dpms: Handle very short timeout-when-locked better

For automatic display turn-off, we now allow setting an idle timeout
when the screen is locked, down to 0 seconds. This makes sense when
the session transitions from unlocked to locked, allowing the user to
turn off the display at the same time as the lockscreen would appear.

Unfortunately, it doesn't work for a 0 second timeout. The issue is
that low timeout values also affect user interaction on wakeup,
i.e. when trying to enter the password the user now has 0 seconds
available to type their password. This prevents us from simply
removing the check for >0 seconds when registering DPMS timeouts.

Instead, this commit splits the timeout when locked into two internal
member variables.

For the traditional "timeout when locked" value, we now apply a
(hardcoded) minimum duration to allow uninterrupted authentication
when the lock screen is already active.

In addition, we introduce a new "timeout when activating lock" value
that uses the configured value as is (more or less - applying an
extremely short minimum may help prevent unintended behavior).
This new timeout only gets used when switching from unlocked
to locked, and is replaced by the regular "timeout when locked"
thereafter until the session gets unlocked again.

Suspend/resume handling receives some extra care to behave well.
Unlocked timeouts also apply a minimum duration for extra safety.

M  +52   -16   daemon/actions/bundled/dpms.cpp
M  +8    -3    daemon/actions/bundled/dpms.h
M  +6    -1    daemon/powerdevilaction.cpp
M  +6    -0    daemon/powerdevilaction.h

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