From f45de5b87ae8da2fc9e3c87bdd88b03b2930e07e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 2 Aug 2019 17:07:51 -0400 Subject: [PATCH] Adds how-to-release-the-mouse instructions for Cocoa. --- .../Documents/MachineDocument.swift | 17 ++++++++++++++++- .../Mac/Clock Signal/Views/CSOpenGLView.h | 13 +++++++++++++ .../Mac/Clock Signal/Views/CSOpenGLView.m | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 9e60e057a..c849095fb 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -154,6 +154,11 @@ class MachineDocument: // a sheet mysteriously floating on its own. For now, use windowDidUpdate as a proxy to know that the window // is visible, though it's a little premature. func windowDidUpdate(_ notification: Notification) { + // Grab the regular window title, if it's not already stored. + if self.unadornedWindowTitle.count == 0 { + self.unadornedWindowTitle = self.windowControllers[0].window!.title + } + // If an interaction mode is not yet in effect, pick the proper one and display the relevant thing. if self.interactionMode == .notStarted { // If a full machine exists, just continue showing it. @@ -613,7 +618,17 @@ class MachineDocument: try! pngData?.write(to: url) } - // MARK: Activity display. + // MARK: - Window Title Updates. + private var unadornedWindowTitle = "" + func openGLViewDidCaptureMouse(_ view: CSOpenGLView) { + self.windowControllers[0].window?.title = self.unadornedWindowTitle + " (press ⌘+command to release mouse)" + } + + func openGLViewDidReleaseMouse(_ view: CSOpenGLView) { + self.windowControllers[0].window?.title = self.unadornedWindowTitle + } + + // MARK: - Activity Display. private class LED { let levelIndicator: NSLevelIndicator diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h index 4bf010a1e..8437bb999 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h @@ -37,6 +37,19 @@ typedef NS_ENUM(NSInteger, CSOpenGLViewRedrawEvent) { */ - (void)openGLView:(nonnull CSOpenGLView *)view didReceiveFileAtURL:(nonnull NSURL *)URL; +/*! + Announces 'capture' of the mouse — i.e. that the view is now preventing the mouse from exiting + the window, in order to forward continuous mouse motion. + @param view The view making the announcement. +*/ +- (void)openGLViewDidCaptureMouse:(nonnull CSOpenGLView *)view; + +/*! + Announces that the mouse is no longer captured. + @param view The view making the announcement. +*/ +- (void)openGLViewDidReleaseMouse:(nonnull CSOpenGLView *)view; + @end @protocol CSOpenGLViewResponderDelegate diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m index 919fb03ca..697aa138c 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m @@ -223,6 +223,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt _mouseIsCaptured = NO; CGAssociateMouseAndMouseCursorPosition(true); [NSCursor unhide]; + [self.delegate openGLViewDidReleaseMouse:self]; } } @@ -281,6 +282,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt _mouseIsCaptured = YES; [NSCursor hide]; CGAssociateMouseAndMouseCursorPosition(false); + [self.delegate openGLViewDidCaptureMouse:self]; // Don't report the first click to the delegate; treat that as merely // an invitation to capture the cursor.