From 6bcdd3177ddb721f51958fbe9cfa35f04fad6040 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 26 Jan 2020 18:04:25 -0500 Subject: [PATCH] Ensures that a change of screen issues a `reshape`. Just in case. Thereby resolves display mis-sizing when dragging from a Retina display to a regular one, or vice versa. --- OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m index 283f6e19b..5f4267c3a 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m @@ -17,6 +17,7 @@ @implementation CSOpenGLView { CVDisplayLinkRef _displayLink; CGSize _backingSize; + NSScreen *_currentScreen; NSTrackingArea *_mouseTrackingArea; NSTimer *_mouseHideTimer; @@ -26,6 +27,9 @@ - (void)prepareOpenGL { [super prepareOpenGL]; + // Note the initial screen. + _currentScreen = self.window.screen; + // Synchronize buffer swaps with vertical refresh rate GLint swapInt = 1; [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; @@ -56,6 +60,14 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt } - (void)drawAtTime:(const CVTimeStamp *)now frequency:(double)frequency { + if(self.window.screen != _currentScreen) { + _currentScreen = self.window.screen; + + // Issue a reshape, in case a switch to/from a Retina display has + // happened, changing the results of -convertSizeToBacking:, etc. + [self reshape]; + } + [self redrawWithEvent:CSOpenGLViewRedrawEventTimer]; }