I am trying to build something like Manic Time - which is an application that tracks what the user is currently working on. It worked flawlessly on Windows, but doesn't support Linux.
It has mad features, but the core is basically just tracking what the current 'active' window is, it's process, window title etc.
I've been thinking about this problem for some time and here's the Pythonic pseudo-code that I've come up with, but I'm not sure if this is the way to go.
# The script will probably run as a daemon
while True:
# Get process, window title, etc.
wnd_details = get_active_window_details()
# Save the current timestamp and the details to a database (SQLite)
insert_in_db(current_timestamp, wnd_details)
# Wait for a second
sleep(1000)
Will executing a write query per second affect performance?
An optimization might be to remember what the previous window details were and write to database only when the window changes (the user has switched to another application) but that will add unnecessary complexity to the code.
Yet another thing to look into might be some sort of hooks or callbacks, so my Python code gets called whenever a Window change occurs (like a new window is created or active window is changed) I guess Windows had something similar to this, but have no idea about Linux.