Backport focus fixes from Spartacus (bug 956959)