Commit 89ab9f18 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: use a modern system sleep prevention mechanism for the 64bit builds (close #7391)

This is a manual backport of 4a47fcb1. Regrettably, this API was introduced in 10.6 so there is no way to make it work for the legacy 32bit platforms.

The benefit of this approach is that VLC can differenciate between system and screen sleep, so it can allow the system to turn off the screen while playing audio-only media.
parent 970c0c65
......@@ -16,6 +16,9 @@ Mac OS X:
* Deactivate CoreAnimation effects on Leopard
* Fix menus display and behaviour
* Fix various crashes and small issues
* Improve system sleep behavior when playing audio-only media. The screen is
allowed to sleep while the system is kept awake for the play time.
Requires OS X 10.6 or later and a 64bit-capable Mac.
Miscellaneous:
* Fix Notify (D-Bus) plugin deadlock.
......
......@@ -41,6 +41,10 @@
#import "misc.h"
#import "MainWindow.h"
#ifdef __x86_64__
#import <IOKit/pwr_mgt/IOPMLib.h> /* for sleep prevention */
#endif
/*****************************************************************************
* Local prototypes.
*****************************************************************************/
......@@ -146,6 +150,11 @@ struct intf_sys_t
SPMediaKeyTap * o_mediaKeyController;
NSArray *o_usedHotkeys;
#ifdef __x86_64__
/* sleep management */
IOPMAssertionID systemSleepAssertionID;
#endif
}
+ (VLCMain *)sharedInstance;
......
......@@ -1554,6 +1554,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
{
[o_mainwindow updateTimeSlider];
#ifndef __x86_64__
input_thread_t * p_input;
p_input = pl_CurrentInput( p_intf );
if( p_input )
......@@ -1562,6 +1563,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
UpdateSystemActivity( UsrActivity );
vlc_object_release( p_input );
}
#endif
}
- (void)updateVolume
......@@ -1597,6 +1599,22 @@ unsigned int CocoaKeyToVLC( unichar i_key )
int state = var_GetInteger( p_input, "state" );
if( state == PLAYING_S )
{
#ifdef __x86_64__
/* 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");
#endif
[[self mainMenu] setPause];
[o_mainwindow setPause];
}
......@@ -1606,6 +1624,12 @@ unsigned int CocoaKeyToVLC( unichar i_key )
[o_mainmenu setSubmenusEnabled: FALSE];
[[self mainMenu] setPlay];
[o_mainwindow setPlay];
#ifdef __x86_64__
/* allow the system to sleep again */
msg_Dbg( VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID );
IOPMAssertionRelease( systemSleepAssertionID );
#endif
}
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