macosx: replaced deprecated 'UpdateSystemActivity' call with a modern, IOKit-based approach to prevent system sleep (close #6589)

This way, we can also differenciate between screen sleep (for video) and system sleep (for audio)
This commit is contained in:
Felix Paul Kühne 2012-08-24 12:32:14 +02:00
parent b8566bb71d
commit 4a47fcb16f
2 changed files with 23 additions and 9 deletions

View File

@ -41,6 +41,8 @@
#import "misc.h"
#import "MainWindow.h"
#import <IOKit/pwr_mgt/IOPMLib.h> /* for sleep prevention */
/*****************************************************************************
* Local prototypes.
*****************************************************************************/
@ -144,6 +146,9 @@ struct intf_sys_t
SPMediaKeyTap * o_mediaKeyController;
NSArray *o_usedHotkeys;
/* sleep management */
IOPMAssertionID systemSleepAssertionID;
}
+ (VLCMain *)sharedInstance;

View File

@ -1570,15 +1570,6 @@ unsigned int CocoaKeyToVLC( unichar i_key )
- (void)updatePlaybackPosition
{
[o_mainwindow updateTimeSlider];
input_thread_t * p_input;
p_input = pl_CurrentInput( p_intf );
if( p_input )
{
if( var_GetInteger( p_input, "state" ) == PLAYING_S && [self activeVideoPlayback] )
UpdateSystemActivity( UsrActivity );
vlc_object_release( p_input );
}
}
- (void)updateVolume
@ -1614,6 +1605,20 @@ unsigned int CocoaKeyToVLC( unichar i_key )
int state = var_GetInteger( p_input, "state" );
if( state == PLAYING_S )
{
/* prevent the system from sleeping */
IOReturn success;
CFStringRef reasonForActivity= CFStringCreateWithCString( kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8 );
if ( [self activeVideoPlayback] )
success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
else
success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
CFRelease( reasonForActivity );
if (success == kIOReturnSuccess)
msg_Dbg( VLCIntf, "prevented sleep through IOKit (%i)", systemSleepAssertionID);
else
msg_Warn( VLCIntf, "failed to prevent system sleep through IOKit");
[[self mainMenu] setPause];
[o_mainwindow setPause];
}
@ -1623,6 +1628,10 @@ unsigned int CocoaKeyToVLC( unichar i_key )
[o_mainmenu setSubmenusEnabled: FALSE];
[[self mainMenu] setPlay];
[o_mainwindow setPlay];
/* allow the system to sleep again */
msg_Dbg( VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID );
IOPMAssertionRelease( systemSleepAssertionID );
}
vlc_object_release( p_input );
}