Main window receives an OnFocus event when a child window closes

Issue Description:
We noticed while testing the changes discussed in Add on-focus event for OW windows that we were receiving OnFocus events in the main window when a child window closes. But the main window is not actually focused.

Attached is a video showing the issue. Notice that the main window’s title bar will turn magenta when we receive an OnFocus event and the console will also print a debug log on focus or blur. At the end of the video, the main window is not the focused window but has gained a focus event.

In our app specifically, we have a child, in-game window that can be opened and closed by the user via hotkeys. Manifest for our in-game window looks like:

"overlay": {
  "transparent": true,
  "desktop_only": false,
  "in_game_only": true,
  "clickthrough": false,
  "mute": true,
  "resizable": true,
  "show_in_taskbar": false,
  "disable_restore_animation": true,
  "keep_window_location": true,
  ...

The issue does not appear to be limited to just in-game child windows though. I confirmed the same issue while testing the above as a desktop window, instead of in-game.

okletsplay-ow-focus-issue.mp4.zip (225.3 KB)

Steps to reproduce:
For our app specifically…

  1. Focus the main window by clicking anywhere in the app.
  2. Change focus to the game (Rocket League) by clicking anywhere in game.
  3. Change focus to the in-game window by clicking anywhere in the overlay window.
  4. Close the window via hotkeys.
  5. Notice that the main window has received an OnFocus event incorrectly.

Impact for my app: [low, mid, high, show-stopper]
High. It’s an annoyance as we depend on focus/blur events to know when the player has returned from a match so we can show a win animation. This is essential to our UX.

Hi @bryan and thanks for your patience.

I followed your steps to reproduce the issue: Instead of using your app, I used our events simulator.
(You disabled the app from working in my region).

I registered for these two events:

window.onfocus = function(){ console.log(":debug OnFocus"); };
window.onblur = function(){ console.log(":debug OnBlur"); };

Everything worked as expected.

Can you please update your version to the developer’s channel and confirm that it’s working as expected with our simulator?

Reproduction of this issue requires a child window to gain focus, thus the base events simulator app does not meet the requirements.

I have reproduced the issue in a modified version of the events simulator with your added focus/blur events. Attached zip contains the following contents:

  • ow-version.png (screenshot of my current OW version, showing latest on Developers)
  • onfocus-issue.mp4 (video showing reproduction in the modified events simulator app)
  • rocket-league-events-sample-app (modified events simulator app to include a child window)

Please follow these reproduction steps with the modified events simulator app:

  1. Prepare the test by opening the modified events simulator app, Rocket League, and the child window. The child window can be opened by pressing tab while in game.
  2. Click within the index window. Notice that the OnFocus event is received correctly.
  3. Click within Rocket League. Notice that the OnBlur event is received correctly.
  4. Click within the child window to gain focus to the child window.
  5. Click the x to close the child window.
  6. Notice that the index window has received the OnFocus event incorrectly.

onfocus-issue.zip (1.7 MB)

@bryan hey,

I’m re-checking this issue again now.
I can still reproduce it, and I opened a bug for the R&D about it.
As it’s an old issue, I want to understand if, meanwhile, you were able to find a workaround it.

Thanks.
Eran.

@bryan, now we are all on the same page, our R&D is going to investigate this issue. But it can take some time. Meanwhile, I want to offer a workaround:

The concept is to identify when you get the “false” OnFocus on your desktop window.

To identify it, you should identify if you get this event on the desktop, AND the game is still in the foreground. If this is the situation - you are in the “false” state.

To identify if your game in the foreground, you can listen to overwolf.games.onGameInfoUpdated. It has the InFocus field that indicates if the game is in focus or not.

As mentioned, if your game is in focus and you got the OnFocus event on your desktop window - you are in a false state.

Another workaround will be to “catch” the close on the in-game window. If immediately after that, you get the OnFocus on the desktop - it means that you are in a false state.

I didn’t test it yet, and maybe you need to tune some details, but that should work.

Please update if it’s clear and make sense.

Thanks.

@bryan I just wanted to update that we deeply investigated this issue.
And currently, except for the workarounds that I suggested, we don’t have any solution.
It’s the behavior of a window that when you close your in-game window, the other window in the same process gains the focus.

Any case if we will have other updates, I will let you know. Thanks.

Eran

Thanks for looking more into the issue. We’ll take your workaround into considering and figure out what works best for us.

It is important to note that this is a standard Windows behaviour - if you open two notepad.exe - select one of them,. then select the other, then close it - it will return focus to the previous window.