On Tue, 22 Nov 2005 10:58:24 -0800 Tim Roberts <[EMAIL PROTECTED]> babbled:
> Karthik Ramamoorthy wrote: > > > > > Is there any option to get the topmost window or currently > > active window through anu xlib API . Because i think, through > > XQueryTree we can get all the Alive windows(windows that are not > > closed) only. So is there any means to get the topmost window, also is > > it possible to check whether the windowID that i am having is top most > > window or not? > > > XGetInputFocus will tell you the window that currently holds the > keyboard focus. That is usually what you what when you ask for the > "topmost window". well not topmost - but definitely your best candidate for the "active window". the topmost window is easy. read the manual page on XQueryTree - note it returns windows in ORDER of stacking, from bottom to top. so the last window in the returned array is the top-most one (at that sibling level). other windows by definition of parent/child CANNOT be on top so simply then query the children of the topmost window at any level, UNTIL you find a window that has a WM_STATE property on it (it has been managed by the window manager) (this code will not work with no wm active - but that basically almost never happens. you can fall back to finding a window with WM_NAME or WM_CLASS properties instead as most clients set a title - but again, not guaranteed - you shoudl use the LAST window with WM_STATE you find in this tree hunt OR the LAST window with WM_NAME/WM_CLASS if you find no window with WM_STATE). note - if the topmost window is not visible (i suggest you get the window attributes and find out) then use the next one down - until you find one that is mapped - then that is what you should consider the topmost. also remember - grab the server at the start of your hunting and ungrab at the end to avoid the tree changing on you magically between requests while you are hunting as windows may be raised, lowered, mapped and unmapped while you look. this DOESNT stop windows being destroyed as clients lose connections due to other issues (kill -9, network problems). so you need to make sure your x error handler is set and you actually handle a request error gracefully, assuming the branch you were walking down is now dead fropm the error point onwards. the simple way is then to restart the scan from the top until you get no errors (as this wont happen too often this shouldnt be a problem), OR you can backstep to the last window that was "ok" and continue from there to be a bit more efficient in the rare case that clients are disconnected while you do this walk. just keep in mind - the window heirachy is a TREE with many levels. ordering at any level in the tree is stacking WITHIN that window. a window may or may not be visible, but if it is not, then its children will not be visible. also you may want to simply ignore windows that are input only as they will likely NEVER contain anything of interest for you :) while i'm at it being thourough - it Is possible the topmost window is an override-redirect window - but this is rare and special and a lot harder to guess at. -- ------------- Codito, ergo sum - "I code, therefore I am" -------------- The Rasterman (Carsten Haitzler) [EMAIL PROTECTED] 裸好多 Tokyo, Japan (東京 日本) _______________________________________________ Devel mailing list Devel@XFree86.Org http://XFree86.Org/mailman/listinfo/devel