How do I stop screen dim/screen energy/sleep mode while watching youtube?

Hi!

Is there any script or community guide or something else I can use to disable temporarily screenlock/sleep/etc when watching videos/youtube please?

I use KDE, but it’s probably doesn’t matter much.

Hi,

If it’s a computer with a battery, click on the battery icon in the systray bar and enable the presentation mode, I think this is exactly the purpose of this.

1 Like

Yes I use laptop, but I don’t have that option I think… there’s no presentation mode.

Oh, did you meant the toggle for manual sleep block? Then I have this, but this is not what I want…

I want to have an option to watch a youtube video and when it ends and stop the sleep/screenlock will start working again. Like normally it should do, you know…

This can’t work. It’s handled by dbus that tells the screensaver / system that it shouldn’t dim / suspend / screensaver because something is being displayed on screen.

However, on qubes os, it’s dom0 dbus daemon that manages it, but it’s your qube dbus that will send a signal to the qube display server, it will never reach dom0.

2 Likes

But isn’t there some kind of sys-whatever to make that dbus signal go through it or something like that? After all it’s the VM that keep the signal alive and all is needed is to intercept that signal and I don’t know, transfer/inform dom0 about it somehow?
Or am I not getting it?

for security reasons you don’t want to connect dom0 dbus with another dbus :frowning:

Yes, you can. If you do not have sys-audio qube (99% you do not, it still not fully supported), you can run in dom0 a simple script, that will prevent xscreensaver and other power management from activating when you have sound in pulseaudio.
This way when you watch video, it will never lock nor sleep. But when you stop or pause, it will, in the usual time you set in the screensaver settings (e.g. in 15 minutes).

2 Likes

do you have such script at hand?

1 Like

Yeah, I don’t have sys-audio(yet?), is there a guide/script/or maybe someone can come up with this please?

This script will scan the window title for YouTube and turn on/off presentation mode, you can cron run it every 5 min in dom0.

#!/bin/bash

if xdotool search --name YouTube; then
	xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s false
else
	xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s true
fi
2 Likes

Yeah, thanks for that link, I’m gonna setup it in upcoming days, but I meant guide/script for what balko said

@renehoj Thanks! But this approach isn’t going to do much as it will not toggle the presentation mode when that window is present, but say a video finished, you know? balko’s way is more like a traditional approach… this way when the video is going it will keep the screen on and if the video stopped it will kick the suspend/sleep/whatever… but I have no idea how to do it, google doesn’t help much either

I used something like that. The script was made a long time ago, so its style looks as a mix of bash and sh, but the point should be clear.

This script being added to autostart (not cron, just run once) should prevent screen blank and screensaver activation when any media is played, does not matter youtube, smplayer, mpv or some web page in browser.

#!/bin/bash

shopt -s dotglob
export LC_ALL=en_US.utf8

sleep 30

while true; do

    active_sink_inputs=`pacmd list-sink-inputs | grep -c "state: RUNNING"`
    screensaved_active=`xscreensaver-command --time | grep -c -E ' (locked|blanked)'`
    
    date_prefix=`date '+%Y-%m-%d_%H-%M-%S'`
    
    dpms_status=`xset -q | grep -c 'DPMS is Enabled'`

    if [ X"$screensaved_active" != X"0" ]; then
        echo "$date_prefix: Screensaver is active (locked or blanked). Doing nothing"
        #xset +dpms        
    elif [ X"$active_sink_inputs" != X"0" ]; then    
        echo "$date_prefix: Running sink-input found. Blocking screensaver timer dpms"
        if [ X"$dpms_status" = X"1" ]; then
            # deactivate and reactive again
            xset -dpms && xset dpms
        fi
        xscreensaver-command -deactivate > /dev/null
    else
        echo "$date_prefix: No running sink-inputs found. Doing nothing"        
        #xset +dpms
    fi

    sleep 50
    
done

P.S. I hope something like that will be available out of box in Qubes OS someday, as it is so small and easy.

3 Likes

Thank you so much! I actually went hardcore with what Tezeria said and installed that audio-qube… it kinda works… I don’t know if there will be issues with this as you said it’s not fully supported? But the more important question is what should I tweak in that script so it will work with my sys-audio? or is it completely different now?

Why? That was not a great idea if you do not need bluetooth audio output.
I said about not having sys-audio just because my solution will not work if you have one. Not like it is good to have it if you do not need it.

You should either revert the sys-audio qube actions (possible, nothing drastic happened) to make my solution work, because it runs in dom0, check pulseaudio in dom0 and prevents xscreensaver from running in dom0.
Or you have to complicate things further and run like 2 scripts, one in sys-audio with pulseaudio checks and another in dom0 that would ask the first script (check e.g. some lock file in sys-audio) and prevent xscreensaver or something from starting.

1 Like

Nah, I’ll go back to what it was :smiley:
I shouldn’t do anything to make it work with KDE, right? you also use KDE?

What do you mean exactly?
I use KDE apps in qubes (because they are by far superior to Gnome/GTK), but not in dom0 (the official support of KDE in dom0 unfotunately was dropped).

Anyway, the solution does not depend on XFCE/KDE in dom0 anyway.
But note that I made and used this script on Qubes OS ~4.0 and not sure if it still works as is.

Em… I followed the docs in KDE (desktop environment) | Qubes OS and just installed it as it says in dom0…

At some point there was a choice during installation - KDE or XFCE. But nowadays, it’s only XFCE.