From ae9a099569c366863ee448b6bdc2c0dec1e45203 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 21 Jul 2019 14:31:07 +0200 Subject: Draw during resizing on MacOS Unfortunately drawing still stalls if the user just grabs the resize handle until the first resize event happens, but it seems to be impossible to fix this without using another thread. --- pugl/pugl_osx.m | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index 3b6919d..273002a 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -115,9 +115,9 @@ struct PuglInternalsImpl { @interface PuglOpenGLView : NSOpenGLView { @public - PuglView* puglview; - + PuglView* puglview; NSTrackingArea* trackingArea; + NSTimer* timer; } - (id) initWithFrame:(NSRect)frame; @@ -537,6 +537,36 @@ keySymToSpecial(PuglView* view, NSEvent* ev) puglview->impl->mods = mods; } +- (BOOL) preservesContentInLiveResize +{ + return NO; +} + +- (void) viewWillStartLiveResize +{ + timer = [NSTimer timerWithTimeInterval:(1 / 60.0) + target:self + selector:@selector(resizeTick) + userInfo:nil + repeats:YES]; + [[NSRunLoop currentRunLoop] addTimer:timer + forMode:NSRunLoopCommonModes]; + + [super viewWillStartLiveResize]; +} + +- (void) resizeTick +{ + puglPostRedisplay(puglview); +} + +- (void) viewDidEndLiveResize +{ + [super viewDidEndLiveResize]; + [timer invalidate]; + timer = NULL; +} + @end PuglInternals* -- cgit v1.2.1