From c7b21d5bd6cdc803035d97a484160a3d6b4ff32c Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Wed, 4 Jul 2018 13:13:03 -0700 Subject: [PATCH] feat(Metal): Add support to disable display sleep (no screen saver) --- ui/drivers/cocoa/cocoa_common.h | 4 ++++ ui/drivers/ui_cocoa.m | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ui/drivers/cocoa/cocoa_common.h b/ui/drivers/cocoa/cocoa_common.h index 8e0cc1a0dd..a291b769b3 100644 --- a/ui/drivers/cocoa/cocoa_common.h +++ b/ui/drivers/cocoa/cocoa_common.h @@ -60,6 +60,10 @@ typedef enum apple_view_type { /*! @brief setCursorVisible specifies whether the cursor is visible */ - (void)setCursorVisible:(bool)v; +/*! @brief controls whether the screen saver should be disabled and + * the displays should not sleep. + */ +- (bool)setDisableDisplaySleep:(bool)disable; @end extern id apple_platform; diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index 24540d2e70..4070cfe873 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -53,6 +53,8 @@ id apple_platform; NSWindow* _window; apple_view_type_t _vt; NSView* _renderView; + id _sleepActivity; + } @property (nonatomic, retain) NSWindow IBOutlet* window; @@ -337,6 +339,26 @@ static char** waiting_argv; [NSCursor hide]; } +- (bool)setDisableDisplaySleep:(bool)disable +{ +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9 + if (disable && _sleepActivity == nil) + { + _sleepActivity = [NSProcessInfo.processInfo beginActivityWithOptions:NSActivityIdleDisplaySleepDisabled reason:@"disable screen saver"]; + } + else if (!disable && _sleepActivity != nil) + { + [NSProcessInfo.processInfo endActivity:_sleepActivity]; + _sleepActivity = nil; + } + return YES; +#else + return NO; +#endif + +} + + - (void) rarch_main { do