Is there a way to find the id and maybe the path or the type(browser, ...) of the front most window in X?
Asked
Active
Viewed 678 times
1 Answers
1
To find out the window ID, try:
xprop -root|grep "_NET_CLIENT_LIST_STACKING(WINDOW): window id"
_NET_CLIENT_LIST_STACKING has bottom-to-top stacking order
One way to accomplish this is to parse the output of this command inside your application. The topmost window is the last on the list.
EDIT:
If you need to retrieve the process ID from the window ID, there's a small application here that shows how to do this trick. I successfully compiled it with:
g++ win_procid.cpp -o win_procid -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libgtop-2.0 -lXtst -lgtop-2.0
I had to install the package libgtop2-dev because I didn't have it on my system.

karlphillip
- 92,053
- 36
- 243
- 426
-
I just found this thread, it might be an interesting reading for you: http://stackoverflow.com/q/2041532/176769 – karlphillip May 17 '11 at 20:08
-
Is there a way to distinguish the first "normal" window(i don't know how to say it, meaning a window that does not belong to a browser or other application.In mac it's Finder's window) – thikonom May 17 '11 at 20:34
-
Not that I'm aware of. But from the process ID you can grab the process name and do this checking yourself. If process name == browser's name, then ignore this PID and get the next one from the list. – karlphillip May 17 '11 at 20:44
-
This thread might be interesting: http://stackoverflow.com/questions/60967/how-do-i-keep-track-of-related-windows-in-x11/61144#61144 – karlphillip May 17 '11 at 20:45