- applied tito's base.window implementation on top of a fresh master

I manually ported @tito's changes to a fresh master and split it into a separate branch. I considered cherry-picking, but that got really messy, really fast, and manual patches couldn't resolve due to conflicts.