Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not initiate breaks when the display is blank/sleeping/off or the screen is locked #134

Open
vedgy opened this issue Jun 10, 2019 · 8 comments
Labels
feature New feature or request

Comments

@vedgy
Copy link
Contributor

vedgy commented Jun 10, 2019

When the Reading mode is on, workrave keeps asking for breaks indefinitely even if there is nothing to read on the screen and the user stopped all mouse/keyboard activity some time ago.

Workrave can check if the screen is readable before initiating a break. If the screen is not readable, check again after some time (a percentage of the shortest interval between enabled breaks perhaps).

For example, on GNU/Linux xset q can be used to query the current display state. Unfortunately, it is probably unfeasible for workrave to support all the different screen lockers. But I think some checks (the display state at least) is better than no detection at all.

#120 proposes an alternative manual way to address this issue - by configuring the inactivity timer.

@rcaelers rcaelers added the feature New feature or request label Feb 8, 2020
@vedgy
Copy link
Contributor Author

vedgy commented Feb 20, 2020

I've implemented a workaround that works perfectly with xfce4-screensaver. I added the script below into Autostart list. It has to be constantly running and monitoring D-Bus.

The script always works for screen locking. However it requires the Activate screensaver when computer is idle option to be on in xfce4-screensaver settings in order to detect display blanking/sleeping/off. With this option on the screensaver emits the necessary ActiveChanged signal even if the Enable Screensaver option is off.

suspend-workrave-on-screensaver-activation

#!/bin/bash

setWorkraveOperationMode () {
    dbus-send --session --dest=org.workrave.Workrave --type=method_call \
    /org/workrave/Workrave/Core org.workrave.CoreInterface.SetOperationMode \
    string:"$1"
}

justChanged=0

dbus-monitor --session "interface='org.xfce.ScreenSaver',member='ActiveChanged'" |
while read -r line; do  
  if [[ $justChanged == 1 ]]; then
    if [[ "$line" =~ 'true' ]]; then
      setWorkraveOperationMode "suspended"
    elif [[ "$line" =~ 'false' ]]; then
      setWorkraveOperationMode "normal"
    else
      echo "Error! Unexpected activated value: '$line' $(date)"
    fi
    justChanged=0
  elif [[ "$line" =~ 'ActiveChanged' ]]; then
    justChanged=1
  fi
done

@xeruf
Copy link
Contributor

xeruf commented Jul 8, 2020

This sounds like a great way to implement other custom behavior - is the workrave dbus API documented somewhere?

@vedgy
Copy link
Contributor Author

vedgy commented Jul 9, 2020

Not that I know of. You can explore the DBus API in QDBusViewer or a similar tool.

@xeruf
Copy link
Contributor

xeruf commented Aug 6, 2020

Btw, maybe you can add a PR to add the script to the contrib section, so it doesn't get lost here :)

@vedgy
Copy link
Contributor Author

vedgy commented Aug 7, 2020

The script is now in contrib.

@xeruf
Copy link
Contributor

xeruf commented Aug 8, 2020

@vedgy nice! Can this be adapted to suspend workrave when there is a fullscreen application running?

@vedgy
Copy link
Contributor Author

vedgy commented Aug 8, 2020

Only if your window manager/desktop environment sends a D-Bus signal when an application enters and exits the full-screen mode.

@xeruf
Copy link
Contributor

xeruf commented Aug 8, 2020

Well, I now figured out how to check it: https://askubuntu.com/a/1265587
so I guess a cronjob would be the way to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants