Skip to content

ui.active_window() sometimes returns the wrong windows #502

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

Closed
phillco opened this issue Apr 27, 2022 · 19 comments
Closed

ui.active_window() sometimes returns the wrong windows #502

phillco opened this issue Apr 27, 2022 · 19 comments

Comments

@phillco
Copy link

phillco commented Apr 27, 2022

I'm on beta 454, but I've noticed this for a while, most commonly (exclusively?) on JetBrains IDEs. After pushing ctrl-` to rotate windows, ui.active_window() will sometimes return the wrong (old), one. I notice this most frequently when using keyboard shortcuts to snap windows.

In testing, I noticed ui.focused_element().AXWindow does return the right one, so for now I can work around by writing an action that will compare the AXTitle of those two, and if they differ searching through ui.active_app().windows() to find the right one.

@phillco
Copy link
Author

phillco commented Apr 27, 2022

Correction: haven't tried this on 460 yet, will report back if it still happens there.

@lunixbochs
Copy link

Can you retest on -468?

@phillco
Copy link
Author

phillco commented Jun 5, 2022

Just for clarity, still seeing this on 496, in JetBrains. I've also noticed ui.active_window().title can also be stale even if the active window is correct. I've added some overrides for JetBrains specifically to work around this for now.

@phillco
Copy link
Author

phillco commented Aug 3, 2022

I unfortunately do continue to see this on recent betas, although it's less common than before your ~46x fixes.

I'll retest on the newly released 2022.2 though, as that version brings in a large JVM upgrade which I imagine brings in a lot of new Swing behavior.

@rntz
Copy link

rntz commented Dec 10, 2022

I believe I have observed this on mac ventura, in my case with firefox.

@rntz
Copy link

rntz commented Jan 3, 2023

I now observe behavior that I believe to be due to this regularly. It's pretty annoying, a lot of my window management stuff now doesn't work reliably. Mac Ventura, talon 0.3.1-57, multiple apps (firefox, emacs, apple terminal). I'll let you know if I figure out a consistent repro.

symptoms possibly due to this:

@lunixbochs
Copy link

still just firefox?

@rntz
Copy link

rntz commented Jan 3, 2023

No, multiple apps. Firefox, Apple Terminal, Emacs are the ones I think I've seen it on.

@rntz
Copy link

rntz commented Jan 3, 2023

I made a little script that watches for ui.active_window() not agreeing with ui.focused_element() to see if I can catch it in the act and figure out how to repro consistently, but no hits yet: https://gist.github.com/f5771b6d2b303c4f1287379b27a9be9b

@lunixbochs
Copy link

lunixbochs commented Jan 3, 2023

Don't check it in the win_focus event, call this wherever you're triggering your window management code.

@rntz
Copy link

rntz commented Jan 30, 2023

The script had way too many false positives so I turned it off a while ago. I think this was because terminal tabs are actually treated as windows somehow? Ugh. Bug is still occurring frequently and very frustrating. I've mostly been mixing keyboard/mouse use with talon use, maybe that has something to do with it. Gonna try instrumenting just the snap commands again.

@rntz
Copy link

rntz commented Jan 31, 2023

Ok, I managed to actually catch an occurrence with the instrumentation on. I'm not sure what triggered it, but once it happened, switching between two different firefox windows on the same virtual desktop by clicking with the mouse did not update ui.active_window() (so it became incorrect whenever I clicked on the other window) but did update ui.focused_element().window correctly. Switching to another desktop, however, fixed the problem.

@lunixbochs
Copy link

firefox is kind of bad at accessibility events, talon already has several firefox specific workarounds in place

@rntz
Copy link

rntz commented Feb 2, 2023

I've now observed similar behavior in Emacs. Emacs was focused but ui.active_window().title reported a title that I think didn't exist on any window, and consistent with this, "snap right" failed with UIErr: Could not get window rect.

Meanwhile, ui.focused_element().window.title reported the correct title, but ui.focused_element() had no AXWindow attribute (this seems to be standard for Emacs).

If I switched away from Emacs by clicking on an Apple Terminal window, then re-focused the Emacs window by clicking, the problem persisted. But, there was no problem with the Terminal window focused.

Does Talon's ability to determine which window is active depend on that application doing the right thing? That would be a bummer. This all worked quite reliably for me in Linux.

@david-tejada
Copy link

Is there any hope for this in Firefox? Any time I want to snap a recently focused window I have to first switch to another app and then switch back. win.title also doesn't update as you switch tabs. I have also observed this behavior in Windows.

@lunixbochs
Copy link

please retest on latest beta

@david-tejada
Copy link

The issue with Firefox is indeed fixed, at least for me. Thanks!

@nriley
Copy link

nriley commented Jun 25, 2023

My issues are fixed too and I am joyfully removing a whole bunch of workarounds.

Thanks!

@phillco
Copy link
Author

phillco commented Jun 25, 2023

I can confirm:

  • This reproduces on the old version 100%, with the realization that the problem is launching the bad app (IntelliJ/PyCharm for me) after Talon (thanks @david-tejada for the insight; can't believe I never noticed that before)
  • This looks to be fixed for me (for those two apps; presumably, everything else as well) in the latest beta.

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

5 participants