Commit 4a47fcb1 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: replaced deprecated 'UpdateSystemActivity' call with a modern,...

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)
parent b8566bb7
......@@ -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;
......
......@@ -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 );
}
......
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