Improve focus emulation

Fixes #296.