5

I'm running Ubuntu 12.04. I installed xscreensaver in place of gnome.screensaver.

My problem is that I cannot get the screensaver to stop popping up when I'm watching a movie on Movie Player. I have Movie Player set to disable screensavers but it's not working on xscreensaver.

How do I change the program files to disable xscreensaver while Movie Player is running?

user.dz
  • 48,105
Chris26284
  • 73
  • 2
  • 9

6 Answers6

7

You may try similar script to this one. Watch for player state through DBUS.

I lower delay to 55 sec, work better with 1min screen saver idle time.

  • Example VLC:

    BTW, VLC in Ubuntu 14.04 has DBUS interface enabled by default. Where in Ubuntu 12.04 is not. Check it from:

    Tools → Preferences → Advanced (or All) → Interface → Control Interfaces → D-Bus control interface. (Apply then Restart VLC)

    1. Create a file heartbeat.sh in ~/Desktop/:

      #!/bin/bash
      
      while sleep 55
      do
          if [ "$(pgrep vlc)" != "" ]
          then
              state=$(bash -c 'gdbus call --session \
                  --dest org.mpris.MediaPlayer2.vlc \
                  --object-path /org/mpris/MediaPlayer2 \
                  --method org.freedesktop.DBus.Properties.Get \
                  "org.mpris.MediaPlayer2.Player" \
                  "PlaybackStatus"')
              if [ "$state" = "(<'Playing'>,)" ]
              then
                  #xscreensaver-command -deactivate
                  xset s reset
              fi
          fi
      done
      
    2. Open terminal Ctrl+Alt+t

    3. Add run permissions:

      chmod +x ~/Desktop/heartbeat.sh
      
    4. Run script:

      ~/Desktop/heartbeat.sh
      
    5. Try VLC player.

  • For Gnome MPlayer (D-Bus enabled by default), use:

    "$(pgrep gnome-mplayer)" and --dest org.mpris.MediaPlayer2.gnome-mplayer

  • For (Totem) Videos player (D-Bus plugin disabled by default),

    Edit → Plugins → Check D-Bus service. (Restart totem)

    Use:

    "$(pgrep totem)" and --dest org.mpris.MediaPlayer2.totem

  • This is modified with to work with any player that provide MPRIS. It gets the list dynamically (drawback, it doesn't distinguish between audio only play and video play). The best way I think is to put manually the list of players you like:

    #!/bin/bash
    
    players_list=$(gdbus call --session --dest org.freedesktop.DBus \
        --object-path / --method org.freedesktop.DBus.ListNames | \
        awk 'BEGIN { RS=","; } /org.mpris.MediaPlayer2./ { gsub(/[\[\]()\x27]/, ""); print $1; }')
    
    while sleep 55
    do
        for player in $players_list
        do
            state=$(gdbus call --session \
                --dest $player \
                --object-path /org/mpris/MediaPlayer2 \
                --method org.freedesktop.DBus.Properties.Get \
                "org.mpris.MediaPlayer2.Player" \
                "PlaybackStatus")
            if [ "$state" = "(<'Playing'>,)" ]
            then
                echo $player $state send signal
                #xscreensaver-command -deactivate
                #use xset to work with all screensaver tools and avoid dimming display ... 
                xset s reset
                break
            else
                echo $player $state
            fi
        done
    done
    

Debug hints:

  1. Watch X idle time

    watch -n1 xprintidle
    

    or:

    while sleep 1; do xprintidle; done;
    
  2. Check if disabling screensaver works (while running this script, xscreensave should not pop up)

        #!/bin/bash
    
        while sleep 55
        do
            #xscreensaver-command -deactivate
            #xdg-screensaver reset
            xset s reset
        done
    
  3. Check for DBUS list for MPRIS player interface, example with VLC running:

        gdbus call --session --dest org.freedesktop.DBus \
        --object-path / --method org.freedesktop.DBus.ListNames | \
        awk 'BEGIN { RS=","; } /org.mpris.MediaPlayer2./ { gsub(/[\[\]()\x27]/, ""); print $1; }'
    

    Output:

        org.mpris.MediaPlayer2.vlc
        org.mpris.MediaPlayer2.vlc.instance3939
    

    Or using dbus-send command

        dbus-send --session \
        --dest=org.freedesktop.DBus \
        --type=method_call \
        --print-reply \
        /org/freedesktop/DBus \
        org.freedesktop.DBus.ListNames \
        | grep org.mpris.MediaPlayer2.
    

    Output:

        string "org.mpris.MediaPlayer2.vlc"
        string "org.mpris.MediaPlayer2.vlc.instance3939"
    

References:

user.dz
  • 48,105
  • @Chris26284, I have updated answer. I confirmed, it works in 12.04 as I tested it in a VirtualBox. So did you get any error on terminal when you run the script? – user.dz Apr 13 '14 at 06:05
  • This still doesn't work at all. I've tried both ways. I've deleted previous attempts and tried again from scratch. This does nothing. – Chris26284 Apr 15 '14 at 20:37
  • @Chris26284, I feel difficult to debug or to expect the cause. Only if you have patient to do so. I will try to add some debugging hints – user.dz May 02 '14 at 08:07
  • I recently updated my system to Ubuntu 14.04? Should the above fix work any better now? – Chris26284 May 25 '14 at 00:33
  • @Chris26284, I have updated it to use xset – user.dz Jun 17 '14 at 19:22
2

For MPV, and mplayer, the heartbeat functionality is built in.

1) Locate your mpv configuration file. locate mpv.conf

2) Open it up. sudo nano /path/to/mpv.conf

3) Add this line at the bottom. heartbeat-cmd="/usr/bin/xscreensaver-command -deactivate > /dev/null"

4) Close, and save. Ctrl+X if using nano.

Find out where to find your mpv.conf file here (configuration is identical on Arch Linux), https://wiki.archlinux.org/index.php/Mpv#Configuration

If the environment variable XDG_CONFIG_HOME is not set, user configuration files will be read from the ~/.config/mpv directory. System-wide configuration files are read from the /etc/mpv directory.

Mauro Colella
  • 436
  • 4
  • 6
2

I noticed all the answers here seemed unnecessarily complex; you don't really need to do this based on a specific media player - all you need to do is detect if any audio is playing. I'm actually surprised this isn't a feature built into xscreensaver. Here's a super simple bash script:

#!/bin/bash

while true
do
    state=$(pacmd list-sinks | grep -A 4 "*" | grep "state: " | cut -c 9-)  
    if [[ $state == SUSPENDED || $state == IDLE ]]
    then
        echo "State: $state. Not pausing screensaver."
        sleep 2m
    else
        echo "State: $state. Pausing screensaver."
        xscreensaver-command -deactivate > /dev/null
        sleep 4m
    fi
done
derHugo
  • 3,356
  • 5
  • 31
  • 51
  • Does this exclude audio-only playback like Spotify? Because only video should prevent the screensaver to engage, not pure audio. – klaar Apr 09 '22 at 20:59
0

This worked for me with Xubuntu 18.10 and with VLC, youtube videos, etc... wiithout the need to disable xscreensaver. Just add the following script when you system start:

#!/bin/bash
# enumerate all the attached screens
displays=""
while read id
do
    displays="$displays $id"
done< <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')

checkFullscreen() {

# loop through every display looking for a fullscreen window
for display in $displays
do
    #get id of active window and clean output
    activ_win_id=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
    activ_win_id=${activ_win_id:40:9}

    # Check if Active Window (the foremost window) is in fullscreen state
    isActivWinFullscreen=`DISPLAY=:0.${display} xprop -id $activ_win_id | grep _NET_WM_STATE_FULLSCREEN`
    if [[ &quot;$isActivWinFullscreen&quot; == *NET_WM_STATE_FULLSCREEN* ]];then
        xscreensaver-command -deactivate
    fi
done

}

while sleep $((30)); do checkFullscreen done

exit 0

Alter Lagos
  • 1,159
0

Here is my own version from Chris' code:

#!/bin/bash
while sleep 55
do
    players_list=$(gdbus call --session --dest org.freedesktop.DBus \
        --object-path / --method org.freedesktop.DBus.ListNames | \
        awk 'BEGIN { RS=","; } /org.mpris.MediaPlayer2./ { gsub(/[\[\]()\x27]/, ""); print $1; }')

    for player in $players_list
    do
        state=$(gdbus call --session \
            --dest $player \
            --object-path /org/mpris/MediaPlayer2 \
            --method org.freedesktop.DBus.Properties.Get \
            "org.mpris.MediaPlayer2.Player" \
            "PlaybackStatus")

        fullscreen=$(gdbus call --session \
            --dest $player \
            --object-path /org/mpris/MediaPlayer2 \
            --method org.freedesktop.DBus.Properties.Get \
            "org.mpris.MediaPlayer2" \
            "Fullscreen")

        if [ "$state" = "(<'Playing'>,)" -a "$fullscreen" = "(<true>,)" ]
        then
            echo $player $state $fullscreen send signal
            xscreensaver-command -deactivate
            break
        else
            echo $player $state $fullscreen
        fi
    done
done

It checks at each iteration if the list of players has been changed.

It also deactivates the screensaver only if the player is fullscreen which is normally the case for video.

I just put this script in the autostart and don't bother anymore with xscreensaver while watching video.

derHugo
  • 3,356
  • 5
  • 31
  • 51
sk3
  • 1
0

This worked for me on Xubuntu 17.10 with xscreensaver

#!/bin/bash

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