From dbf80bf782b60db15e964b42bbe0d800fdad7626 Mon Sep 17 00:00:00 2001 From: Waishnav Date: Mon, 18 Jul 2022 18:15:09 +0530 Subject: adding AFK condition if there is any video playback running in background (for pulseaudio) | changing value for more accuracy --- src/Watcher/afk.py | 20 ++++++++++++++++++-- src/Watcher/get_windows.py | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src') 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)) diff --git a/src/Watcher/get_windows.py b/src/Watcher/get_windows.py index 2831833..8f30932 100755 --- a/src/Watcher/get_windows.py +++ b/src/Watcher/get_windows.py @@ -42,7 +42,7 @@ def active_window(): def is_window_changed(a, afk, timeout): result = False while not(result): - time.sleep(1) + time.sleep(0.5) b = active_window() if a != b : result = True -- cgit v1.2.3