 @available(macOS 10.12.1, *)
 extension AppDelegate {
     
+    private enum TouchBarValidationDelay: TimeInterval {
+        
+        case normal = 0.1
+        case lazy = 0.85
+    }
+    
+    
     fileprivate func validateTouchBarIfNeeded() {
         
         guard NSClassFromString("NSTouchBar") != nil else { return }  // run-time check

        // skip validation for specific events
        //   -> Just like NSToolbar does. See Apple's API reference for NSToolbar's `validateVisibleItems()`.
        //      cf. https://developer.apple.com/reference/appkit/nstoolbar/1516947-validatevisibleitems
        switch event.type {
        case .leftMouseDragged,
             .rightMouseDragged,

             .mouseMoved:
            return
            
        case .keyUp,
             .flagsChanged:
            isLazy = true
            
        default:
            break
        }
        
        // schedule validation with delay
        // -> A tiny delay makes sense:
        //      1. To wait change state.
        //      2. To gather multiple events.
        if let timer = self.touchBarValidationTimer, timer.isValid {
            timer.fireDate = Date(timeIntervalSinceNow: TouchBarValidationDelay.normal.rawValue)
        } else {
            let delay: TouchBarValidationDelay = isLazy ? .lazy : .normal
            self.touchBarValidationTimer = Timer.scheduledTimer(timeInterval: delay.rawValue,
                                                                target: self,
                                                                selector: #selector(validateTouchBar(timer:)),
                                                                userInfo: nil,
                                                                repeats: false)
        }
    }
    
