libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.38k stars 1.74k forks source link

Linux: unexpected window size when setting minimum window size after exiting fullscreen #5233

Closed slime73 closed 2 years ago

slime73 commented 2 years ago

I have a report on my issue tracker here https://github.com/love2d/love/issues/1444 about a problem when SDL_SetWindowFullscreen(window, 0) is called. Our code was calling SetWindowMinimumSize directly after that SetFullscreen call, which on Linux apparently prevents the window from downsizing to its original size after it was fullscreen.

I don't have a Linux setup to test myself, but this code (according to the issue comments) might reproduce it:

#include <SDL.h>
#include <stdio.h>

const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;

int main(int argc, char* argv[])
{
    SDL_Window *window = NULL;
    SDL_Renderer *renderer = NULL;
    int quit = 0;
    Uint32 flags = SDL_WINDOW_SHOWN;

    SDL_Init(SDL_INIT_VIDEO);
    SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, flags, &window, &renderer);

    SDL_SetWindowMinimumSize(window, WINDOW_WIDTH, WINDOW_HEIGHT);
    SDL_RenderSetVSync(renderer, 1);

    while (!quit)
    {
        SDL_Event e;
        while (SDL_PollEvent(&e) > 0)
        {
          switch (e.type)
          {
            case SDL_QUIT:
                quit = 1;
                break;
            case SDL_KEYDOWN:
                if (e.key.keysym.scancode == SDL_SCANCODE_F) {
                    // press "f" to enable fullscreen
                    SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
                } if (e.key.keysym.scancode == SDL_SCANCODE_G) {
                    // press "g" to disable fullscreen
                    SDL_SetWindowFullscreen(window, 0);

                    // Problem call is here:
                    SDL_SetWindowMinimumSize(window, WINDOW_WIDTH, WINDOW_HEIGHT);
                }
                break;
            }
        }

        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);
    }

    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

The issue doesn't occur on macOS. If you're not able to reproduce it on Linux I can try to help narrow it down.

1bsyl commented 2 years ago

Just tried and this is reproduced on linux / x11 I think updating fullscreen is somehow asynchronous so calling SDL_SetWindowMinimumSize() will call

SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));

which sets the current fullscreen size

https://github.com/libsdl-org/SDL/blob/main/src/video/SDL_video.c#L2351

flibitijibibo commented 2 years ago

Might be the same bug as #5055? EDIT: Possibly also #2095?

icculus commented 2 years ago

5274 is likely more of these async issues. Probably going to trying to close some of these as dupes as I test through them.

icculus commented 2 years ago

(The previously mentioned bug was an async thing, but a different async thing than I had in mind. I'll check this issue shortly.)