macosnstimernstextfield

How to prevent mouse event to freeze timers


I have a very simple macOS app that runs a NSTimer to update a value and display it on a NSTextField on my NSView.

The NSView also contains NSButton and NSSlider controls, not related to that timer.

When I hold mouse button on a NSButton or NSSlider, the timer does not update anymore, until I lift the mouse button (and then the timer resume).

How do I prevent the mouse button events to freeze timer?

The timer should not freeze when I hit and hold mouse button on the NSButton and NSSlider controls.

UPDATE:

I've found a solution, I need to subclass any NSButton and NSSlider objects, with empty mouse event functions like this:

  override func mouseUp(with event: NSEvent) {}

(those functions are a lot).

Mouse event will not bother NSTimer anymore.

But this solution is tricky, I'll go for the suggested solution.


Solution

  • It is a question of the run loop modes that you are using for the timer: