GhostNaN / mpvpaper

A video wallpaper program for wlroots based wayland compositors.
GNU General Public License v3.0
805 stars 26 forks source link

Is it possible to make the wallpaper pause on battery and unpause when charging? #33

Closed conrad-mo closed 2 years ago

conrad-mo commented 2 years ago

I am wondering if theres any possibility of making the wallpaper pause on battery and animated again when charging

Also, is there any way to reduce the fps from 30fps to something along the lines of 12 to reduce processing?

GhostNaN commented 2 years ago

I am wondering if theres any possibility of making the wallpaper pause on battery and animated again when charging

I'm not sure if I want to build in the functionality into mpvpaper, but it's absolutely possible with just a bash script. I'll get you started with using upower to probe:

#!/bin/bash

MPV_SOCKET_PATH="/tmp/mpv-socket"

mpvpaper -o "input-ipc-server=$MPV_SOCKET_PATH" '*' /path/to/wallpaper &

while pidof mpvpaper >/dev/null; do
    bat_state=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep state | awk '{print $2}')

    if [ "$bat_state" = "fully-charged" ] || [ "$bat_state" = "charging" ]; then
        echo 'set pause no' | socat - $MPV_SOCKET_PATH
    elif [ "$bat_state" = "discharging" ]; then
        echo 'set pause yes' | socat - $MPV_SOCKET_PATH
    fi

    sleep 5
done

Feel free to modify as you like, but this should work for your use case.

Also, is there any way to reduce the fps from 30fps to something along the lines of 12 to reduce processing?

Sure, you can add vf-add=fps=12:round=near to your mpv options like so: mpvpaper -o "vf-add=fps=12:round=near" DP-3 /path/to/video

conrad-mo commented 2 years ago
#!/bin/bash

MPV_SOCKET_PATH="/tmp/mpv-socket"

mpvpaper -o "input-ipc-server=$MPV_SOCKET_PATH no-audio --loop" '*' /path/to/wallpaper &

while pidof mpvpaper >/dev/null; do
    bat_state=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep state | awk '{print $2}')

    if [ "$bat_state" = "fully-charged" ] || [ "$bat_state" = "charging" ]; then
        echo 'set pause no' | socat - $MPV_SOCKET_PATH
    elif [ "$bat_state" = "discharging" ]; then
        echo 'set pause yes' | socat - $MPV_SOCKET_PATH
    fi

    sleep 5
done

Does this script not work with loop enabled?

conrad-mo commented 2 years ago
#!/bin/bash

MPV_SOCKET_PATH="/tmp/mpv-socket"

mpvpaper -o "input-ipc-server=$MPV_SOCKET_PATH no-audio --loop" '*' /path/to/wallpaper &

while pidof mpvpaper >/dev/null; do
  bat_state=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep state | awk '{print $2}')

  if [ "$bat_state" = "fully-charged" ] || [ "$bat_state" = "charging" ]; then
      echo 'set pause no' | socat - $MPV_SOCKET_PATH
  elif [ "$bat_state" = "discharging" ]; then
      echo 'set pause yes' | socat - $MPV_SOCKET_PATH
  fi

  sleep 5
done

Does this script not work with loop enabled?

Nevermind I accidently removed the & after the initial mpvpaper call