Handle focus events better (fixes #18)