Skip to content

Commit 18bc345

Browse files
committed
OS specific NSView implementation
1 parent f8ad608 commit 18bc345

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

src/window-osx.mm

+39-25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "window-osx.h"
2020

21+
NSOperatingSystemVersion OSversion = [NSProcessInfo processInfo].operatingSystemVersion;
22+
2123
void renderFrames(WindowInfo* wi)
2224
{
2325
while (!wi->view.glData->stop) {
@@ -385,18 +387,24 @@ @implementation WindowImplObj
385387
NSView *viewParent = *reinterpret_cast<NSView**>(handle);
386388
NSWindow *winParent = [viewParent window];
387389

388-
NSRect content_rect = NSMakeRect(0, 0, 0, 0);
389-
wi->window = [
390-
[NSWindow alloc]
391-
initWithContentRect:content_rect
392-
styleMask:NSBorderlessWindowMask
393-
backing:NSBackingStoreBuffered
394-
defer:NO
395-
];
396-
[winParent addChildWindow:wi->window ordered:NSWindowAbove];
397-
wi->window.ignoresMouseEvents = true;
398390
wi->view = [[OpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
399-
[wi->window.contentView addSubview:wi->view];
391+
392+
if (OSversion.majorVersion == 10 && OSversion.minorVersion < 14) {
393+
// Less performant but solves flickering issue on macOS High Sierra and lower
394+
NSRect content_rect = NSMakeRect(0, 0, 0, 0);
395+
wi->window = [
396+
[NSWindow alloc]
397+
initWithContentRect:content_rect
398+
styleMask:NSBorderlessWindowMask
399+
backing:NSBackingStoreBuffered
400+
defer:NO
401+
];
402+
[winParent addChildWindow:wi->window ordered:NSWindowAbove];
403+
wi->window.ignoresMouseEvents = true;
404+
[wi->window.contentView addSubview:wi->view];
405+
} else {
406+
[winParent.contentView addSubview:wi->view];
407+
}
400408
windows.emplace(name, wi);
401409
}
402410

@@ -425,7 +433,8 @@ @implementation WindowImplObj
425433
[wi->view removeFromSuperview];
426434
CFRelease(wi->view);
427435

428-
[wi->window close];
436+
if (wi->window)
437+
[wi->window close];
429438

430439
windows.erase(name);
431440
}
@@ -467,23 +476,28 @@ @implementation WindowImplObj
467476

468477
WindowInfo* wi = reinterpret_cast<WindowInfo*>(it->second);
469478

470-
NSWindow* parent = (NSWindow*)[wi->window parentWindow];
471-
NSRect parentFrame = [parent frame];
479+
if (OSversion.majorVersion == 10 && OSversion.minorVersion < 14) {
480+
NSWindow* parent = (NSWindow*)[wi->window parentWindow];
481+
NSRect parentFrame = [parent frame];
472482

473-
NSRect frame = [wi->window frame];
474-
frame.size = NSMakeSize(
475-
IOSurfaceGetWidth(wi->view.glData->surface),
476-
IOSurfaceGetHeight(wi->view.glData->surface)
477-
);
478-
479-
frame.origin.x = parentFrame.origin.x + cx;
480-
frame.origin.y = parentFrame.origin.y + cy;
483+
NSRect frame = [wi->window frame];
484+
frame.size = NSMakeSize(
485+
IOSurfaceGetWidth(wi->view.glData->surface),
486+
IOSurfaceGetHeight(wi->view.glData->surface)
487+
);
481488

482-
[wi->view setFrameSize:NSMakeSize(IOSurfaceGetWidth(wi->view.glData->surface),
483-
IOSurfaceGetHeight(wi->view.glData->surface))];
489+
frame.origin.x = parentFrame.origin.x + cx;
490+
frame.origin.y = parentFrame.origin.y + cy;
484491

485-
[wi->window setFrame:frame display: YES animate: NO];
492+
[wi->view setFrameSize:NSMakeSize(IOSurfaceGetWidth(wi->view.glData->surface),
493+
IOSurfaceGetHeight(wi->view.glData->surface))];
486494

495+
[wi->window setFrame:frame display: YES animate: NO];
496+
} else {
497+
[wi->view setFrameSize:NSMakeSize(IOSurfaceGetWidth(wi->view.glData->surface),
498+
IOSurfaceGetHeight(wi->view.glData->surface))];
499+
[wi->view setFrameOrigin:NSMakePoint(cx, cy)];
500+
}
487501
}
488502

489503
@end

0 commit comments

Comments
 (0)