diff options
-rw-r--r-- | xbmc/Application.cpp | 3 | ||||
-rw-r--r-- | xbmc/osx/CocoaInterface.h | 4 | ||||
-rw-r--r-- | xbmc/osx/CocoaInterface.mm | 6 | ||||
-rw-r--r-- | xbmc/windowing/osx/WinSystemOSX.h | 8 | ||||
-rw-r--r-- | xbmc/windowing/osx/WinSystemOSX.mm | 121 |
5 files changed, 76 insertions, 66 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 738b766065..ee01b2f9ba 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -4349,9 +4349,6 @@ void CApplication::ResetScreenSaver() void CApplication::ResetScreenSaverTimer() { -#if defined(__APPLE__) && !defined(__arm__) - Cocoa_UpdateSystemActivity(); -#endif m_screenSaverTimer.StartZero(); } diff --git a/xbmc/osx/CocoaInterface.h b/xbmc/osx/CocoaInterface.h index 776a051a31..59ba4ac714 100644 --- a/xbmc/osx/CocoaInterface.h +++ b/xbmc/osx/CocoaInterface.h @@ -32,10 +32,6 @@ extern "C" { #endif - // Power and Screen - // - void Cocoa_UpdateSystemActivity(void); - // DisplayLink // bool Cocoa_CVDisplayLinkCreate(void *displayLinkcallback, void *displayLinkContext); diff --git a/xbmc/osx/CocoaInterface.mm b/xbmc/osx/CocoaInterface.mm index 9e85f776ad..f2f6267b68 100644 --- a/xbmc/osx/CocoaInterface.mm +++ b/xbmc/osx/CocoaInterface.mm @@ -108,12 +108,6 @@ void Cocoa_SetDisplaySleep(bool enable) } */ -void Cocoa_UpdateSystemActivity(void) -{ - // Original Author: Elan Feingold - UpdateSystemActivity(UsrActivity); -} - bool Cocoa_CVDisplayLinkCreate(void *displayLinkcallback, void *displayLinkContext) { CVReturn status = kCVReturnError; diff --git a/xbmc/windowing/osx/WinSystemOSX.h b/xbmc/windowing/osx/WinSystemOSX.h index 8d1cfae7e1..ebfbe78b62 100644 --- a/xbmc/windowing/osx/WinSystemOSX.h +++ b/xbmc/windowing/osx/WinSystemOSX.h @@ -55,11 +55,12 @@ public: virtual bool Show(bool raise = true); virtual void OnMove(int x, int y); - virtual void Register(IDispResource *resource); - virtual void Unregister(IDispResource *resource); - virtual void EnableSystemScreenSaver(bool bEnable); virtual bool IsSystemScreenSaverEnabled(); + virtual void ResetOSScreensaver(); + + virtual void Register(IDispResource *resource); + virtual void Unregister(IDispResource *resource); virtual int GetNumScreens(); @@ -80,6 +81,7 @@ protected: static void* m_lastOwnedContext; SDL_Surface* m_SDLSurface; CWinEventsOSX *m_osx_events; + bool m_use_system_screensaver; bool m_can_display_switch; void *m_windowDidMove; void *m_windowDidReSize; diff --git a/xbmc/windowing/osx/WinSystemOSX.mm b/xbmc/windowing/osx/WinSystemOSX.mm index ab2539b374..160772ff54 100644 --- a/xbmc/windowing/osx/WinSystemOSX.mm +++ b/xbmc/windowing/osx/WinSystemOSX.mm @@ -43,10 +43,24 @@ #import <Cocoa/Cocoa.h> #import <QuartzCore/QuartzCore.h> +#import <IOKit/pwr_mgt/IOPMLib.h> #import <IOKit/graphics/IOGraphicsLib.h> #import <Carbon/Carbon.h> // ShowMenuBar, HideMenuBar //------------------------------------------------------------------------------------------ +// special object-c class for handling the inhibit display NSTimer callback. +@interface windowInhibitScreenSaverClass : NSObject +- (void) updateSystemActivity: (NSTimer*)timer; +@end + +@implementation windowInhibitScreenSaverClass +-(void) updateSystemActivity: (NSTimer*)timer +{ + UpdateSystemActivity(UsrActivity); +} +@end + +//------------------------------------------------------------------------------------------ // special object-c class for handling the NSWindowDidMoveNotification callback. @interface windowDidMoveNoteClass : NSObject { @@ -442,6 +456,7 @@ CWinSystemOSX::CWinSystemOSX() : CWinSystemBase() m_glContext = 0; m_SDLSurface = NULL; m_osx_events = NULL; + m_use_system_screensaver = true; // check runtime, we only allow this on 10.5+ m_can_display_switch = (floor(NSAppKitVersionNumber) >= 949); } @@ -1231,6 +1246,62 @@ void CWinSystemOSX::OnMove(int x, int y) Cocoa_CVDisplayLinkUpdate(); } +void CWinSystemOSX::EnableSystemScreenSaver(bool bEnable) +{ +#if (MAC_OS_X_VERSION_MAX_ALLOWED < 1050) + // static games because NSTimer is an object-c class and we cannot + // forward declare nor include NSTimer.h in WinSystemOSX.h + static NSTimer *display_tickle; + + if (bEnable) + { + if (display_tickle != NULL) + { + [display_tickle invalidate]; + [display_tickle release]; + display_tickle = NULL; + } + } + else + { + if (display_tickle == NULL) + { + // NSTimer will retain the target until it is released, + // so we do not worry about retaining/releasing it. + windowInhibitScreenSaverClass *inhibitScreenSaver; + inhibitScreenSaver = [[[windowInhibitScreenSaverClass alloc] init] autorelease]; + // schedule every 30 seconds + display_tickle = [NSTimer scheduledTimerWithTimeInterval:30.0 + target:inhibitScreenSaver selector:@selector(updateSystemActivity:) userInfo:nil repeats:YES]; + [display_tickle retain]; + } + } + m_use_system_screensaver = (display_tickle == NULL); +#else + // only present in 10.5 SDK and above + // kIOPMAssertionTypeNoDisplaySleep prevents display idle sleep + static IOPMAssertionID assertionID = 0; + + if (bEnable) + IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &assertionID); + else + IOPMAssertionRelease(assertionID); + + m_use_system_screensaver = bEnable; +#endif +} + +bool CWinSystemOSX::IsSystemScreenSaverEnabled() +{ + return m_use_system_screensaver; +} + +void CWinSystemOSX::ResetOSScreensaver() +{ + // allow os screensaver only if we are fullscreen + EnableSystemScreenSaver(!m_bFullScreen); +} + void CWinSystemOSX::Register(IDispResource *resource) { CSingleLock lock(m_resourceSection); @@ -1264,56 +1335,6 @@ bool CWinSystemOSX::Show(bool raise) return true; } -void CWinSystemOSX::EnableSystemScreenSaver(bool bEnable) -{ -/* not working any more, problems on 10.6 and atv) - if (!g_sysinfo.IsAppleTV() ) - { - NSDictionary* errorDict; - NSAppleScript* scriptObject; - NSAppleEventDescriptor* returnDescriptor; - - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - // If we don't call this, the screen saver will just stop and then start up again. - UpdateSystemActivity(UsrActivity); - - if (bEnable) - { - // tell application id "com.apple.ScreenSaver.Engine" to launch - scriptObject = [[NSAppleScript alloc] initWithSource: - @"launch application \"ScreenSaverEngine\""]; - } - else - { - // tell application id "com.apple.ScreenSaver.Engine" to quit - scriptObject = [[NSAppleScript alloc] initWithSource: - @"tell application \"ScreenSaverEngine\" to quit"]; - } - returnDescriptor = [scriptObject executeAndReturnError: &errorDict]; - [scriptObject release]; - - [pool release]; - } -*/ -} - -bool CWinSystemOSX::IsSystemScreenSaverEnabled() -{ - bool sss_enabled = false; -/* - if (g_sysinfo.IsAppleTV() ) - { - sss_enabled = false; - } - else - { - sss_enabled = g_xbmcHelper.GetProcessPid("ScreenSaverEngine") != -1; - } -*/ - return(sss_enabled); -} - int CWinSystemOSX::GetNumScreens() { int numDisplays = [[NSScreen screens] count]; |