[Bug 48121] Unity games do not fire OnApplicationFocus/OnApplicationPause events on focus regain

WineHQ Bugzilla wine-bugs at winehq.org
Sat Sep 26 19:11:26 CDT 2020


https://bugs.winehq.org/show_bug.cgi?id=48121

--- Comment #9 from w at zeroitlab.com ---
I looked at this issue again and possible fixes to it. Unfortunately faking a
caption / menu click is not really reliable to do, since neither of those are
guaranteed to exist at all, and even if they do we can't know where they are
located. I tried sending a WM_NCLBUTTONDOWN at 0,0 but it just hung the program
so I didn't bother more with that. I was thinking what else we could do to
follow Windows behavior more correctly. Obvious "fix" would be properly getting
mouse cursor, hittesting, etc.. but that's quite complex, and we'd still have
problems with when people alt-tab or click the caption. So the next best thing
would be simulating some app switch in windows that doesn't have interaction
with the window, like alt-tab. I wrote a simple C++ program to dump events sent
by Windows
(https://zerobin.net/?f96a3d885e1ced60#mGNqn2ultaBbuVNuZrnszC0hWlWau+yhHRGUKa0oCcU=)
and alt-tabbed into it on a Win8 install. Ignoring some irrelevant or
undocumented junk, following events are received by my program:

WM_WINDOWPOSCHANGING    00000000        0050F808        -> 00000000
        lParam: 00000003 (0 0 0 0) 000401BC 000401B6
WM_WINDOWPOSCHANGED     00000000        0050F808        -> 00000000
        lParam: 00001803 (216 466 200 200) 000401BC 000401B6
WM_ACTIVATEAPP          00000001        000008E8        -> 00000000
WM_NCACTIVATE           00000001        00000000        -> 00000001
WM_SETFOCUS             00000000        00000000        -> 00000000
WM_ACTIVATE             00000001        00000000        -> 00000000

So indeed, no WM_MOUSEACTIVATE happens in this case which means this:
https://github.com/wine-mirror/wine/blob/master/dlls/winex11.drv/event.c#L705-L709
can be simply removed and implemented as if it was MA_ACTIVATE at all times
(not simulating clicks would cause regression with click-through windows if
they were supported, but we don't support that anyways) since Windows does this
too.
After changing this, Unity window does detect application focus, however the
window jumps in the middle (this also happens with David's PoC patch). This is
due to the missing WINDOWPOSCHANGING / WINDOWPOSCHANGED. These two are sent in
all cases when a window is activated, so might be better to implement in
set_focus. I ended up sending the messages manually since couldn't quite figure
out how to get SetWindowPos send them (maybe also needs changes).

-- 
Do not reply to this email, post in Bugzilla using the
above URL to reply.
You are receiving this mail because:
You are watching all bug changes.



More information about the wine-bugs mailing list