Created
November 1, 2015 20:26
-
-
Save ahamez/03118d6691e66f0451d8 to your computer and use it in GitHub Desktop.
Programmatically put display to sleep
This file contains hidden or 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
#include <CoreFoundation/CoreFoundation.h> | |
#include <IOKit/IOKitLib.h> | |
// clang++ -framework CoreFoundation -framework IOKIT display_sleep.cc | |
int | |
main() | |
{ | |
const io_registry_entry_t r = | |
IORegistryEntryFromPath( kIOMasterPortDefault | |
, "IOService:/IOResources/IODisplayWrangler"); | |
if (r) | |
{ | |
IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanTrue); | |
IOObjectRelease(r); | |
return 0; | |
} | |
else | |
{ | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment