Bug 378404

Summary: Turn off screen when PM-inhibiting app is not the active app
Product: [Plasma] Powerdevil Reporter: Martin Klapetek <mklapetek>
Component: generalAssignee: Plasma Development Mailing List <plasma-devel>
Status: CONFIRMED ---    
Severity: wishlist CC: bugseforuns, kde, voidpointertonull+bugskdeorg
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:

Description Martin Klapetek 2017-04-03 16:58:15 UTC
A scenario: I'm listening to music from YouTube
playing in Chromium while writing some code on
my battery-only laptop. I leave my laptop for a
little while and when I come back, the backlight
is still full on and the music is still playing.

It made me realize that while I was gone, the screen
could have turned itself off while the music could
keep playing like normal.

In other words, if an application is inhibiting
the power management and thus preventing the laptop
to go to sleep, it could at least let the screen
turn itself off when the inhibiting app isn't the
current active app. If I'm listening to music and
the app is not in the foreground (ie. I am not
watching it on the screen), then it should be ok
to turn the screen off in the predefined timeout
during inactivity but still prevent going to sleep.

This would allow for a nice battery-saving media
playback with Plasma.

TL;DR - if the PM-inhibiting app is not the current
active app on screen (ie. it's in the background
and/or minimized), let the screen be turned off like
normal during inactivity, but still prevent sleep.
Comment 1 Kai Uwe Broulik 2017-04-03 17:06:45 UTC
Interesting idea. Might be tricky, though, as the process that created the inhibition and/or the application name it tells me does not neccessarily correspond with a window on the system.

Also, depending on the type of inhibition I would want it to say on, e.g. a copy process should keep the device on even if I'm doing something else or am idle.
Comment 2 Kai Uwe Broulik 2017-04-03 17:09:23 UTC
Fun fact: KDE's proprietary power management system allows a distinction between "keep screen on" (video playback) and "just keep the machine on" (audio playback). Chrome does that on Gnome, even, but on Plasma it just uses the FDO interface which only knows all or nothing. I did file a wishlist entry about that against Chrome but it has not yet been resolved.
Comment 3 Martin Flöser 2017-04-03 19:13:52 UTC
As a note: if the audio goes through HDMI turning off the screen is a bad idea if music is inhibiting. So it might need coupling with pulseaudio to check the output channel.
Comment 4 Pedro V 2023-11-18 12:15:15 UTC
Currently with Firefox playing a video in a non-active tab, there's no power management inhibition, so the described way of playing music from YouTube and still having automatic session locking already works with Firefox.
Not sure about Chromium though specifically. Gave Google Chrome a try some time ago, and it could neither work in a Wayland-only environment, nor it could use the GPU for video decoding, so I wouldn't expect that to be a good showcase of otherwise decently working Linux/KDE features.

The minimization desire also works with for example mpv which seems to release its power management inhibition when minimized, so it's possible to keep on listening to the video while automatic session locking and screen timeout is working.

What's a bit tricky though is ignoring the inhibitions of programs not "active":
- A window not in focus can be still watched by the user, even if it's partially occluded. The window manager would need to keep track of whether there's anything visible from the window and toggle the activity of the inhibition based on that
- The source of the inhibition could be a program with no windows, or possibly a program which has a window, but it has a reason to have the inhibition around without desiring to have anything visible tied to that

(In reply to Kai Uwe Broulik from comment #2)
> Fun fact: KDE's proprietary power management system allows a distinction
> between "keep screen on" (video playback) and "just keep the machine on"
> (audio playback). Chrome does that on Gnome, even, but on Plasma it just
> uses the FDO interface which only knows all or nothing. I did file a
> wishlist entry about that against Chrome but it has not yet been resolved.

That sounds interesting. Does anything use it, or does it still exist to begin with?
Firefox and mpv apparently doesn't, and I just recently ran into a bug report of Elisa even inhibiting screen locking, so I have doubts of it having support worth noting.