You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar to getWindowsAt, but only returns the top window at position. It can also rely on faster implementation since it may not need to get all windows.
import win32gui
def __get_window_from_point(x: int, y: int) -> tuple[int, str]:
# Grab the window handle from the coordinates selected by the widget
hwnd = cast(int, win32gui.WindowFromPoint((x, y)))
# Want to pull the parent window from the window handle
# By using GetAncestor we are able to get the parent window instead
# of the owner window.
while win32gui.IsChild(win32gui.GetParent(hwnd), hwnd):
hwnd = cast(int, user32.GetAncestor(hwnd, GA_ROOT))
window_text = win32gui.GetWindowText(hwnd)
return hwnd, window_text
For Linux, it seems getClientListStacking actually returns windows in stacking order from bottom to top.
I'm curious if there's any real performance difference between getClientListStacking and getClientList. If not, we could just opt for getClientListStacking all the time. And take the last element returned by getWindowsAt
I think I get your point. You want the upper window at a given point, right? Then, we could create a new method called: getUpperWindowAt() (sorry for my english, perhaps there is a better word than "upper").
In such a case, order matters, so your implementation on Windows and Linux seems totally right (I have not tested getClientList vs. getClientListStacking performance, though I don't think there should be much difference).
The problem will come, once again, on macOS. I didn't find any property or attribute which can be used to know the windows/apps stacking. Quartz returns the list of apps in "last to first focused" order, which in many cases may not match "upper". Given an app, it's possible to know its windows stack order, but unfortunately not for the app itself... Yes, I also love macOS... HAHAHAHA!
I'm still out for some reasons and couldn't work on the module yet. If you agree, I will add this new method (including the constrains of macOS) as soon as I can!!! You can also clone or fork the project and work on a PR if you want to. Any contribution is more than welcome!
Activity
Avasam commentedon Jul 24, 2022
For Linux, it seems
getClientListStackingactually returns windows in stacking order from bottom to top.I'm curious if there's any real performance difference between
getClientListStackingandgetClientList. If not, we could just opt forgetClientListStackingall the time. And take the last element returned bygetWindowsAthttps://ewmh.readthedocs.io/en/latest/ewmh.html#ewmh.ewmh.EWMH.getClientListStacking
I also saw someone say that XQueryTree gives list of windows in the stacking order. But I have not tested that claim.
https://stackoverflow.com/questions/31712876/with-x11-get-window-at-coordinates#31733725
https://tronche.com/gui/x/xlib/window-information/XQueryTree.html
Kalmat commentedon Jul 24, 2022
Hi!
I think I get your point. You want the upper window at a given point, right? Then, we could create a new method called: getUpperWindowAt() (sorry for my english, perhaps there is a better word than "upper").
In such a case, order matters, so your implementation on Windows and Linux seems totally right (I have not tested getClientList vs. getClientListStacking performance, though I don't think there should be much difference).
The problem will come, once again, on macOS. I didn't find any property or attribute which can be used to know the windows/apps stacking. Quartz returns the list of apps in "last to first focused" order, which in many cases may not match "upper". Given an app, it's possible to know its windows stack order, but unfortunately not for the app itself... Yes, I also love macOS... HAHAHAHA!
I'm still out for some reasons and couldn't work on the module yet. If you agree, I will add this new method (including the constrains of macOS) as soon as I can!!! You can also clone or fork the project and work on a PR if you want to. Any contribution is more than welcome!