-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2988 from MartinZikmund/dev/mazi/displayrequest-m…
…acos feat(DisplayRequest): macOS support
- Loading branch information
Showing
4 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using CoreFoundation; | ||
|
||
namespace Uno.Helpers | ||
{ | ||
internal static class IOKit | ||
{ | ||
private const string IOKitLibrary = "/System/Library/Frameworks/IOKit.framework/IOKit"; | ||
private const uint kIOPMAssertionLevelOn = 255; | ||
|
||
private static readonly CFString kIOPMAssertionTypePreventUserIdleDisplaySleep = "PreventUserIdleDisplaySleep"; | ||
|
||
[DllImport(IOKitLibrary)] | ||
static extern uint IOPMAssertionCreateWithName(IntPtr type, uint level, IntPtr name, out uint id); | ||
|
||
[DllImport(IOKitLibrary)] | ||
static extern uint IOPMAssertionRelease(uint id); | ||
|
||
internal static bool PreventUserIdleDisplaySleep(CFString name, out uint id) | ||
{ | ||
var result = IOPMAssertionCreateWithName( | ||
kIOPMAssertionTypePreventUserIdleDisplaySleep.Handle, | ||
kIOPMAssertionLevelOn, | ||
name.Handle, | ||
out var newId); | ||
|
||
id = result == 0 ? newId : 0; | ||
|
||
return result == 0; | ||
} | ||
|
||
internal static bool AllowUserIdleDisplaySleep(uint id) | ||
{ | ||
var result = IOPMAssertionRelease(id); | ||
return result == 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#if __MACOS__ | ||
using Uno.Helpers; | ||
|
||
namespace Windows.System.Display | ||
{ | ||
public partial class DisplayRequest | ||
{ | ||
private uint _displayRequestId; | ||
|
||
partial void ActivateScreenLock() | ||
{ | ||
IOKit.PreventUserIdleDisplaySleep("DisplayRequest", out _displayRequestId); | ||
} | ||
|
||
partial void DeactivateScreenLock() | ||
{ | ||
IOKit.AllowUserIdleDisplaySleep(_displayRequestId); | ||
} | ||
} | ||
} | ||
#endif |