Make mouse foreground window check more reliable