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); ...@@ -79,6 +79,14 @@ extern OSErr UpdateSystemActivity(UInt8 activity);
@interface NSURL (IntroducedInSnowLeopard) @interface NSURL (IntroducedInSnowLeopard)
- (NSArray *)pathComponents; - (NSArray *)pathComponents;
@end @end
IOReturn IOPMAssertionCreateWithName( CFStringRef AssertionType,
IOPMAssertionLevel AssertionLevel,
CFStringRef AssertionName,
IOPMAssertionID *AssertionID );
#define kIOPMAssertionTypePreventUserIdleDisplaySleep CFSTR("PreventUserIdleDisplaySleep");
#define kIOPMAssertionTypePreventUserIdleSystemSleep CFSTR("PreventUserIdleSystemSleep");
#endif #endif
#pragma mark - #pragma mark -
......
...@@ -1585,15 +1585,38 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1585,15 +1585,38 @@ unsigned int CocoaKeyToVLC( unichar i_key )
p_input = pl_CurrentInput( p_intf ); p_input = pl_CurrentInput( p_intf );
if( p_input ) if( p_input )
{ {
IOReturn success;
int state = var_GetInteger( p_input, "state" ); int state = var_GetInteger( p_input, "state" );
if( state == PLAYING_S ) 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 */ /* prevent the system from sleeping using the 10.5 API to be as compatible as possible */
IOReturn success; /* 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 ( [self activeVideoPlayback] ) if ((NSAppKitVersionNumber >= 1115.2 && NSAppKitVersionNumber < 1138.45) || OSX_MOUNTAIN_LION) {
success = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &systemSleepAssertionID); CFStringRef reasonForActivity= CFStringCreateWithCString(kCFAllocatorDefault, "VLC media playback", kCFStringEncodingUTF8);
else if ([self activeVideoPlayback]) {
success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &systemSleepAssertionID); 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) if (success == kIOReturnSuccess)
msg_Dbg( VLCIntf, "prevented sleep through IOKit (%i)", systemSleepAssertionID); msg_Dbg( VLCIntf, "prevented sleep through IOKit (%i)", systemSleepAssertionID);
...@@ -1611,8 +1634,12 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1611,8 +1634,12 @@ unsigned int CocoaKeyToVLC( unichar i_key )
[o_mainwindow setPlay]; [o_mainwindow setPlay];
/* allow the system to sleep again */ /* allow the system to sleep again */
msg_Dbg( VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID ); if (systemSleepAssertionID > 0) {
IOPMAssertionRelease( systemSleepAssertionID ); msg_Dbg( VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID );
success = IOPMAssertionRelease( systemSleepAssertionID );
if (success == kIOReturnSuccess)
systemSleepAssertionID = 0;
}
} }
vlc_object_release( p_input ); vlc_object_release( p_input );
} }
...@@ -1666,11 +1693,14 @@ unsigned int CocoaKeyToVLC( unichar i_key ) ...@@ -1666,11 +1693,14 @@ unsigned int CocoaKeyToVLC( unichar i_key )
- (void)setActiveVideoPlayback:(BOOL)b_value - (void)setActiveVideoPlayback:(BOOL)b_value
{ {
b_active_videoplayback = b_value; b_active_videoplayback = b_value;
if( o_mainwindow ) if( o_mainwindow )
{ {
[o_mainwindow performSelectorOnMainThread:@selector(setVideoplayEnabled) withObject:nil waitUntilDone:YES]; [o_mainwindow performSelectorOnMainThread:@selector(setVideoplayEnabled) withObject:nil waitUntilDone:YES];
[o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject:nil waitUntilDone:NO]; [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject:nil waitUntilDone:NO];
} }
[self performSelectorOnMainThread:@selector(playbackStatusUpdated) withObject:nil waitUntilDone:NO];
} }
- (void)setNativeVideoSize:(NSSize)size - (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