Mac: screensaver fixes for OS 10.14 Mojave

This commit is contained in:
Charlie Fenton 2018-09-28 06:39:11 -07:00
parent b6f71ab7f8
commit 7acac3295d
2 changed files with 42 additions and 6 deletions

View File

@ -43,6 +43,7 @@
- (IBAction)closeSheetCancel:(id) sender;
- (bool) setUpToUseCGWindowList;
- (void) doPeriodicTasks;
@end

View File

@ -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;
}