1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00

Use screen number for spotting screen changes.

NSScreen implements Swift Equatable but doesn't seem officially to implement -isEqual:.
This commit is contained in:
Thomas Harte 2020-03-21 17:01:57 -04:00
parent 75f2b0487e
commit 0c689e85a5
2 changed files with 6 additions and 9 deletions

View File

@ -67,7 +67,7 @@
</Testables> </Testables>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableASanStackUseAfterReturn = "YES" enableASanStackUseAfterReturn = "YES"

View File

@ -17,7 +17,7 @@
@implementation CSOpenGLView { @implementation CSOpenGLView {
CVDisplayLinkRef _displayLink; CVDisplayLinkRef _displayLink;
CGSize _backingSize; CGSize _backingSize;
NSScreen *_currentScreen; NSNumber *_currentScreenNumber;
NSTrackingArea *_mouseTrackingArea; NSTrackingArea *_mouseTrackingArea;
NSTimer *_mouseHideTimer; NSTimer *_mouseHideTimer;
@ -30,10 +30,7 @@
- (void)prepareOpenGL { - (void)prepareOpenGL {
[super prepareOpenGL]; [super prepareOpenGL];
// Note the initial screen. // Set the clear colour.
_currentScreen = self.window.screen;
// set the clear colour
[self.openGLContext makeCurrentContext]; [self.openGLContext makeCurrentContext];
glClearColor(0.0, 0.0, 0.0, 1.0); glClearColor(0.0, 0.0, 0.0, 1.0);
@ -50,6 +47,7 @@
// Create a display link for the display the window is currently on. // Create a display link for the display the window is currently on.
NSNumber *const screenNumber = self.window.screen.deviceDescription[@"NSScreenNumber"]; NSNumber *const screenNumber = self.window.screen.deviceDescription[@"NSScreenNumber"];
_currentScreenNumber = screenNumber;
CVDisplayLinkCreateWithCGDisplay(screenNumber.unsignedIntValue, &_displayLink); CVDisplayLinkCreateWithCGDisplay(screenNumber.unsignedIntValue, &_displayLink);
// Set the renderer output callback function. // Set the renderer output callback function.
@ -101,9 +99,8 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
// There's likely a callback available for this, on NSWindow if nowhere else, or an NSNotification, // There's likely a callback available for this, on NSWindow if nowhere else, or an NSNotification,
// but since this method is going to be called repeatedly anyway, and the test is cheap, polling // but since this method is going to be called repeatedly anyway, and the test is cheap, polling
// feels fine. // feels fine.
if(![self.window.screen isEqual:_currentScreen]) { NSNumber *const screenNumber = self.window.screen.deviceDescription[@"NSScreenNumber"];
_currentScreen = self.window.screen; if(![_currentScreenNumber isEqual:screenNumber]) {
// Issue a reshape, in case a switch to/from a Retina display has // Issue a reshape, in case a switch to/from a Retina display has
// happened, changing the results of -convertSizeToBacking:, etc. // happened, changing the results of -convertSizeToBacking:, etc.
[self reshape]; [self reshape];