1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-09 06:29:33 +00:00

Adds how-to-release-the-mouse instructions for Cocoa.

This commit is contained in:
Thomas Harte 2019-08-02 17:07:51 -04:00
parent 011d76175c
commit f45de5b87a
3 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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 <NSObject>

View File

@ -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.