From a2065f59a1a62812279ceaa3fcf8e019a4dfb027 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 12 Jul 2021 19:12:04 -0400 Subject: [PATCH] Adds a 0.1 second pause before exit-related menu fadeout. This is because the system may post a quick succession of exits and enters if the view hierarchy changes. --- .../Mac/Clock Signal/Views/CSScanTargetView.m | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Views/CSScanTargetView.m b/OSBindings/Mac/Clock Signal/Views/CSScanTargetView.m index 1fe1ebbb6..eb6615745 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSScanTargetView.m +++ b/OSBindings/Mac/Clock Signal/Views/CSScanTargetView.m @@ -14,6 +14,9 @@ #include +static const NSTimeInterval standardMouseHideInterval = 3.0; +static const NSTimeInterval quickMouseHideInterval = 0.1; + @interface CSScanTargetView () @end @@ -237,11 +240,11 @@ static CVReturn DisplayLinkCallback(__unused CVDisplayLinkRef displayLink, const [self addTrackingArea:_mouseTrackingArea]; } -- (void)scheduleMouseHide { +- (void)scheduleMouseHideAfter:(NSTimeInterval)interval { if(!self.shouldCaptureMouse) { [_mouseHideTimer invalidate]; - _mouseHideTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 repeats:NO block:^(__unused NSTimer * _Nonnull timer) { + _mouseHideTimer = [NSTimer scheduledTimerWithTimeInterval:interval repeats:NO block:^(__unused NSTimer * _Nonnull timer) { [NSCursor setHiddenUntilMouseMoves:YES]; [self.responderDelegate scanTargetViewWillHideOSMouseCursor:self]; }]; @@ -249,16 +252,17 @@ static CVReturn DisplayLinkCallback(__unused CVDisplayLinkRef displayLink, const } - (void)mouseEntered:(NSEvent *)event { - [self.responderDelegate scanTargetViewDidShowOSMouseCursor:self]; [super mouseEntered:event]; - [self scheduleMouseHide]; + + [self.responderDelegate scanTargetViewDidShowOSMouseCursor:self]; + [self scheduleMouseHideAfter:standardMouseHideInterval]; } - (void)mouseExited:(NSEvent *)event { [super mouseExited:event]; - [_mouseHideTimer invalidate]; - _mouseHideTimer = nil; - [self.responderDelegate scanTargetViewWillHideOSMouseCursor:self]; + + // Schedule a really short mouse-hiding interval. + [self scheduleMouseHideAfter:quickMouseHideInterval]; } - (void)releaseMouse { @@ -278,7 +282,7 @@ static CVReturn DisplayLinkCallback(__unused CVDisplayLinkRef displayLink, const if(!self.shouldCaptureMouse) { // Mouse capture is off, so don't play games with the cursor, just schedule it to // hide in the near future. - [self scheduleMouseHide]; + [self scheduleMouseHideAfter:standardMouseHideInterval]; [self.responderDelegate scanTargetViewDidShowOSMouseCursor:self]; } else { if(_mouseIsCaptured) {