prevent the window from going beyond the edge of the screen

how to prevent the window from not passing the screen limit?