Improve window focusing (need to fix tests)