Announcement

Collapse
No announcement yet.

Powerdevil sleep timer behavior

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Powerdevil sleep timer behavior

    Hello people,

    I recently switched from Ubuntu vanilla to Kubuntu. After spending some time tweaking the OS to match the functionalities I had on Ubuntu, I've hit a wall with Powerdevil.

    When setting the power options to turn off the screen and sleep after 10 minutes, the system doesn't immediately go to sleep after a movie ends in VLC. Instead, you have to wait the full 10 minutes after the sleep triggers, which wasn't the case with Ubuntu.

    I've visited almost every website to get info on this, tried writing a bash script using xprintidle. Unfortunately, I discovered that the xprintidle timer resets when VLC stops, rendering it useless.

    Is there anything that I'm missing? Or it's just impossible to achieve this given the way Powerdevil works?

    #2
    Hello DrPanic
    I'm new in Kubuntu too, but you don't said in your message if you use the option "Quit at the end of the playlist" in the menu "Media".
    I don't think the software behaves in the same way if this function is activated or not.

    -Sincerely, User09

    Comment


      #3
      After a few tests more, I discovered that xprintidle resets every time an inhibitor entry is added/removed from "Energy management" on "Status and Notifications". I don't know if this is related with the idle timer resetting and could be the root cause.

      In the mean time I made another script using xinput instead which I think works as Intended I'll leave it here just in case someone wants it.

      Code:
      #!/bin/bash
      
      # Function to get the list of device IDs for the mouse and keyboard
      get_device_ids() {
          xinput --list | grep -E 'slave\s+pointer|slave\s+keyboard' | awk -F'id=' '{print $2}' | awk '{print $1}'
      }
      
      # Function to reset the timer
      reset_timer() {
          idle_time=0
          echo $idle_time > /tmp/idle_timer
      }
      
      # Function to check VLC playing status
      is_vlc_playing() {
          vlc_status=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.vlc \
              /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get \
              string:"org.mpris.MediaPlayer2.Player" string:"PlaybackStatus" 2>&1)
      
          if [[ $vlc_status == *"Playing"* ]]; then
              echo "true"
          elif [[ $vlc_status == *"DBus.Error.ServiceUnknown"* ]]; then
              echo "false"
          else
              echo "false"
          fi
      }
      
      # Function to check Firefox playing status
      is_firefox_playing() {
          firefox_status=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.plasma-browser-integration \
              /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get \
              string:"org.mpris.MediaPlayer2.Player" string:"PlaybackStatus" 2>&1)
      
          if [[ $firefox_status == *"Playing"* ]]; then
              echo "true"
          elif [[ $firefox_status == *"DBus.Error.ServiceUnknown"* ]]; then
              echo "false"
          else
              echo "false"
          fi
      }
      
      # Function to suspend the system
      suspend_system() {
          pkill -f vlc
          pkill -f firefox
          pkill -f xinput
          systemctl suspend
          pkill -f test.sh
      }
      
      # Initialize the idle timer file
      echo 0 > /tmp/idle_timer
      
      # Get the list of device IDs
      device_ids=$(get_device_ids)
      
      # Monitor events from all devices in the background
      for id in $device_ids; do
          xinput --test $id | while read line; do
              reset_timer
          done &
      done
      
      # Increase the timer in milliseconds
      while true; do
          current_time=$(cat /tmp/idle_timer)
          new_time=$((current_time + 1000))
          echo $new_time > /tmp/idle_timer
          echo "Idle time: ${new_time} ms"
      
          vlc_playing=$(is_vlc_playing)
          firefox_playing=$(is_firefox_playing)
          echo "VLC Playing: $vlc_playing, Firefox Playing: $firefox_playing"
      
          if [ "$new_time" -ge 600000 ]; then
              vlc_playing=$(is_vlc_playing)
              firefox_playing=$(is_firefox_playing)
              if [ "$vlc_playing" = "false" ] && [ "$firefox_playing" = "false" ]; then
                  echo "System will suspend now."
                  suspend_system
              fi
          fi
      
          sleep 1
      done
      
      ​

      Comment

      Working...
      X