"Focused Window Did Change" issue

Installed BTT 4,356 and Ventura 13.6.3 on macbook pro m1 max.

The new trigger "Focused Window Did Change" works perfectly, except when I switch the focus from an app with an opened window to another app without any window.

I have tested this scenario using Finder and Chrome:
1- Finder has zero windows
2-Chrome has 1 window opened
3- Going from Finder to Chrome is detected by the trigger
4- Going from Chrome to Finder is NOT detected by the trigger

And also this scenario using Finder and TextEdit:
1- TextEdit has zero windows
2-Finder has 1 window opened
3- Going from Finder to TextEdit is NOT detected by the trigger
4- Going from TextEdit to Finder is NOT detected by the trigger

It would be necessary to detect when the focus goes from an exisiting window to an unexisting window.

So in your case no window would be focused? I think I should be able to add an option to detect that.

Yes, something happens when an app has no opened windows.

Here are 2 short videos of the scenarios described before:

There is also a similar issue when an app is minimizing windows.

Here is a video example using 2 windows in Finder and TextEdit.

Sometimes the trigger is not detecting when a window is minimized.

And also the trigger is not detecting when all windows are minimized in both applications and the focus changes from TextEdit to Finder (when the focus changes from Finder to TextEdit it's detected correctly).

yep, currently the trigger only detects if there is a new focused window. If there is no focused window it doesn't trigger. (This was intended to only trigger of windows, but I will add an option to always trigger)

Thanks, the addition will be great.

Take in consideration that now the trigger is detecting no windows sometimes, as the example of my last video when all windows are minimized.

I just want to remark that, when there is a change to apps with zero windows or all windows minimized, it seems the detection has inconsistencies.

in your last example there was no focused window (window buttons gray), or is it just not visible on the screen capture?

The screen capture is showing all windows.

The 2 upper windows are TextEdit windows.

The 2 lower windows are Finder windows.

When these 4 windows are minimized, changing from Finder to Text Edit is detected as a "Focused Window Did Change".

But in the same situation (the 4 windows are minimized) , changing from TextEdit to Finder is not detected as a "Focused Window Did Change".

You can see this behaviour at the end of the last video.

That's the reason I said that it seems to happen some inconsistency.

sorry I just noticed the two different apps. MacOS only auto-changes focus as long as there are other windows of the same app. I think this explains the behavior you are seeing. You‘ll probably also see that the menubar still shows Textedit as active app

I have done another video, showing the menubar.

I am using 1 window in Finder and 1 window in TextEdit in the video, and I minimize both windows pressing cmd+M, and switching between these two apps pressing cmd+tab.

You can see that the menubar is changing correctly the name of the front app, and the trigger "Focused Window Did Change" is detecting a change when focus goes from Finder to TextEdit, but not detecting any change when focus goes in the inverse direction.

Also you can see at the beginning that when I minimize the Finder window, the trigger detects the change of focused window. When I minimize the TextEdit window, the trigger doesn't detect the change.

Ah that's indeed weird. Seems like some windows don't send out the notifications when being minimized.

I have added some more listeners in v 4.358 alpha (uploading now), however this probably still doesn't catch all situations. If I find ways to detect those I'll add them!

Downloaded v4,361

Now the trigger is always detecting when a window is minimized, so that's working correctly.

Now there are only 2 situations where the trigger sometimes works, sometimes fails:

1- When the last window of an application is closed, and the application remains opened with zero windows (as example, Finder is detecting it, TextEdit is not detecting it)

2- When the focus changes from an application to another application without visible windows (zero window or all windows minimized). This has been commented previously in this thread.

Some ideas for both:

1- Maybe add a listener for any change in the title of the focused window? If the title is "" or missing value, then execute the action. This could be managed with a checkbox in the trigger, something like "Execute actions when there is no window focused".

2- Maybe you could "mix" the detection of the trigger "Active App Did Change" inside the trigger "Focused Window Did Change" (because when the front app changes, it will always change also the focused window, isn't it?). This could be also managed with a checkbox in the trigger, something like "Always trigger when frontmost application changes".

Unfortunately the system doesn't offer such a general notification I could listen to. I could only achieve this by polling, which would constantly hit the CPU.

Ah these are already mixed, but maybe I forgot the "both apps without windows" case, I'll have a look!

It happens in the case of "both apps without windows", but also in the case of "app with windows to app without windows".

Let's take:

  • Chrome with 1 visible window
  • Finder with 0 windows (or 1 minimized window)
  • TextEdit with 0 windows (or 1 minimized window)

Results:

:white_check_mark: Going from Chrome to Finder is detected.

:x: Going from Chrome to TextEdit is not detected.

:x: Going from TextEdit to Finder is not detected.

:white_check_mark: Going from Finder to TextEdit is detected.

It is very weird for me, because depending on the previous app, the detection works or fails. Hope you can understand it! :grinning:

yep it's confusing, unfortunately all this stuff is based on ancient system notifications that are implemented differently by the various apps - depending on which technology they are based and what window types they use.

Thanks for testing this stuff, that definitely helps! I plan to add more options to the trigger as well, e.g. to exclude dialogs/alerts/modal windows.

1 Like