From d22ac28f5e257cd0eb302322f2c039d124871cad Mon Sep 17 00:00:00 2001
From: Ken Thomases <ken@codeweavers.com>
Date: Fri, 7 Jun 2013 04:26:33 -0500
Subject: [PATCH] winemac: Allow clicks on owned windows to reorder them
 relative to other owned windows of the same owner.

---
 dlls/winemac.drv/cocoa_app.m | 42 ++++++++++++++++++++++++++++++++----
 1 file changed, 38 insertions(+), 4 deletions(-)

diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m
index fe9648b069c..fd481e533db 100644
--- a/dlls/winemac.drv/cocoa_app.m
+++ b/dlls/winemac.drv/cocoa_app.m
@@ -1424,16 +1424,50 @@ - (void) handleMouseMove:(NSEvent*)anEvent
 
     - (void) handleMouseButton:(NSEvent*)theEvent
     {
-        WineWindow* window;
+        WineWindow* window = (WineWindow*)[theEvent window];
+        NSEventType type = [theEvent type];
+
+        if ([window isKindOfClass:[WineWindow class]] &&
+            type == NSLeftMouseDown &&
+            (([theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask| NSAlternateKeyMask | NSCommandKeyMask)) != NSCommandKeyMask))
+        {
+            NSWindowButton windowButton;
+            BOOL broughtWindowForward = TRUE;
+
+            /* Any left-click on our window anyplace other than the close or
+               minimize buttons will bring it forward. */
+            for (windowButton = NSWindowCloseButton;
+                 windowButton <= NSWindowMiniaturizeButton;
+                 windowButton++)
+            {
+                NSButton* button = [window standardWindowButton:windowButton];
+                if (button)
+                {
+                    NSPoint point = [button convertPoint:[theEvent locationInWindow] fromView:nil];
+                    if ([button mouse:point inRect:[button bounds]])
+                    {
+                        broughtWindowForward = FALSE;
+                        break;
+                    }
+                }
+            }
+
+            if (broughtWindowForward)
+            {
+                // Clicking on a child window does not normally reorder it with
+                // respect to its siblings, but we want it to.  We have to do it
+                // manually.
+                NSWindow* parent = [window parentWindow];
+                [parent removeChildWindow:window];
+                [parent addChildWindow:window ordered:NSWindowAbove];
+            }
+        }
 
         if (mouseCaptureWindow)
             window = mouseCaptureWindow;
-        else
-            window = (WineWindow*)[theEvent window];
 
         if ([window isKindOfClass:[WineWindow class]])
         {
-            NSEventType type = [theEvent type];
             BOOL pressed = (type == NSLeftMouseDown || type == NSRightMouseDown || type == NSOtherMouseDown);
             CGPoint pt = CGEventGetLocation([theEvent CGEvent]);
             BOOL process;
-- 
GitLab