The officially official Devuan Forum!

You are not logged in.

#1 2017-05-25 13:07:21

GNUser
Member
Registered: 2017-03-16
Posts: 561  

automatically disable screensaver during video (incl. web browser)

It is relatively easy to configure media player applications to automatically disable screensavers during video playback. Some of them (e.g., mpv) even do this automatically out of the box.

However, for several years I've had to use a keyboard shortcut to toggle my screensaver off when watching video in a web browser. It seems the difficulty with video in a web browser is that for some time now web browsers have been able to play video without using any external software. Therefore, from the system's perspective, it is difficult to tell whether the web browser is just sitting idly or actually playing a video.

Well, I figured out a workaround: Watch for any sound output!

#!/bin/bash

while true; do
	sleep 10
	cat /proc/asound/card*/pcm*/sub*/status | grep RUNNING && xscreensaver-command -deactivate
done

Just add the above script to your startup applications and voilà: As long as any application is outputting sound, every 10 seconds xscreensaver gets a little nudge. This works regardless of whether you have pulseaudio or just alsa.

Last edited by GNUser (2017-08-24 13:28:57)

Offline

#2 2017-05-25 13:59:05

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: automatically disable screensaver during video (incl. web browser)

If you are using a screensaver other than xscreensaver, here is a screensaver-agnostic alternative:

#!/bin/bash

while true; do
	sleep 10
	cat /proc/asound/card*/pcm*/sub*/status | grep RUNNING && xdotool key Pause
done

The Pause key does not seem to do anything at all on my system, and I can use my system normally even if the key is being pressed in the background.

Last edited by GNUser (2017-08-24 13:44:48)

Offline

#3 2017-05-25 14:13:06

golinux
Administrator
Registered: 2016-11-25
Posts: 3,137  

Re: automatically disable screensaver during video (incl. web browser)

Thanks.  Very useful. I wonder if this would also work for video chat when there is no mouse activity . . .

Offline

#4 2017-05-25 14:19:34

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: automatically disable screensaver during video (incl. web browser)

Yes, it should work just fine: It doesn't matter if what's generating sound is a video, a game, or a chat. If there is sound, the script keeps screensaver at bay.

Last edited by GNUser (2017-08-24 13:30:36)

Offline

#5 2017-05-28 18:05:25

malinas
Member
Registered: 2017-02-21
Posts: 12  

Re: automatically disable screensaver during video (incl. web browser)

What if I'm playing my favourite albums on audacious while not being in front of the computer? I certainly would like the screensaver to work in that case.

Offline

#6 2017-05-28 19:15:46

smoki
Member
Registered: 2017-05-15
Posts: 56  

Re: automatically disable screensaver during video (incl. web browser)

I stopped using screensavers since i stopped using CRTs something like 10+ years ago big_smile.  My scenario is that i completely have disabled that xserver feature and then i do manual dpms off with xset command if/when/where i need it and mostly i don't.

Just saying maybe someone found idea useful, since screensavers actually does not save anything just might look fine.

edit: to mention computer monitors have DPMS on in EDID by default, while TVs or TV/Monitor combinations have DPMS off usually since you don't want TV to auto go to sleep by default but on PC some users like that for some reason still... well even my PC monitors never sleeps too, only when i force dpms off, timings can be set there also for those who like, etc... Thing sometimes further requre manual configurations as some GPU drivers might like to command there also... i like to disable it everywhere and to have non-automatic/manual control. But that is just me smile

Last edited by smoki (2017-05-28 20:02:43)

Offline

#7 2017-05-29 00:05:06

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: automatically disable screensaver during video (incl. web browser)

@malinas: Yes, that is a limitation of the script as written. I don't listen to music at the computer, so that wasn't an issue for me. It would be trivial, however, to add some logic to *not* send the nudge if audacious (or any other application used specifically for listening to music) is running.

@smoki: Indeed, LCDs have no need of screensaver--I have xscreensaver on my daily driver laptop only for ornamental purposes. On the other hand, I have an old laptop that I converted into a media player (including IR receiver!) which lives permanently connected to a 60'' plasma TV. In this case, a reliable screensaver is an absolute must-have. Since I started using this script, I no longer have to depend on a manual process to turn screensaver off and on when watching videos in a web browser.

