How to ignore mousedown event if window not active

I have a large canvas in the main document window of my MacOS app. I would like to have it ignore any mousedown events if the window is not active (the same way things worked back in the carbon days). I thought maybe I could check whether the doc window is frontmost in the canvas’s mousedown event, but that doesn’t work, because the the mousedown event has already activated the window before the mousedown event handler gets called. So, it appears that the only way to do what I want is to have a window activate event that discards all pending events. Is there some way to discard pending events?

I think I found a reasonably acceptable solution. I’ve created a boolean property called disableMouseDown that is set to true in the window activate event. The mousedown event checks the state of disableMouseDown, and if false, it behaves normally. If true, then it sets it to false and then exits without doing anything else.

I’ve also added a timer that is triggered in the window activate event. When it times out (200ms) it also resets disableMouseDown. That way, only the mousedown event that triggered the window activation will be ignored.