From a1624540184856b96aadec5b233f1661834121ca Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Wed, 27 Jul 2011 11:54:06 +0000 Subject: [PATCH] SCR: Fix delay dismissing screensaver under Mac OS10.7 svn path=/branches/boinc_core_release_6_12/; revision=23885 --- checkin_notes | 11 ++++++++ clientscr/Mac_Saver_Module.h | 1 + clientscr/Mac_Saver_ModuleView.h | 1 + clientscr/Mac_Saver_ModuleView.m | 32 +++++++++++++++++++++++ clientscr/mac_saver_module.cpp | 14 +++++----- mac_build/boinc.xcodeproj/project.pbxproj | 2 ++ 6 files changed, 53 insertions(+), 8 deletions(-) diff --git a/checkin_notes b/checkin_notes index 80a07aad5d..2e12a86394 100644 --- a/checkin_notes +++ b/checkin_notes @@ -10020,3 +10020,14 @@ Charlie 18 July 11 clientgui/ sg_StatImageLoader.cpp sg_ViewTabPage.cpp + +Charlie 27 July 11 + - SCR: Fix delay dismissing screensaver under Mac OS10.7. + + clientscr/ + mac_saver_module.cpp + Mac_Saver_Module.h + Mac_Saver_ModuleView.m, .h + mac_build/ + boinc.xcodeproj/ + project.pbxproj diff --git a/clientscr/Mac_Saver_Module.h b/clientscr/Mac_Saver_Module.h index 967608f8a2..c8b101261f 100644 --- a/clientscr/Mac_Saver_Module.h +++ b/clientscr/Mac_Saver_Module.h @@ -48,6 +48,7 @@ void setShow_default_ss_first(bool value); void setGFXDefaultPeriod(double value); void setGFXSciencePeriod(double value); void setGGFXChangePeriod(double value); +double getDTime(); void print_to_log_file(const char *format, ...); void strip_cr(char *buf); void PrintBacktrace(void); diff --git a/clientscr/Mac_Saver_ModuleView.h b/clientscr/Mac_Saver_ModuleView.h index 18daa4bde1..e3cf558eb2 100644 --- a/clientscr/Mac_Saver_ModuleView.h +++ b/clientscr/Mac_Saver_ModuleView.h @@ -56,4 +56,5 @@ void setGFXDefaultPeriod(double value); void setGFXSciencePeriod(double value); void setGGFXChangePeriod(double value); bool validateNumericString(CFStringRef s); +double getDTime(); extern void print_to_log_file(const char *format, ...); diff --git a/clientscr/Mac_Saver_ModuleView.m b/clientscr/Mac_Saver_ModuleView.m index 9b9a112dc2..fc791be7c0 100644 --- a/clientscr/Mac_Saver_ModuleView.m +++ b/clientscr/Mac_Saver_ModuleView.m @@ -24,6 +24,9 @@ #include #include #include // For NSInteger +#include +#include +#include #ifndef NSInteger #if __LP64__ || NS_BUILD_32_LIKE_64 @@ -40,6 +43,10 @@ typedef float CGFloat; void print_to_log_file(const char *format, ...); void strip_cr(char *buf); +static SInt32 gSystemVersion = 0; +static double gSS_StartTime = 0.0; +mach_port_t gEventHandle = 0; + int gGoToBlank; // True if we are to blank the screen int gBlankingTime; // Delay in minutes before blanking the screen NSString *gPathToBundleResources = NULL; @@ -83,6 +90,13 @@ int signof(float x) { NSBundle * myBundle; int newFrequency; int period; + + gEventHandle = NXOpenEventStatus(); + + OSStatus err = Gestalt(gestaltSystemVersion, &gSystemVersion); + if (err != noErr) { + gSystemVersion = 0; + } initBOINCSaver(); @@ -178,6 +192,8 @@ int signof(float x) { newFrequency = startBOINCSaver(); if (newFrequency) [ self setAnimationTimeInterval:1.0/newFrequency ]; + + gSS_StartTime = getDTime(); } // If there are multiple displays, this may get called @@ -223,6 +239,10 @@ int signof(float x) { char *msg; CFStringRef cf_msg; AbsoluteTime timeToUnblock, frameStartTime = UpTime(); + kern_return_t kernResult = kIOReturnError; + UInt64 params; + IOByteCount rcnt = sizeof(UInt64); + double idleTime = 0; if ([ self isPreview ]) { #if 1 // Currently drawRect just draws our logo in the preview window @@ -243,6 +263,18 @@ int signof(float x) { return; } + // For unkown reasons, OS 10.7 Lion screensaver delays several seconds after + // user activity before calling stopAnimation, so we check user activity here + if ((gSystemVersion >= 1070) && ((getDTime() - gSS_StartTime) > 2.0)) { + kernResult = IOHIDGetParameter( gEventHandle, CFSTR(EVSIOIDLE), sizeof(UInt64), ¶ms, &rcnt ); + if ( kernResult == kIOReturnSuccess ) { + idleTime = ((double)params) / 1000.0 / 1000.0 / 1000.0; + if (idleTime < 1.5) { + [ self stopAnimation ]; + } + } + } + myContext = [[NSGraphicsContext currentContext] graphicsPort]; // [myContext retain]; diff --git a/clientscr/mac_saver_module.cpp b/clientscr/mac_saver_module.cpp index d3c1f03841..8fda5fb6b4 100644 --- a/clientscr/mac_saver_module.cpp +++ b/clientscr/mac_saver_module.cpp @@ -72,7 +72,6 @@ extern CFStringRef gPathToBundleResources; static SaverState saverState = SaverState_Idle; // int gQuitCounter = 0; -static SInt32 gSystemVersion = 0; const char * CantLaunchCCMsg = "Unable to launch BOINC application."; @@ -201,6 +200,11 @@ void setGGFXChangePeriod(double value) { } +double getDTime() { + return dtime(); +} + + bool validateNumericString(CFStringRef s) { CFIndex i; CFRange range, result; @@ -218,7 +222,6 @@ bool validateNumericString(CFStringRef s) { CScreensaver::CScreensaver() { struct ss_periods periods; - OSStatus err; m_dwBlankScreen = 0; m_dwBlankTime = 0; @@ -241,11 +244,6 @@ CScreensaver::CScreensaver() { rpc = 0; m_bConnected = false; - err = Gestalt(gestaltSystemVersion, &gSystemVersion); - if (err != noErr) { - gSystemVersion = 0; - } - // Get project-defined default values for GFXDefaultPeriod, GFXSciencePeriod, GFXChangePeriod GetDefaultDisplayPeriods(periods); m_bShow_default_ss_first = periods.Show_default_ss_first; @@ -650,7 +648,7 @@ bool CScreensaver::DestroyDataManagementThread() { } if (rpc) { - rpc->close(); // In case DataManagementProc is hung waiting for RPC + rpc->close(); // In case DataManagementProc is hung waiting for RPC } m_hDataManagementThread = NULL; // Don't delay more if this routine is called again. if (m_hGraphicsApplication) { diff --git a/mac_build/boinc.xcodeproj/project.pbxproj b/mac_build/boinc.xcodeproj/project.pbxproj index b40e49a0c4..6a99d3903e 100755 --- a/mac_build/boinc.xcodeproj/project.pbxproj +++ b/mac_build/boinc.xcodeproj/project.pbxproj @@ -65,6 +65,7 @@ DD29B8A2139F0CED0014477D /* procinfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DD29B89E139F0CED0014477D /* procinfo.cpp */; }; DD29B8A7139F14D10014477D /* procinfo_mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDB6934F0ABFE9C600689FD8 /* procinfo_mac.cpp */; }; DD29B8AC139F15080014477D /* procinfo_mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDB6934F0ABFE9C600689FD8 /* procinfo_mac.cpp */; }; + DD3048CD13E032DD00D47966 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDE2552B07C62F3E008E7D6E /* IOKit.framework */; }; DD32CC830C27CEFB0016F571 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F51BDF4903086C46012012A7 /* InfoPlist.strings */; }; DD32CC8F0C27CF860016F571 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F51BDF4903086C46012012A7 /* InfoPlist.strings */; }; DD33C6F308B5BAF500768630 /* gui_http.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DD33C6F108B5BAF500768630 /* gui_http.cpp */; }; @@ -1151,6 +1152,7 @@ DD130E740820C422001A0291 /* ScreenSaver.framework in Frameworks */, DDB6E3EF0D5B27AA00ED12B8 /* Carbon.framework in Frameworks */, DDB74A6C0D74259E00E97A40 /* AppKit.framework in Frameworks */, + DD3048CD13E032DD00D47966 /* IOKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; };