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

Felix Paul Kühne git at videolan.org
Fri Aug 24 12:32:26 CEST 2012


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Fri Aug 24 12:32:14 2012 +0200| [4a47fcb16f3f06268a1f1cf0f14f85491cc907ec] | committer: Felix Paul Kühne

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)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4a47fcb16f3f06268a1f1cf0f14f85491cc907ec
---

 modules/gui/macosx/intf.h |    5 +++++
 modules/gui/macosx/intf.m |   27 ++++++++++++++++++---------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h
index a7553cf..7064b91 100644
--- a/modules/gui/macosx/intf.h
+++ b/modules/gui/macosx/intf.h
@@ -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;
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index ffc9528..d12af90 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -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 );
     }



More information about the vlc-commits mailing list