objective c - Programatically check whether monitor is switched off -
mac os x has power saving feature allows os turn off monitor. there api detect in code whether monitor switched on or off?
check out iokit's power management section. http://developer.apple.com/library/mac/#documentation/devicedrivers/conceptual/iokitfundamentals/powermgmt/powermgmt.html#//apple_ref/doc/uid/tp0000020-tpxref104
you might able use ioregistryexplorer , find node state information on setting looking for. there can multiple monitors on mac in different states, have enumerate tree looking nodes class type need.
sleep state handled in iopmrootdomain.cpp in darwin kernel. can probe iokit believe. http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/iokit/kernel/iopmrootdomain.cpp
something like:
mach_port_t masterport; io_registry_entry_t root; kern_return_t kr; boolean_t flag = false; kr = iomasterport(bootstrap_port,&masterport); if ( kioreturnsuccess == kr ) { root = ioregistryentryfrompath(masterport,kiopowerplane ":/iopowerconnection/iopmrootdomain"); if ( root ) { cftyperef data; data = ioregistryentrycreatecfproperty(root,cfstr("iosleepsupported"),kcfallocatordefault,kniloptions); if ( data ) { flag = true; cfrelease(data); } ioobjectrelease(root); } } return flag;
there function in iokit called getpowerstate(). not sure if it's accessible.
hope helps.
Comments
Post a Comment