From: Tim Clem tclem@codeweavers.com
-transformProcessToForeground: and -tryToActivateIgnoringOtherApps: are effectively a pair. Moreover -transformProcess does some work (handling App Nap and sometimes activating the app) that we may want to happen regardless of whether the app has a dock icon.
-appDidShowUIAndShouldActivate:dockIconAction: consolidates all that logic, and makes the intended behavior by callers more clear. -tryToActivateIgnoringOtherApps: is no longer exposed in the header. --- dlls/winemac.drv/cocoa_app.h | 10 ++++++++-- dlls/winemac.drv/cocoa_app.m | 28 ++++++++++++++-------------- dlls/winemac.drv/cocoa_window.m | 20 ++++++++++++-------- 3 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/dlls/winemac.drv/cocoa_app.h b/dlls/winemac.drv/cocoa_app.h index d51dca2f2e3..b33e2f43e8d 100644 --- a/dlls/winemac.drv/cocoa_app.h +++ b/dlls/winemac.drv/cocoa_app.h @@ -66,6 +66,12 @@ WineApplicationEventWakeQuery, };
+typedef enum { + WineApplicationDockIconActionHide, + WineApplicationDockIconActionShow, + WineApplicationDockIconActionNoChange +} WineApplicationDockIconAction; +
@class WineEventQueue; @class WineWindow; @@ -144,8 +150,8 @@ @interface WineApplicationController : NSObject <NSApplicationDelegate>
+ (WineApplicationController*) sharedController;
- - (void) transformProcessToForeground:(BOOL)activateIfTransformed; - - (void) tryToActivateIgnoringOtherApps:(BOOL)ignore; + - (void) appDidShowUIAndShouldActivate:(BOOL)activate + dockIconAction:(WineApplicationDockIconAction)dockIconAction;
- (BOOL) registerEventQueue:(WineEventQueue*)queue; - (void) unregisterEventQueue:(WineEventQueue*)queue; diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m index dd9ae15ab15..cf0759d0310 100644 --- a/dlls/winemac.drv/cocoa_app.m +++ b/dlls/winemac.drv/cocoa_app.m @@ -369,25 +369,25 @@ - (void) showDockIcon:(BOOL)show } }
- - (void) transformProcessToForeground:(BOOL)activateIfTransformed + - (void) appDidShowUIAndShouldActivate:(BOOL)activate + dockIconAction:(WineApplicationDockIconAction)dockIconAction; { - /* activationPolicy may not be exactly accurate if there's a pending - hide/show of the dock icon, but it's not a big deal here. */ - if ([NSApp activationPolicy] != NSApplicationActivationPolicyRegular) + if (dockIconAction != WineApplicationDockIconActionNoChange) { - [self showDockIcon:YES]; + [self showDockIcon:dockIconAction == WineApplicationDockIconActionShow + andActivate:activate]; + }
- if (activateIfTransformed) - [self tryToActivateIgnoringOtherApps:YES]; + if (activate) + [self tryToActivateIgnoringOtherApps:YES];
#if defined(MAC_OS_X_VERSION_10_9) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 - if (!enable_app_nap && [NSProcessInfo instancesRespondToSelector:@selector(beginActivityWithOptions:reason:)]) - { - [[[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityUserInitiatedAllowingIdleSystemSleep - reason:@"Running Windows program"] retain]; // intentional leak - } -#endif + if (!enable_app_nap && [NSProcessInfo instancesRespondToSelector:@selector(beginActivityWithOptions:reason:)]) + { + [[[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityUserInitiatedAllowingIdleSystemSleep + reason:@"Running Windows program"] retain]; // intentional leak } +#endif }
- (BOOL) waitUntilQueryDone:(int*)done timeout:(NSDate*)timeout processEvents:(BOOL)processEvents @@ -948,7 +948,7 @@ - (BOOL) setMode:(CGDisplayModeRef)mode forDisplay:(CGDirectDisplayID)displayID if (!modes.count) return FALSE;
- [self transformProcessToForeground:YES]; + [self appDidShowUIAndShouldActivate:YES dockIconAction:WineApplicationDockIconActionShow];
BOOL active = [NSApp isActive];
diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m index 2358cc70118..112bfe6fb76 100644 --- a/dlls/winemac.drv/cocoa_window.m +++ b/dlls/winemac.drv/cocoa_window.m @@ -1239,7 +1239,8 @@ - (void) setWindowFeatures:(const struct macdrv_window_features*)wf if (neededDockIcon && !needsDockIcon) [[WineApplicationController sharedController] maybeHideDockIconDueToWindowOrderingOut:nil]; else if(!neededDockIcon && needsDockIcon) - [[WineApplicationController sharedController] transformProcessToForeground:!self.preventsAppActivation]; + [[WineApplicationController sharedController] appDidShowUIAndShouldActivate:!self.preventsAppActivation + dockIconAction:WineApplicationDockIconActionShow]; } }
@@ -1753,15 +1754,16 @@ - (void) orderBelow:(WineWindow*)prev orAbove:(WineWindow*)next forceActivate:(B WineWindow* child;
if (!eager_dock_icon_hiding || self.needsDockIcon) - [controller transformProcessToForeground:!self.preventsAppActivation]; + [controller appDidShowUIAndShouldActivate:activate || !self.preventsAppActivation + dockIconAction:WineApplicationDockIconActionShow]; + else + [controller appDidShowUIAndShouldActivate:activate || !self.preventsAppActivation + dockIconAction:WineApplicationDockIconActionNoChange];
if ([NSApp isHidden]) [NSApp unhide:nil]; wasVisible = [self isVisible];
- if (activate) - [controller tryToActivateIgnoringOtherApps:YES]; - NSDisableScreenUpdates();
if ([self becameEligibleParentOrChild]) @@ -2127,9 +2129,11 @@ - (void) makeFocused:(BOOL)activate WineApplicationController *controller = [WineApplicationController sharedController];
if (!eager_dock_icon_hiding || self.needsDockIcon) - [controller transformProcessToForeground:YES]; - - [controller tryToActivateIgnoringOtherApps:YES]; + [controller appDidShowUIAndShouldActivate:activate + dockIconAction:WineApplicationDockIconActionShow]; + else + [controller appDidShowUIAndShouldActivate:activate + dockIconAction:WineApplicationDockIconActionNoChange]; }
causing_becomeKeyWindow = self;