Last edited by GNUser (2017-08-24 13:31:37)

Offline

#8 2017-05-29 01:12:33

Somewhat Reticent
Member
Registered: 2017-04-06
Posts: 103  

Re: automatically disable screensaver during video (incl. web browser)

On one system, I have to use a screensaver to keep the LED+LCD display from shutting down due to boredom.
Otherwise it suspends while I'm watching a movie!
If a video is playing fullscreen, I'd think suppressing the screensaver makes sense - provided someone's watching.
Pausing the video as well might be a way to save electrical energy ... tradeoff for human energy, of course ... hey, wake up! Aw...

Last edited by Somewhat Reticent (2017-05-30 00:51:58)

Offline

#9 2017-05-29 09:00:23

smoki
Member
Registered: 2017-05-15
Posts: 56  

Re: automatically disable screensaver during video (incl. web browser)

Somewhat Reticent wrote:

On one system, I have to use a screensaver to keep the LED+LCD display from shutting down due to boredom.
If a video is playing fullscreen, I'd think suppressing the screensaver makes sense - provided someone's watching.

Pausing the video as well might be a way to save electrical energy ... tradeoff for human energy, of course ... hey, wake up! Aw...

Problem is that screensavers does not actually save neither energy, running these actually uses more energy. People usually use opengl ones and with that your screen is still active, your CPU is more used, your GPU is more used.

What saves energy is only monitors DPMS (marketing name Energy Star) states are useful to really send monitor to save energy and do nothing else. For that screensaver is not needed.

Basically:

xset dpms force off

Saves energy and it wakes up on any input, doing something else actually uses more energy.

I understand as GNUser mention he runs screensavers for ornamental purposes, that is fine - so for aesthetics. But does that really save a screen? No. Does that really saves energy? Again, no.

Last edited by smoki (2017-05-29 09:44:35)

Offline

#10 2017-05-30 00:54:08

Somewhat Reticent
Member
Registered: 2017-04-06
Posts: 103  

Re: automatically disable screensaver during video (incl. web browser)

Yes, screensaver made sense back when it saved a CRT from phosphor burnout.  Generally obsoleted by modern screen tech.
Now I only use one to keep a screen active.

Last edited by Somewhat Reticent (2017-05-30 00:54:35)

Offline

#11 2017-05-30 19:03:18

greenjeans
Member
Registered: 2017-04-07
Posts: 505  
Website

Re: automatically disable screensaver during video (incl. web browser)

Somewhat Reticent wrote:

Yes, screensaver made sense back when it saved a CRT from phosphor burnout.  Generally obsoleted by modern screen tech.
Now I only use one to keep a screen active.

Agree completely. No point these days really, I disable the service on startup in my Mate partitions. In openbox I just never install one.

If you just want a screenlocker, i3lock works great.


https://sourceforge.net/projects/vuu-do/
Vuu-do GNU/Linux, minimal Devuan-based openbox systems to build on, maximal versions if you prefer your linux fully-loaded.

Please donate to support Devuan and init freedom! https://devuan.org/os/donate

Offline

#12 2017-08-16 18:01:13

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: automatically disable screensaver during video (incl. web browser)

Here's version 2.0, with cleaner logic and a new feature: Cursor disappears during video/audio playback (requires that the "unclutter" package be installed).

#!/bin/bash

while true; do
    sleep 10
    if grep -q RUNNING /proc/asound/card*/pcm*/sub*/status; then # there is sound, so we want "movie mode"...
        # xscreensaver nudge:
        /usr/bin/xscreensaver-command -deactivate
        # screensaver-agnostic nudge:
        # xdotool key Pause
        pgrep unclutter || unclutter & # if unclutter isn't running, start it
    else # there is no sound, so no "movie mode"...
        pgrep unclutter && pkill unclutter # if unclutter is running, kill it
    fi
done

Offline

Board footer