Skip to content

Commit

Permalink
Prevent display sleep while game is running on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Jul 8, 2024
1 parent 01d0704 commit e8c3845
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ target_link_libraries(
CURL::libcurl
"$<$<PLATFORM_ID:Darwin>:-framework Cocoa>"
"$<$<PLATFORM_ID:Darwin>:-framework QuartzCore>"
"$<$<PLATFORM_ID:Darwin>:-framework IOKit>"
)
target_include_directories(plClient PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")

Expand Down
12 changes: 12 additions & 0 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#import <Metal/Metal.h>
#endif
#import <QuartzCore/QuartzCore.h>
#import <IOKit/pwr_mgt/IOPMLib.h>

// Cocoa client
#import "NSString+StringTheory.h"
Expand All @@ -64,6 +65,7 @@
#include <unordered_set>

// Plasma engine
#include "hsDarwin.h"
#include "plClient/plClient.h"
#include "plClient/plClientLoader.h"
#include "plCmdParser.h"
Expand Down Expand Up @@ -478,6 +480,16 @@ - (void)startClient
((PLSView*)self.window.contentView).inputManager = gClient->GetInputManager();
[self.window makeFirstResponder:self.window.contentView];

IOPMAssertionID assertionID = 0;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
IOReturn result = IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep, kIOPMAssertionLevelOn, CFStringCreateWithSTString(plProduct::LongName()), &assertionID);
#else
IOReturn result = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &assertionID);
#endif
if (result != kIOReturnSuccess) {
hsStatusMessage("Failed to acquire idle prevention assertion");
}

// Main loop
if (gClient && !gClient->GetDone()) {
[self startRunLoop];
Expand Down

0 comments on commit e8c3845

Please sign in to comment.