This is a fork of #629 and #627. We should introduce a private method to share the implementation among the three `Window*` methods.