This isn't correct as window activation is handled separately from the cursor entering/leaving a window. This would call de-activate when the cursor moved outside the window even though the window remained focused. Rely on focus changes which already handle activate/deactivate events.