aboutsummaryrefslogtreecommitdiff
path: root/src/yuzu/util/macos_sleep.cpp
blob: 7525c37dca09dbecdd58a3e37eee70d3ab2e70f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// SPDX-License-Identifier: GPL-3.0-or-later

#include <IOKit/pwr_mgt/IOPMLib.h>
#include "common/logging.h"
#include "yuzu/util/macos_sleep.h"

namespace MacOS {

u32 PreventSleep() {
    IOPMAssertionID assertion_id = kIOPMNullAssertionID;
    const auto result =
        IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
                                    kIOPMAssertionLevelOn, CFSTR("Running a game"), &assertion_id);
    if (result != kIOReturnSuccess) {
        LOG_WARNING(Frontend, "Failed to prevent display sleep: {}", result);
        return kIOPMNullAssertionID;
    }
    return assertion_id;
}

void AllowSleep(u32 assertion_id) {
    IOPMAssertionRelease(assertion_id);
}

} // namespace MacOS