aboutsummaryrefslogtreecommitdiff
path: root/src/Watcher/afk.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/Watcher/afk.py')
-rwxr-xr-xsrc/Watcher/afk.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Watcher/afk.py b/src/Watcher/afk.py
index 4f2b1f7..41f8fe9 100755
--- a/src/Watcher/afk.py
+++ b/src/Watcher/afk.py
@@ -1,4 +1,5 @@
import os
+import time
# checks if currently in afk mode, only returns true once
def get_afk_status(afk_active, timeout):
@@ -14,6 +15,21 @@ def returned_from_afk(afk_active, timeout):
return has_returned
def is_afk(timeout):
- timeout = timeout * 60 * 1000
+ timeout = timeout * 60 * 1000 - 200 # minimizing 200 milisec error
#If the AFK feature is installed
- return (int((os.popen("xprintidle").read())) > timeout)
+ time_since_last_input = int(os.popen("xprintidle").read()[:-1])
+ if (time_since_last_input > timeout):
+ video_playback = os.popen("""pacmd list-sink-inputs | grep -w state | grep -i 'RUNNING'""").read()
+ # if playback is not running as well as user is AFK
+ if "RUNNING" in video_playback:
+ return False
+ # if playback is running is background as well as user is AFK
+ else:
+ return True
+ return False
+
+# testing out
+if __name__ == "__main__":
+ while True:
+ time.sleep(1)
+ print(is_afk(0.05))