From d1b35bf1d723c4699dc0762915d9197191865d42 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 19 Sep 2021 09:16:11 +0200 Subject: [PATCH] app: [macOS] trigger redraw on resize for context-less windows Switching to using a CAMetalLayer as the layer backing our NSView implementation broke programs such as the opengl example. Somehow, using ANGLE on top of a CAMetalLayer (but not a CAEAGLLayer) stops resizes from triggering redraws. This change invalidates the view in setFrameSize, to force a redraw and no longer rely on the implicit redraws. Signed-off-by: Elias Naur --- app/os_macos.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/os_macos.m b/app/os_macos.m index bd2c20bc..7ec868bb 100644 --- a/app/os_macos.m +++ b/app/os_macos.m @@ -60,6 +60,10 @@ static void handleMouse(NSView *view, NSEvent *event, int typ, CGFloat dx, CGFlo @end @implementation GioView +- (void)setFrameSize:(NSSize)newSize { + [super setFrameSize:newSize]; + [self setNeedsDisplay:YES]; +} // drawRect is called when OpenGL is used, displayLayer otherwise. // Don't know why. - (void)drawRect:(NSRect)r { @@ -233,7 +237,7 @@ CFTypeRef gio_createView(void) { @autoreleasepool { NSRect frame = NSMakeRect(0, 0, 0, 0); GioView* view = [[GioView alloc] initWithFrame:frame]; - [view setWantsLayer:YES]; + view.wantsLayer = YES; view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize; return CFBridgingRetain(view); }