How do I wake from display sleep in OSX 10.7.4?

纵饮孤独 提交于 2019-12-29 08:12:39

问题


In the most recent version of OSX Lion, how do you wake up the machine from display sleep? This is in response to network activity.

In 10.7.3 this was possible with the following call:

IOPMAssertionID id = 0;
IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
                            kIOPMAssertionLevelOn, reason, &id)

However, this does not work in 10.7.4. What can be done instead?


回答1:


I have not yet tested the performance implications nor the interaction with the idle timer itself, but:

io_registry_entry_t regEntry = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
if (regEntry != MACH_PORT_NULL) {
        IORegistryEntrySetCFProperty(regEntry, CFSTR("IORequestIdle"), kCFBooleanFalse);
        IOObjectRelease(regEntry);
}

works in 10.7.4 to wake the screen from idle.




回答2:


It appears from the docs that the way to "wake up" the display these days is:

IOPMAssertionID assertionID2;
IOPMAssertionDeclareUserActivity(CFSTR("Your reasoning"),
       kIOPMUserActiveLocal, &assertionID2);

The IOPMAssertionCreateWithName(...) way from original the question only "prevents display going to sleep" if it's already on (though it does work and can also be used to prevent it from going to sleep for a duration of time).

The way the docs method for "keeping" the display on works about the same way as IOPMAssertionCreateWithName

IOPMAssertionID m_disableDisplaySleepAssertion;    
IOReturn success2 = IOPMAssertionCreateWithDescription(
  kIOPMAssertionTypePreventUserIdleDisplaySleep, reasonForActivity, NULL, NULL, NULL, 0, NULL, &m_disableDisplaySleepAssertion); 
if (success2 == kIOReturnSuccess) {
    // screen will stay on, do you work
    success = IOPMAssertionRelease(m_disableDisplaySleepAssertion);
}

If you want to "turn it on and keep it on forever" then IOPMAssertionDeclareUserActivity followed by the above, or just call IOPMAssertionDeclareUserActivity over and over again somehow.

You could also call out to the caffeinate command line utility I suppose :)



来源:https://stackoverflow.com/questions/10598809/how-do-i-wake-from-display-sleep-in-osx-10-7-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!