Support environments with both window and global

Fixes #1340
Closes #1377