Ken Thomases : winemac: Disable macOS' s App Nap energy-saving feature by default for Wine GUI processes.

Alexandre Julliard julliard at winehq.org
Mon Jul 16 14:40:00 CDT 2018


Module: wine
Branch: master
Commit: 250944b64304ee85d92955d2a901268ab08b720e
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=250944b64304ee85d92955d2a901268ab08b720e

Author: Ken Thomases <ken at codeweavers.com>
Date:   Sun Jul 15 22:54:15 2018 -0500

winemac: Disable macOS's App Nap energy-saving feature by default for Wine GUI processes.

App Nap defers timer firings and I/O if the app is not visibly or audibly
updating.  An app is supposed to disable it during user-requested or background
activity, but we can't know when the Windows app is engaged in such.  Since it's
not generally acceptable for timers or IO to be deferred, we have to disable it
at all times.

The user can re-enable it by setting the following registry setting:

[HKEY\Software\Wine\Mac Driver]
"EnableAppNap"="y"

Signed-off-by: Ken Thomases <ken at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winemac.drv/cocoa_app.m    | 7 +++++++
 dlls/winemac.drv/macdrv_cocoa.h | 1 +
 dlls/winemac.drv/macdrv_main.c  | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m
index 239c11f..efbd657 100644
--- a/dlls/winemac.drv/cocoa_app.m
+++ b/dlls/winemac.drv/cocoa_app.m
@@ -235,6 +235,13 @@ static NSString* WineLocalizedString(unsigned int stringID)
 
             [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
             [NSApp activateIgnoringOtherApps: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
 
             mainMenu = [[[NSMenu alloc] init] autorelease];
 
diff --git a/dlls/winemac.drv/macdrv_cocoa.h b/dlls/winemac.drv/macdrv_cocoa.h
index acab5df..6bad790 100644
--- a/dlls/winemac.drv/macdrv_cocoa.h
+++ b/dlls/winemac.drv/macdrv_cocoa.h
@@ -166,6 +166,7 @@ extern int gl_surface_mode DECLSPEC_HIDDEN;
 extern CFDictionaryRef localized_strings DECLSPEC_HIDDEN;
 extern int retina_enabled DECLSPEC_HIDDEN;  /* Whether Retina mode is enabled via registry setting. */
 extern int retina_on DECLSPEC_HIDDEN;       /* Whether Retina mode is currently active (enabled and display is in default mode). */
+extern int enable_app_nap DECLSPEC_HIDDEN;
 
 static inline CGRect cgrect_mac_from_win(CGRect rect)
 {
diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c
index 491ab06..4bd7411 100644
--- a/dlls/winemac.drv/macdrv_main.c
+++ b/dlls/winemac.drv/macdrv_main.c
@@ -60,6 +60,7 @@ int use_precise_scrolling = TRUE;
 int gl_surface_mode = GL_SURFACE_IN_FRONT_OPAQUE;
 int retina_enabled = FALSE;
 HMODULE macdrv_module = 0;
+int enable_app_nap = FALSE;
 
 CFDictionaryRef localized_strings;
 
@@ -197,6 +198,9 @@ static void setup_options(void)
             gl_surface_mode = GL_SURFACE_IN_FRONT_OPAQUE;
     }
 
+    if (!get_config_key(hkey, appkey, "EnableAppNap", buffer, sizeof(buffer)))
+        enable_app_nap = IS_OPTION_TRUE(buffer[0]);
+
     /* Don't use appkey.  The DPI and monitor sizes should be consistent for all
        processes in the prefix. */
     if (!get_config_key(hkey, NULL, "RetinaMode", buffer, sizeof(buffer)))




More information about the wine-cvs mailing list