When WM_STATE is being quickly updated, and depending on the WM we might receive transient focus changes, which will disrupt the Win32 state and make us randomly lose focus.
Ignore them instead, when a window is being shown, and wait for WM_STATE to be updated and stable. We will eventually receive a WM_TAKE_FOCUS / FocusIn event *after* a window has been shown.
When a window is hidden or minimized, we will receive the FocusOut event during the WM_STATE transition, and can safely handle it in this case, as we should have done all the Win32 side effects and have changed the foreground window already.
When there's no window state change pending, the focus change event is unexpected, coming from the user or WM, and we handle it normally.
With the planned asynchronous state changes it will become more likely to receive transient focus events, and we need to ignore any focus change that is expected or known to be superseded.