diff options
author | 2022-07-08 20:23:17 +0530 | |
---|---|---|
committer | 2022-07-08 20:23:17 +0530 | |
commit | 471d0b43e3fa2f5f077ce9ad4824992058d26e0e (patch) | |
tree | d262855355d683074c21bb39f196e98e4d26cc94 /src/Watcher/get_windows.py | |
parent | af16350b30a9f02974ddc880ee51bf475cb150f8 (diff) | |
download | shopno-os-log-sync-471d0b43e3fa2f5f077ce9ad4824992058d26e0e.tar.gz shopno-os-log-sync-471d0b43e3fa2f5f077ce9ad4824992058d26e0e.zip |
updating log file algorithm | added AFK feature | changing dependency xdotool to ewmh
Diffstat (limited to 'src/Watcher/get_windows.py')
-rwxr-xr-x | src/Watcher/get_windows.py | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/src/Watcher/get_windows.py b/src/Watcher/get_windows.py index 6b1960f..393c7ff 100755 --- a/src/Watcher/get_windows.py +++ b/src/Watcher/get_windows.py @@ -1,49 +1,55 @@ import os import time +from ewmh import EWMH class window: def __init__(self, class_name, title_name): self.class_name = class_name self.title_name = title_name -# get classname of app that user working on -def active_window(): - # running bash command and storing result as a string - active_window = os.popen("xdotool getwindowfocus getwindowclassname").read() - active_window = active_window[0:-1] - return active_window - # get title name of app that user working on def active_window_title(): - active_window_title = os.popen("xdotool getwindowfocus getwindowname").read() - active_window_title = active_window_title[0:-1] + try: + win = EWMH().getActiveWindow() + active_window_title = win.get_wm_name() + except AttributeError: + active_window_title = "unknown" + active_window_title = active_window_title.capitalize() return active_window_title -# get list of opened apps in background as well as in foreground -def opened_windows_list(): - raw_data = os.popen('''wmctrl -lx | awk '{print $3}' ''').read() - raw_data_ls = raw_data.split('\n') - windows_list = [] - for x in raw_data_ls: - last = x.rfind(".") - windows_list.append(x[last+1::]) - windows_list.remove('') - windows_list = list(set(windows_list)) - return windows_list +# get classname of app that user working on +def active_window(): + try: + win = EWMH().getActiveWindow() + active_window = win.get_wm_class()[1] + except AttributeError: + active_window = "unknown" + + if len(active_window) > 20: + active_window = "unknown" + elif "\n" in active_window: + active_window = "unknown" + active_window = active_window.capitalize() + + # check whether user is using nvim or vim + aw_title = active_window_title() + terminals = ["Kitty", "Alacritty", "Terminator", "Tilda", "Guake", "Yakuake", "Roxterm", "Eterm", "Rxvt", "Xterm", "Tilix", "Lxterminal", "Konsole", "St", "Gnome-terminal", "Xfce4-terminal", "Terminology", "Extraterm"] + if active_window in terminals: + if "Nvim" in aw_title: + active_window = "NeoVim" + elif "Vim" in aw_title: + active_window = "Vim" + return active_window # returns true if user has move to next app which is not the same as previous def is_window_changed(a): result = False - while not(result): - time.sleep(1) - b = active_window() - if a != b : - result = True - else: - result = False + time.sleep(0.1) + b = active_window() + if a != b : + result = True return result - ### what to do after window get change I've to append one line in csv data file in following format ### opened-time closed-time time-spent window_class_name window_title_name |