Terminal: make sure window fits in screen.

Fixes #8414.