Bug 472541

Summary: Powerdevil idle script does not respect idle inhibition of wljoywake or caffeine
Product: [Plasma] Powerdevil Reporter: Svyatoslav Timofeev <timofeevsv1989>
Component: generalAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED NOT A BUG    
Severity: normal CC: jpetso, me, natalie_clarius, nate, nicolas.fella, oded, tinozzo123
Priority: NOR    
Version: 5.27.6   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Svyatoslav Timofeev 2023-07-23 17:51:11 UTC
SUMMARY
***
Idle Script in settings of Power Management is separated from Idle Inhibit, which makes impossible wljoywake and caffeine to create screensaver inhibited by joystick
***


STEPS TO REPRODUCE
1. Setup wljoywake or caffeine to inhibit idle
2. Set Idle Script to Screensaver under Wine
3. Script Inhibit does not work!

OBSERVED RESULT
Screensaver on wine still running on Screen Inhibit, which is "undefined behavior"

EXPECTED RESULT
Idle Script should be inhibited by programs

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: CachyOS (Arch Linux)
(available in About System)
KDE Plasma Version: 5.27.6
KDE Frameworks Version: 5.108.0
Qt Version: 5.15.10
Comment 1 Nicolas Fella 2023-07-23 18:16:08 UTC
> 2. Set Idle Script to Screensaver under Wine

What you you mean with this?
Comment 2 Svyatoslav Timofeev 2023-07-23 19:40:46 UTC
(In reply to Nicolas Fella from comment #1)
> > 2. Set Idle Script to Screensaver under Wine
> 
> What you you mean with this?

Oh, sorry.
I'm using Windows Screensaver in Wine, such as fancy Dream Aquarium
Comment 3 Svyatoslav Timofeev 2023-07-23 20:01:55 UTC
(In reply to Nicolas Fella from comment #1)
> > 2. Set Idle Script to Screensaver under Wine
> 
> What you you mean with this?

I wrote simple script for launching Windows screensaver with Wine.
But, it triggers when screensaver of KDE (screen locker, screen sleep) inhibited by other programs, such as Caffeine or wljoywake

There is no way to prevent script from triggering, while screensaver inhibited by programs or D-Bus
Comment 4 Jakob Petsovits 2023-12-03 06:01:20 UTC
Not sure how wljoywake or caffeine inhibit idle, but Bug 457859 (systemd-inhibit is not respected) seems like a related issue.
Comment 5 Oded Arbel 2024-03-20 18:35:45 UTC

*** This bug has been marked as a duplicate of bug 457859 ***
Comment 6 Jakob Petsovits 2024-04-04 03:21:18 UTC
Reopening as "not a duplicate". I haven't gotten around to testing custom script idle behavior, but this is different to Bug 457859 which is not at all about custom scripts and just talks about preventing regular suspend actions.
Comment 7 Martino Fontana 2024-07-05 17:41:32 UTC
I found another app that has the same problem.
https://github.com/rafaelrc7/wayland-pipewire-idle-inhibit/issues/1
Comment 8 Martino Fontana 2024-07-20 14:50:28 UTC
Regarding `wljoywake` and `wayland-pipewire-idle-inhibit`, it seems that KDE is implementing the `zwp_idle_inhibit_manager_v1` protocol correctly.
It's other compositors that implement incorrectly, and these apps that rely on incorrect behavior.
See https://github.com/swaywm/sway/issues/8080, and https://codeberg.org/river/river/issues/1079#issuecomment-2013817.

(So, I guess that this issue report is a https://xkcd.com/1172/ situation.)

Caffeine (not -ng) is another situation, since it uses `xdg-screensaver`. https://bugs.kde.org/show_bug.cgi?id=383575#c4
Comment 9 Bug Janitor Service 2024-07-29 15:45:28 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/305
Comment 10 Jakob Petsovits 2024-07-30 12:34:31 UTC
So in Comment #8, we have an explanation for
* why wljoywake won't work: it uses zwp_idle_inhibit_manager_v1 but doesn't have a Wayland surface with focus to keep inhibiting, and
* why caffeine (not -ng) doesn't work: it uses xdg-screensaver, which can't work because it places incorrect assumptions on the old `org.freedesktop.ScreenSaver` interface.

That seems like a good reason to close this bug report.

For an inhibit method that works, consider `systemd-inhibit --what=idle`, or caffeine-ng, or anything that uses one of the inhibition D-Bus APIs correctly: `org.freedesktop.portal.Inhibit` (to be fixed by the MR above, hopefully in Plasma 6.1.4), `org.freedesktop.login1`, `org.freedesktop.PowerManagement.Inhibit`, `org.freedesktop.ScreenSaver`.
Comment 11 Jakob Petsovits 2024-07-31 10:36:50 UTC
Git commit 1549c49f41f544cb9dad54de509f318cc5b6dc38 by Jakob Petsovits.
Committed on 30/07/2024 at 11:20.
Pushed by jpetso into branch 'master'.

Inhibit: Forward the correct inhibition flags to PolicyAgent

The Inhibit method ignored the value of the "flags" argument and
always sent InterruptSession as inhibition policy. This prevents
sleep, but does not prevent idle actions such as screen locking
and dimming.

This commit changes the requested inhibition policies to match
the documented values for "flags":

* Portals "Suspend" remains PolicyAgent "InterruptSession".
* Portals "Idle" becomes PolicyAgent "ChangeScreenSettings".
* Portals "Logout" and "User Switch" are not supported at this time
  and are merely logged but otherwise ignored.

PowerDevil, which implements the PolicyAgent API, uses the same
policies also to represent the logind "sleep" and "idle" inhibitors,
so we can trust that they behave accordingly.
Related: bug 486506, bug 335729

M  +12   -2    src/inhibit.cpp

https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/1549c49f41f544cb9dad54de509f318cc5b6dc38
Comment 12 Bug Janitor Service 2024-07-31 10:39:13 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/306
Comment 13 Jakob Petsovits 2024-07-31 10:40:36 UTC
Git commit 8fd86c5b0e6d6797bff850947b07e086544cd617 by Jakob Petsovits.
Committed on 31/07/2024 at 10:37.
Pushed by jpetso into branch 'Plasma/6.1'.

Inhibit: Forward the correct inhibition flags to PolicyAgent

The Inhibit method ignored the value of the "flags" argument and
always sent InterruptSession as inhibition policy. This prevents
sleep, but does not prevent idle actions such as screen locking
and dimming.

This commit changes the requested inhibition policies to match
the documented values for "flags":

* Portals "Suspend" remains PolicyAgent "InterruptSession".
* Portals "Idle" becomes PolicyAgent "ChangeScreenSettings".
* Portals "Logout" and "User Switch" are not supported at this time
  and are merely logged but otherwise ignored.

PowerDevil, which implements the PolicyAgent API, uses the same
policies also to represent the logind "sleep" and "idle" inhibitors,
so we can trust that they behave accordingly.
Related: bug 486506, bug 335729


(cherry picked from commit 1549c49f41f544cb9dad54de509f318cc5b6dc38)

Co-authored-by: Jakob Petsovits <jpetso@petsovits.com>

M  +12   -2    src/inhibit.cpp

https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/8fd86c5b0e6d6797bff850947b07e086544cd617