Skip to content

display.toggle_fullscreen does not work when toggling a maximized window to fullscreen #2380

@QuetzalQatl

Description

@QuetzalQatl

Environment:
pygame 2.0.0 (SDL 2.0.12, python 3.7.9)

  • Operating system windows 7
  • Python version 3.7.9
  • SDL version 2.0.12
  • PyGame version 2.0.0:

Current behavior:

When toggling fullscreen from a windowed, maximized window, it tries to do it, fails, gives this warning:
Warning: re-creating window in toggle_fullscreen
then a windowed screen is displayed: that is not re-sizable

Expected behavior:

The same as non-maximized windows

Steps to reproduce:

Inspect the sample code: set isFullSreen to True if you want to start with a fullscreen (same behaviour)
Toggle fullscreen with F a couple of times: that works just fine.
then maximize the window, and press F to see the problem arise.

Test code

#!/usr/bin/env python3
import os
import pygame

pygame.init()

# find out & store desktopSize
pgdi=pygame.display.Info()
desktopSize=(pgdi.current_w, pgdi.current_h)

FPS = 100
clock = pygame.time.Clock()

screenWidth=160 # initial screen width when windowed
screenHeight=120

hor=0 # ball position on screen 
ver=0

# will make the first intance of the window appear in the middle of the screen.
# (consecutive instances will appear in the upper most left corner)
os.environ['SDL_VIDEO_CENTERED'] = '1' 

# flag to keep track of the question: is the window maximized or not
# should remain False at startup
maximized=False 

# choose to startup fullscreen or not.
# both options will work fine
isFullScreen=True 

# set up initial display:

# always make the non-fullscreen screen first, 
# so the fullscreen has something to toggle back to that is placed properly (as in not at 0,0 )
screen = pygame.display.set_mode((screenWidth,screenHeight), pygame.RESIZABLE) 

if isFullScreen:
    # set size to desktop 
    # not doing this takes much longer (about 4 seconds)
    # but doing this is near instantanious
    pygame.display.set_mode(desktopSize, pygame.RESIZABLE) 
    
    pygame.display.toggle_fullscreen() # now toggle fullscreen


done=False
while not done:
    for event in pygame.event.get():        
        if event.type == pygame.QUIT: 
            # like ctrl-break or the cross in the title bar
            done = True
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_q: 
            # pressing q will also quit the program
            done = True
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_f:
            # pressing f will toggle fullscreen
            
            isFullScreen=not isFullScreen # toggle fullscreen flag
            if isFullScreen: #toggling from not fullscreen to fullscreen
                # store size of windowed screen 
                # so we can reset it when toggling back
                screenWidth=screen.get_width()
                screenHeight=screen.get_height()
            
                # set the number of pixels to desktop size
                pygame.display.set_mode(desktopSize, pygame.RESIZABLE) 
                # then toggle that to fullscreen                
                pygame.display.toggle_fullscreen()                    
                    
            else: # toggling from fullscreen to not fullscreen
                pygame.display.toggle_fullscreen() 
                # restore to old size
                pygame.display.set_mode((screenWidth, screenHeight), pygame.RESIZABLE)
            
    # show some things on screen:        
    # paint background
    screen.fill((255, 0, 255))

    # slide ball position
    hor += 1
    hor = hor % screen.get_width()
    ver += hor % 2
    ver = ver % screen.get_height()
    
    # paint ball
    pygame.draw.circle(screen, (255, 255, 255), (hor, ver), 5)
        
    pygame.display.flip()
    clock.tick(FPS)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions