Is there a way to detect the pygame display window being moved by user?

Viewed 383

I am writing a game using Pygame. When the game window opens, I currently only have the program call pygame.display.update after the game has changed something that shows on the screen. That works fine for limiting screen refreshes to only when necessary. I have discovered a side effect of moving the game window that causes the screen to get corrupted, which requires the program to force a refresh even if the program itself doesn't require one.

My question is if there is a pygame event (I didn't see one) or something else, that I can use to force the game to refresh the screen after a window move.

1 Answers

Okay, I happened across a code snippet that reports events to the console here: http://www.poketcode.com/en/pygame/events/index.html

Running this was useful because I noticed that every time I moved the window partially off-screen, pygame triggered a VideoExpose event when the window area moved back on screen.

So, I added the following bit of code to my event loop and it worked great!:

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.VIDEOEXPOSE:
            game.update_panels(force=True)

    game.update_panels(force=False)
Related