Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>xlib's <code>XGetInputFocus</code> will tell you which window has focus, which is probably more interesting than which is topmost. Cf. Xfree86's <a href="http://www.xfree86.org/4.0/XGetInputFocus.3.html" rel="nofollow noreferrer">XGetInputFocus manpage</a>.</p> <p>If it's really the topmost window, and not the window-with-focus you're after, well, I don't think there is a simple call to do that, because xlib doesn't seem to offer any way of querying the global stacking order, which is the data structure that tells you which windows are in front of which others.</p> <p>Once you have the right window id, <code>xprop</code> will list the pid under _NET_WM_PID_ - though not all windows have such a property...</p> <p><strong>Postscript</strong> More thoughts; long time since I've thought about <code>xlib</code>...</p> <p>To summarise:</p> <ol> <li><p>X does not offer any reliable association between window ids and pids, and as Noufal observes, the windows served on an X desktop may come from many different machines, and two remote clients might happen to use the same PID, since it is only unique per machine. Cf. <a href="https://stackoverflow.com/questions/151407/how-to-get-an-x11-window-from-a-process-id">How to get an X11 Window from a Process ID?</a></p></li> <li><p>X does not seem to offer an interface asking which is the topmost window, or whether one window occludes another. Likewise with privileged access... Cf. <a href="https://stackoverflow.com/questions/1201179/how-to-identify-top-level-x11-windows-using-xlib">How to identify top-level X11 windows using xlib?</a></p></li> <li><p>Commonly available window managers and Qt don't give you privileged access to X</p></li> <li><p>Without both a way of finding the topmost window, and a reliable association of the window id to the matching pid, we can't solve the question.</p></li> <li><p>We can find which window has focus, and this is probably what we want. But again, without the wid to pid map ...</p></li> </ol> <p>So, sorry, it looks like it can't be done.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload