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

Ken Thomases ken at codeweavers.com
Sun Jul 15 22:26:17 CDT 2018


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>
---
 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 @@ - (void) transformProcessToForeground
 
             [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 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 25832b4..6867c62 100644
--- a/dlls/winemac.drv/macdrv_main.c
+++ b/dlls/winemac.drv/macdrv_main.c
@@ -61,6 +61,7 @@ int gl_surface_mode = GL_SURFACE_IN_FRONT_OPAQUE;
 int retina_enabled = FALSE;
 HMODULE macdrv_module = 0;
 BOOL force_backing_store = FALSE;
+int enable_app_nap = FALSE;
 
 CFDictionaryRef localized_strings;
 
@@ -198,6 +199,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]);
+
     if (!get_config_key(hkey, appkey, "ForceOpenGLBackingStore", buffer, sizeof(buffer)))
         force_backing_store = IS_OPTION_TRUE(buffer[0]);
 
-- 
2.10.2




More information about the wine-devel mailing list