Commit 3f82ec23 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: fixed system idle behavior on 10.8

needs forward-port and testing on 10.5
parent 7e02b83e
......@@ -79,6 +79,14 @@ extern OSErr UpdateSystemActivity(UInt8 activity);
@interface NSURL (IntroducedInSnowLeopard)
- (NSArray *)pathComponents;
@end
IOReturn IOPMAssertionCreateWithName( CFStringRef AssertionType,
IOPMAssertionLevel AssertionLevel,
CFStringRef AssertionName,
IOPMAssertionID *AssertionID );
#define kIOPMAssertionTypePreventUserIdleDisplaySleep CFSTR("PreventUserIdleDisplaySleep");
#define kIOPMAssertionTypePreventUserIdleSystemSleep CFSTR("PreventUserIdleSystemSleep");
#endif
#pragma mark -
......
......@@ -1585,15 +1585,38 @@ unsigned int CocoaKeyToVLC( unichar i_key )
p_input = pl_CurrentInput( p_intf );
if( p_input )
{
IOReturn success;
int state = var_GetInteger( p_input, "state" );
if( state == PLAYING_S )
{
/* check for previous blocker and release it if needed */
if (systemSleepAssertionID > 0) {
msg_Dbg( VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID );
success = IOPMAssertionRelease( systemSleepAssertionID );
if (success == kIOReturnSuccess)
systemSleepAssertionID = 0;
}
/* prevent the system from sleeping using the 10.5 API to be as compatible as possible */
IOReturn success;
if ( [self activeVideoPlayback] )
success = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &systemSleepAssertionID);
else
success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &systemSleepAssertionID);
/* work-around a bug in 10.7.4 and 10.7.5, so check for 10.7.x < 10.7.4, 10.8 and 10.6 */
if ((NSAppKitVersionNumber >= 1115.2 && NSAppKitVersionNumber < 1138.45) || OSX_MOUNTAIN_LION) {
CFStringRef reasonForActivity= CFStringCreateWithCString(kCFAllocatorDefault, "VLC media playback", kCFStringEncodingUTF8);
if ([self activeVideoPlayback]) {
NSLog( @"kIOPMAssertionTypePreventUserIdleDisplaySleep" );
success = IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
} else {
NSLog( @"kIOPMAssertionTypePreventUserIdleSystemSleep" );
success = IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleSystemSleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
}
CFRelease(reasonForActivity);
} else {
/* fall-back on the 10.5 mode, which also works on 10.7.4 and 10.7.5 */
if ([self activeVideoPlayback])
success = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &systemSleepAssertionID);
else
success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &systemSleepAssertionID);
}
if (success == kIOReturnSuccess)
msg_Dbg( VLCIntf, "prevented sleep through IOKit (%i)", systemSleepAssertionID);
......@@ -1611,8 +1634,12 @@ unsigned int CocoaKeyToVLC( unichar i_key )
[o_mainwindow setPlay];
/* allow the system to sleep again */
msg_Dbg( VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID );
IOPMAssertionRelease( systemSleepAssertionID );
if (systemSleepAssertionID > 0) {
msg_Dbg( VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID );
success = IOPMAssertionRelease( systemSleepAssertionID );
if (success == kIOReturnSuccess)
systemSleepAssertionID = 0;
}
}
vlc_object_release( p_input );
}
......@@ -1666,11 +1693,14 @@ unsigned int CocoaKeyToVLC( unichar i_key )
- (void)setActiveVideoPlayback:(BOOL)b_value
{
b_active_videoplayback = b_value;
if( o_mainwindow )
{
[o_mainwindow performSelectorOnMainThread:@selector(setVideoplayEnabled) withObject:nil waitUntilDone:YES];
[o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject:nil waitUntilDone:NO];
}
[self performSelectorOnMainThread:@selector(playbackStatusUpdated) withObject:nil waitUntilDone:NO];
}
- (void)setNativeVideoSize:(NSSize)size
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment