When updating the foreground window, even if both the old and new active window belong to the same non-current thread, the win32u code currently explicitly deactivates the old window. This will cause the transient deactivation of the foreground thread which can lead to undesirable side-effects (e.g., some apps may minimize when they become inactive).
Until this is fixed in Wine core, use an internal driver message to ensure that we call NtUserSetForegroundWindow from the context of the new foreground window thread, to avoid the problematic behavior.
---
Assuming that the aforementioned NtUserSetForegroundWindow behavior is indeed incorrect, this should ideally be addressed in win32u, perhaps along the lines of https://gitlab.winehq.org/wine/wine/-/merge_requests/4593/diffs?commit_id=f6....
However, given the time of year (freeze etc), the proposed mitigation is possibly a safer choice at this point for Wine.