Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui.windows() is not Z ordered on Windows #147

Closed
jamesmugford opened this issue May 13, 2020 · 13 comments
Closed

ui.windows() is not Z ordered on Windows #147

jamesmugford opened this issue May 13, 2020 · 13 comments

Comments

@jamesmugford
Copy link

windows = ui.windows() seems broken

Properties attached to window object are not correct.

e.g: window.height and window.y for specific windows all return the same result

Hope this help

OS: Windows 10

@timo
Copy link

timo commented May 13, 2020

the window class doesn't seem to have height and y properties at all at least on my version; does it have a .rect property?

@jamesmugford
Copy link
Author

Hmmm, maybe it's a deprecated API?

I assumed it was present from knausj85's code, here: https://github.com/knausj85/knausj_talon/blob/dcbb1ea89fd1bfbd09f57c25d9dc8a8907270c42/code/mouse.py#L239

It doesn't look like there is a rect property either.

This is currently a blocker for creating nice gaze scrolling

I'm presuming this is because the eyetracking API is not public yet and is undergoing frequent change.

I'll try to set up proper IntelliSense and see what is available

@knausj85
Copy link

knausj85 commented May 13, 2020

I think Talon's working fine

I think you're slightly misreading the code here due to questionable variable naming. "window" in the referenced script is actually the rect.

The function looks for the first window that contains mouse coordinate. This should perhaps just use ui.active_window() instead.

if you do something like this, you will see all dimensions and positions for windows.
for w in ui.windows(): print(str(w) + "({},{}) ({}{})".format(w.rect.x, w.rect.y, w.rect.width, w.rect.height))

@lunixbochs
Copy link

is this not actually a bug?

@knausj85
Copy link

As far as I can tell, the window sizing information is correct on Windows 10. I believe the actual issue is that the window list isn't Z-sorted, as on Mac and Linux.

I've poked around for an API that will allow us to do so, but they all feature ominous warnings.

e.g., https://stackoverflow.com/questions/6381198/get-window-z-order-with-python-windows-extensions suggests:

import win32gui
import win32con
def get_windows():
    '''Returns windows in z-order (top first)'''
    lst = []
    top = win32gui.GetTopWindow()
    if top is None: return lst
    lst.append(top)
    while True:
        next = win32gui.GetNextWindow(lst[-1], win32con.GW_HWNDNEXT)
        if next is None: break
        lst.append(next)
    return lst

but this just calls GetWindow, which has some (albeit obvious) caveats:

Remarks
The EnumChildWindows function is more reliable than calling GetWindow in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed.

People claim EnumWindows / EnumChildWindows z-orders things, but its not actually documented and probably not guaranteed.

throws hands in air

@lunixbochs
Copy link

lunixbochs commented Aug 16, 2020

Is a valid janky solution just to sort the topmost window to the front and ignore ordering the rest for now?

@knausj85
Copy link

Hmm, maybe. I'd be willing to test around it for you.

@lunixbochs
Copy link

What does your code need the window order for?

@knausj85
Copy link

knausj85 commented Aug 16, 2020

It's used for the rudimentary "gaze" scrolling with control mouse. Scrolls based on the cursor distance vs midpoint of the window that contains the cursor.

https://github.com/knausj85/knausj_talon/blob/d762a609d264b065c165dd97109262bf2915bae4/code/mouse.py#L282

@lunixbochs
Copy link

lunixbochs commented Aug 16, 2020 via email

@knausj85
Copy link

It's on my list to look at active_window first to improve it - or maybe exclusively on Windows for now, but that's a little less convenient. Since scrolling is allowed without a window having focus on Windows and Mac, it's not 'ideal' to consider just active_window, long-term, imo. I take advantage of this behavior often.

@lunixbochs lunixbochs changed the title ui.windows() broken ui.windows() is not Z ordered on Windows Nov 3, 2020
@lunixbochs lunixbochs transferred this issue from talonvoice/beta Nov 3, 2020
@lunixbochs lunixbochs added this to the v0.2.0 milestone Jan 7, 2021
@lunixbochs
Copy link

lunixbochs commented Jun 20, 2021

https://stackoverflow.com/q/295996

Previous answers need considerable refinement. Enum-order = Z-order only if GetSystemMetrics(SM_IMMENABLED)=0, i.e. Input Method Manager/Input Method Editor features are disabled. Because all windows class "IME" (the title "Default IME") and "MSCTFIME UI" are enumerated after the window "Progman" ("Program Manager"), - i.e. not in Z-order.

@lunixbochs
Copy link

Fixed in 0.1.5-452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants