Last active
May 13, 2016 05:16
-
-
Save S2Ler/ede3626405764ef854d6 to your computer and use it in GitHub Desktop.
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
bool isLidClosed(void) | |
{ | |
bool isClosed = false; | |
io_registry_entry_t rootDomain; | |
mach_port_t masterPort; | |
CFTypeRef clamShellStateRef = NULL; | |
// Retrieve the IOKit's master port so a notification port can be created | |
IOReturn ioReturn = IOMasterPort(MACH_PORT_NULL, &masterPort); | |
// Check to see if the "AppleClamshellClosed" property is in the PM root domain: | |
rootDomain = IORegistryEntryFromPath(masterPort, kIOPowerPlane ":/IOPowerConnection/IOPMrootDomain"); | |
clamShellStateRef = IORegistryEntryCreateCFProperty( rootDomain,CFSTR(kAppleClamshellStateKey), kCFAllocatorDefault, 0); | |
if (clamShellStateRef == NULL) | |
{ | |
if ( rootDomain ) | |
IOObjectRelease(rootDomain); | |
ioReturn = kIOReturnNoResources; | |
} | |
if ( CFBooleanGetValue( (CFBooleanRef)(clamShellStateRef) ) == true ) | |
{ | |
printf("closed!\n"); | |
isClosed = true; | |
} | |
if ( rootDomain ) | |
IOObjectRelease(rootDomain); | |
if (clamShellStateRef) | |
CFRelease(clamShellStateRef); | |
return isClosed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment