Does anyone know how to get the PID of the top active window and then how to get the properties of the window using the PID? I mean properties like process name, program nam
Am very very late to the party, but I had a similar problem, and I think this can help someone else who has the same problem. There is a command line trick to do this, you can try execvp'ing it, or executing it redirecting the output to your code
xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) _NET_WM_NAME WM_CLASS
gives the window name, as well as the program name. Eg, for this tab, it gives me
_NET_WM_NAME(UTF8_STRING) = "linux - Getting pid and details for topmost window - Stack Overflow - Mozilla Firefox"
WM_CLASS(STRING) = "Navigator", "Firefox"