From 7acac3295d1ddc80cdd4e2f6b8e0a0ea3c2172a8 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Fri, 28 Sep 2018 06:39:11 -0700 Subject: [PATCH] Mac: screensaver fixes for OS 10.14 Mojave --- clientscr/Mac_Saver_ModuleView.h | 1 + clientscr/Mac_Saver_ModuleView.m | 47 ++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/clientscr/Mac_Saver_ModuleView.h b/clientscr/Mac_Saver_ModuleView.h index 2cad85d0f1..af4c68bb78 100644 --- a/clientscr/Mac_Saver_ModuleView.h +++ b/clientscr/Mac_Saver_ModuleView.h @@ -43,6 +43,7 @@ - (IBAction)closeSheetCancel:(id) sender; - (bool) setUpToUseCGWindowList; +- (void) doPeriodicTasks; @end diff --git a/clientscr/Mac_Saver_ModuleView.m b/clientscr/Mac_Saver_ModuleView.m index 169e432c5b..20f08ab769 100644 --- a/clientscr/Mac_Saver_ModuleView.m +++ b/clientscr/Mac_Saver_ModuleView.m @@ -43,7 +43,7 @@ // [7] In the Edit Scheme dialog Arguments tab, add "-debug" and "-window" to // "Arguments passed on launch" // -// [8] In the Finder, open the directory "/Library/Screen Avers" and remove "BOINCSaver.saver" +// [8] In the Finder, open the directory "/Library/Screen Savers" and remove "BOINCSaver.saver" // // [9] In Xcode's Project navigator, under "Products", control-click on "BOINCSaver.saver" and // select " Show in Finder"; make sure your are looking at the Development subdirectory. @@ -157,6 +157,7 @@ static bool UseSharedOffscreenBuffer(void); static double lastGetSSMsgTime; static pthread_t mainThreadID; static int CGWindowListTries; +static bool mojave; #define TEXTBOXMINWIDTH 400.0 @@ -198,6 +199,7 @@ void launchedGfxApp(char * appPath, pid_t thePID, int slot) { - (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview { self = [ super initWithFrame:frame isPreview:isPreview ]; + mojave = (compareOSVersionTo(10, 14) >= 0); return self; } @@ -213,6 +215,9 @@ void launchedGfxApp(char * appPath, pid_t thePID, int slot) { mainThreadID = pthread_self(); + // Under OS 10.14 Mojave, [super drawRect:] is slow but not needed if we do this: + [[self window] setBackgroundColor:[NSColor blackColor]]; + initBOINCSaver(); if (gBOINC_Logo == NULL) { @@ -341,6 +346,18 @@ void launchedGfxApp(char * appPath, pid_t thePID, int slot) { - (void)stopAnimation { [ super stopAnimation ]; + if ([ self isPreview ]) return; + NSRect windowFrame = [ [ self window ] frame ]; + if ( (windowFrame.origin.x != 0) || (windowFrame.origin.y != 0) ) { + return; // We draw only to main screen + } + if (imageView) { + useCGWindowList = false; + // removeFromSuperview must be called from main thread + [imageView removeFromSuperview]; // Releases imageView + imageView = nil; + } + if ( ! [ self isPreview ] ) { closeBOINCSaver(); } @@ -360,15 +377,18 @@ void launchedGfxApp(char * appPath, pid_t thePID, int slot) { // multiple times (once for each display), so we need to guard // against any problems that may cause. - (void)drawRect:(NSRect)rect { - [ super drawRect:rect ]; - // optionally draw here + if (mojave) { + [self doPeriodicTasks]; + } else { + [ super drawRect:rect ]; + } } // If there are multiple displays, this may get called // multiple times (once for each display), so we need to guard // against any problems that may cause. -- (void)animateOneFrame { +- (void)doPeriodicTasks { int newFrequency = 0; int coveredFreq = 0; NSRect theFrame = [ self frame ]; @@ -472,8 +492,7 @@ void launchedGfxApp(char * appPath, pid_t thePID, int slot) { if (childApp) { if (![ childApp activateWithOptions:NSApplicationActivateIgnoringOtherApps ]) { launchedGfxApp("", 0, -1); // Graphics app is no longer running - } - if (useCGWindowList) { + } else if (useCGWindowList) { // As a safety precaution, prevent terminating gfx app while copying its window pthread_mutex_lock(&saver_mutex); @@ -749,6 +768,22 @@ void launchedGfxApp(char * appPath, pid_t thePID, int slot) { } } + +- (void)animateOneFrame { + + NSRect windowFrame = [ [ self window ] frame ]; + if ( (windowFrame.origin.x != 0) || (windowFrame.origin.y != 0) ) { + return; // We draw only to main screen + } + // Drawing in animateOneFrame doesn't seem to work under OS 10.14 Mojave + // but drawing in drawRect: seems slow under erarlier versions of OS X + if (mojave) { + [self display]; + } else { + [self doPeriodicTasks]; + } +} + - (BOOL)hasConfigureSheet { return YES; }