1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-23 20:29:42 +00:00

Takes a basic stab at mouse cursor hiding.

This commit is contained in:
Thomas Harte 2019-03-06 21:49:50 -05:00
parent d03a7911b5
commit 0ace189e38

View File

@ -16,6 +16,9 @@
@implementation CSOpenGLView {
CVDisplayLinkRef _displayLink;
CGSize _backingSize;
NSTrackingArea *_mouseTrackingArea;
NSTimer *_mouseHideTimer;
}
- (void)prepareOpenGL
@ -184,4 +187,45 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
return NSDragOperationLink;
}
#pragma mark - Mouse hiding
- (void)updateTrackingAreas {
[super updateTrackingAreas];
if(_mouseTrackingArea) {
[self removeTrackingArea:_mouseTrackingArea];
}
_mouseTrackingArea =
[[NSTrackingArea alloc]
initWithRect:self.bounds
options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveWhenFirstResponder
owner:self
userInfo:nil];
[self addTrackingArea:_mouseTrackingArea];
}
- (void)mouseMoved:(NSEvent *)event {
[super mouseMoved:event];
[self scheduleMouseHide];
}
- (void)mouseEntered:(NSEvent *)event {
[super mouseEntered:event];
[self scheduleMouseHide];
}
- (void)scheduleMouseHide {
[_mouseHideTimer invalidate];
_mouseHideTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 repeats:NO block:^(NSTimer * _Nonnull timer) {
[NSCursor setHiddenUntilMouseMoves:YES];
}];
}
- (void)mouseExited:(NSEvent *)event {
[super mouseExited:event];
[_mouseHideTimer invalidate];
_mouseHideTimer = nil;
}
@end