From 8f88addf9ff800c8cd83d2451cd7b091b63ee493 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 22 Sep 2019 13:15:35 -0400 Subject: [PATCH] Establishes an interface for requesting shortcut theft. Not yet implemented. --- .../Mac/Clock Signal/Views/CSOpenGLView.h | 14 +++++++ .../Mac/Clock Signal/Views/CSOpenGLView.m | 41 ++++++++++++++----- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h index 8437bb999..25920e578 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h @@ -110,8 +110,22 @@ typedef NS_ENUM(NSInteger, CSOpenGLViewRedrawEvent) { @property (atomic, weak, nullable) id delegate; @property (nonatomic, weak, nullable) id responderDelegate; +/// Determines whether the view offers mouse capturing — i.e. if the user clicks on the view then +/// then the system cursor is disabled and the mouse events defined by CSOpenGLViewResponderDelegate +/// are forwarded, unless and until the user releases the mouse using the control+command shortcut. @property (nonatomic, assign) BOOL shouldCaptureMouse; +/// Determines whether the CSOpenGLViewResponderDelegate of this window expects to use the command +/// key as though it were any other key — i.e. all command combinations should be forwarded to the delegate, +/// not being allowed to trigger regular application shortcuts such as command+q or command+h. +/// +/// How the view respects this will depend on other state; if this view is one that captures the mouse then it +/// will usurp command only while the mouse is captured. +/// +/// TODO: what's smart behaviour if this view doesn't capture the mouse? Probably +/// force a similar capturing behaviour? +@property (nonatomic, assign) BOOL shouldUsurpCommand; + /*! Ends the timer tracking time; should be called prior to giving up the last owning reference to ensure that any retain cycles implied by the timer are resolved. diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m index 697aa138c..c57c05dfb 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m @@ -7,10 +7,11 @@ // #import "CSOpenGLView.h" +#import "CSApplication.h" @import CoreVideo; @import GLKit; -@interface CSOpenGLView () +@interface CSOpenGLView () @end @implementation CSOpenGLView { @@ -139,23 +140,43 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt return YES; } +- (void)propagateKeyboardEvent:(NSEvent *)event { + switch(event.type) { + default: break; + + case kCGEventKeyDown: + [self.responderDelegate keyDown:event]; + break; + case kCGEventKeyUp: + [self.responderDelegate keyUp:event]; + break; + case kCGEventFlagsChanged: + // Release the mouse upon a control + command. + if(_mouseIsCaptured && + event.modifierFlags & NSEventModifierFlagControl && + event.modifierFlags & NSEventModifierFlagCommand) { + [self releaseMouse]; + } + + [self.responderDelegate flagsChanged:event]; + break; + } +} + - (void)keyDown:(NSEvent *)theEvent { - [self.responderDelegate keyDown:theEvent]; + [self propagateKeyboardEvent:theEvent]; } - (void)keyUp:(NSEvent *)theEvent { - [self.responderDelegate keyUp:theEvent]; + [self propagateKeyboardEvent:theEvent]; } - (void)flagsChanged:(NSEvent *)theEvent { - [self.responderDelegate flagsChanged:theEvent]; + [self propagateKeyboardEvent:theEvent]; +} - // Release the mouse upon a control + command. - if(_mouseIsCaptured && - theEvent.modifierFlags & NSEventModifierFlagControl && - theEvent.modifierFlags & NSEventModifierFlagCommand) { - [self releaseMouse]; - } +- (void)sendEvent:(NSEvent *)event { + [self propagateKeyboardEvent:event]; } - (void)paste:(id)sender {