in some sites when I watch a movie in a browser and I don't touch the computer the screen turns off. In other sites like Youtube I don't have that problem. I tried using caffeine but I don't like the idea of having to manually enable and disable it every time I watch a video. I also tried other methods that I found on the internet but nothing worked. any suggestions? I'm using chrome and running ubuntu 16.04.
-
1Could you give an example of a video that makes you(r screen) fall asleep? need to look into the processes. See if we can get anything usefull out of it.– Jacob VlijmMay 28, 2016 at 20:55
-
More specifically can you provide a link to one or more videos that will not inhibit the screensaver (that's the proper lingo for "preventing the screen from falling asleep)? I suspect they're Flash videos. Can you confirm or deny that?– David FoersterMay 28, 2016 at 22:35
-
FWIW, I find it happens in Totem as well as with Flash videos. askubuntu.com/questions/778882/…– AmandaMay 29, 2016 at 4:58
-
I would suggest "caffeine". It keeps your computer awake ubuntuhandbook.org/index.php/2015/01/…– nicandrisMay 29, 2016 at 8:57
2 Answers
UPDATE 2017/08/23: Changed script to one that doesn't send keystrokes but disables dpms
and the screensaver temporarily while a video is playing full screen.
This only works with applications running full screen, not maximized.
First install xdotool
:
sudo apt install xdotool
then I created a scripts
folder in my home folder that I could drop any scripts into that I wanted to keep:
mkdir -p ~/scripts
then I created a file called check_full.bsh
in my ~/scripts
folder and added the following content to it:
Since my screensaver is set for 20 minutes, I set the sleep timer in the script to 10 minutes (600 seconds). You can change this based on your screensaver settings.
#!/bin/bash
#Get DPMS settings
dpms_set=$(xset -q | awk '/DPMS is/ {print $NF}')
#Get screensaver type and command
scrnsvr=$(ps -ef | awk '/screensav/ {print $8}' | grep -v awk)
scrnsvrcmd=$(ps -ef | awk '/screensav/ {print substr($0,index($0,$8))}' | grep -v awk)
#Sleep Timer in seconds.
SL=600
while true;
do
result=()
#Get all window geometries
all=($(xdotool search --name - | while read win; do xdotool getwindowgeometry $win | awk '/Geometry/ {print $2}'; done))
#Get all screen resolutions detected and build array.
SCREENS=($(xrandr | awk '/\*/ {print $1}'))
SCRN=" ${SCREENS[*]} "
#Get result of all windows and match
for item in ${all[@]}; do if [[ $SCRN =~ " $item " ]] ; then result+=($item); fi; done
#If a result exists disable power management and screensaver
if [[ ${result[@]} ]]; then
ps -ef | grep $scrnsvr | grep -v grep >/dev/null
if [[ $? == 0 ]]; then
kill $(ps -ef | grep $scrnsvr | grep -v grep | awk '{print $2}')
fi
if [[ $dpms_set == "Enabled" ]];then
xset -dpms
fi
else
ps -ef | grep $scrnsvr | grep -v grep >/dev/null
if [[ $? == 1 ]]; then
${scrnsvrcmd} &
fi
if [[ $dpms_set != "Disabled" ]];then
xset dpms
fi
fi
result=()
sleep $SL
done
make the script executable:
chmod +x ~/scripts/check_full.bsh
For some reason, a cron job would not run this correctly. So I added an entry to my startup to call this script. In the ~/.config/autostart/
folder, I created a file called Check_full.desktop
with the following content:
I like to have delays added to startup as they usually load better.
[Desktop Entry]
Type=Application
Name=Check_Full
Comment=Prevent screensaver from activating when full screen video is playing
Exec=bash -c 'sleep 5 && /home/<username>/scripts/check_full.bsh'
change above Exec line to match your home folder.
Set proper permissions to the file:
chmod 664 ~/.config/autostart/Check_full.desktop
After logging out and back in, check_full.bsh
is now running and checking every 10 minutes if active application is full screen. If not, screensaver / lock screen launch at normal times.
Hope this helps!
-
-
2@p3pc1styl3 You're very welcome! Please check the check mark next to my answer showing that it helped you and it can help others looking for the same thing. I came up with this because although there are good solutions out there, none of them allowed me to run whatever player I wanted to to watch videos, so I came up with this script to detect anything in full screen mode. Figured that just made it easier. Glad it is helping you! =)– TerranceMay 30, 2016 at 16:05
-
Please don't make a ton of edits to your answer over time, Terrance. Only make updates when there's something major to change, a ton of minor edits usually is not a good thing.– Thomas Ward ♦Aug 23, 2017 at 18:13
-
@ThomasWard I understand. I didn't like the old answer I had and I dumped that one. I didn't think there were a ton of minor edits anyway.– TerranceAug 23, 2017 at 18:14
-
@Terrance Might want to look at the revision history of your answer here then and see how many small revisions you've made over time.– Thomas Ward ♦Aug 23, 2017 at 18:15
Youtube doesn't have that problem because it uses HTML5 player. The sites you're having the problem with are using Flash Player instead. It is a bug in Adobe Flashplayer, which, in short, is that it never notifies WM that it ran into fullscreen. You may have heard though that Adobe Flash is a buggy app in general, so one workaround is to disable it, and use only sites with HTML5 video.
As you mentioned caffeine, you probably have searched for a solution already. Another thing you could do is to disable «power saving» completely, i.e. to force the screen to never turn off.