1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-24 12:30:17 +00:00

Establishes an interface for requesting shortcut theft. Not yet implemented.

This commit is contained in:
Thomas Harte 2019-09-22 13:15:35 -04:00
parent f28c124039
commit 8f88addf9f
2 changed files with 45 additions and 10 deletions

View File

@ -110,8 +110,22 @@ typedef NS_ENUM(NSInteger, CSOpenGLViewRedrawEvent) {
@property (atomic, weak, nullable) id <CSOpenGLViewDelegate> delegate;
@property (nonatomic, weak, nullable) id <CSOpenGLViewResponderDelegate> 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.

View File

@ -7,10 +7,11 @@
//
#import "CSOpenGLView.h"
#import "CSApplication.h"
@import CoreVideo;
@import GLKit;
@interface CSOpenGLView () <NSDraggingDestination>
@interface CSOpenGLView () <NSDraggingDestination, CSApplicationKeyboardEventDelegate>
@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 {