diff options
author | 2022-07-18 18:15:09 +0530 | |
---|---|---|
committer | 2022-07-18 18:15:09 +0530 | |
commit | dbf80bf782b60db15e964b42bbe0d800fdad7626 (patch) | |
tree | 19b421e204d183e75867cae28f44b0408f14716e | |
parent | fbe30df91fd15dd52c31a1237c9a00c24763f509 (diff) | |
download | shopno-os-log-sync-dbf80bf782b60db15e964b42bbe0d800fdad7626.tar.gz shopno-os-log-sync-dbf80bf782b60db15e964b42bbe0d800fdad7626.zip |
adding AFK condition if there is any video playback running in background (for pulseaudio) | changing value for more accuracy
-rwxr-xr-x | src/Watcher/afk.py | 20 | ||||
-rwxr-xr-x | src/Watcher/get_windows.py | 2 |
2 files changed, 19 insertions, 3 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)) 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 |