vlc/vlc-2.0 | branch: master | Felix Paul Kühne <[email protected]> | Mon 
Oct 15 13:15:47 2012 +0200| [3f82ec232bf6d840e13c3bd6fa6f692a2d1f2d43] | 
committer: Felix Paul Kühne

macosx: fixed system idle behavior on 10.8

needs forward-port and testing on 10.5

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=3f82ec232bf6d840e13c3bd6fa6f692a2d1f2d43
---

 modules/gui/macosx/CompatibilityFixes.h |    8 ++++++
 modules/gui/macosx/intf.m               |   44 ++++++++++++++++++++++++++-----
 2 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/modules/gui/macosx/CompatibilityFixes.h 
b/modules/gui/macosx/CompatibilityFixes.h
index 70adb8d..62edaa4 100644
--- a/modules/gui/macosx/CompatibilityFixes.h
+++ b/modules/gui/macosx/CompatibilityFixes.h
@@ -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 -
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 74c2676..61a58e9 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -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

_______________________________________________
vlc-commits mailing list
[email protected]
http://mailman.videolan.org/listinfo/vlc-commits

Reply via email to