Skip to content

Instantly share code, notes, and snippets.

@ahamez
Created November 1, 2015 20:26
Show Gist options
  • Save ahamez/03118d6691e66f0451d8 to your computer and use it in GitHub Desktop.
Save ahamez/03118d6691e66f0451d8 to your computer and use it in GitHub Desktop.
Programmatically put display to sleep
#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