[PATCH 2/3] macdrv: Fix applications failing to gain or lose focus.

Elaine Lefler elaineclefler at gmail.com
Tue Mar 22 20:31:50 CDT 2022


Wine apps no longer accept the first mouse click when the application
is inactive. This mirrors the expected behavior of Mac apps and
prevents a bug where focus is never received.

Call SetActiveWindow(NULL) on deactivate to prevent a bug where focus
is never lost.

Signed-off-by: Elaine Lefler <elaineclefler at gmail.com>
---

Normally I would put the mouse-down behavior under a toggle, but the
window focus really is broken without it. I'm not sure why, Wine seems
to be doing everything right, but the message gets eaten somewhere
between the Mac side and the Windows side and this is the only way to
fix it.

Most users should find this behavior preferable, as the vast majority
of Mac apps do the same thing, and it's annoying when an application
registers a click that you expected it to ignore.
---
 dlls/winemac.drv/cocoa_app.m | 9 ++++++---
 dlls/winemac.drv/window.c    | 1 +
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m
index b5a3059382e..8c525333e8d 100644
--- a/dlls/winemac.drv/cocoa_app.m
+++ b/dlls/winemac.drv/cocoa_app.m
@@ -1524,15 +1524,18 @@ - (void) handleMouseButton:(NSEvent*)theEvent
             {
                 if (mouseCaptureWindow)
                     process = TRUE;
-                else
+                /* Don't deliver mouse-down to an application that isn't active.
+                 * This mirrors macOS's behavior and delivering the mouse event
+                 * before activate can make the window fail to receive focus. */
+                else if ([[NSApplication sharedApplication] isActive])
                 {
-                    // Test if the click was in the window's content area.
+                    /* Test if the click was in the window's content area. */
                     NSPoint nspoint = [self flippedMouseLocation:NSPointFromCGPoint(pt)];
                     NSRect contentRect = [window contentRectForFrameRect:[window frame]];
                     process = NSMouseInRect(nspoint, contentRect, NO);
                     if (process && [window styleMask] & NSWindowStyleMaskResizable)
                     {
-                        // Ignore clicks in the grow box (resize widget).
+                        /* Ignore clicks in the grow box (resize widget). */
                         HIPoint origin = { 0, 0 };
                         HIThemeGrowBoxDrawInfo info = { 0 };
                         HIRect bounds;
diff --git a/dlls/winemac.drv/window.c b/dlls/winemac.drv/window.c
index 4f3dbc08311..9177f493a5f 100644
--- a/dlls/winemac.drv/window.c
+++ b/dlls/winemac.drv/window.c
@@ -2415,6 +2415,7 @@ void macdrv_app_deactivated(void)
         TRACE("setting fg to desktop\n");
         SetForegroundWindow(GetDesktopWindow());
     }
+    SetActiveWindow(NULL);
 }
 
 
-- 
2.32.0 (Apple Git-132)




More information about the wine-devel mailing list