libsdl-org / SDL

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

[SDL3] [Linux] Odd window behavior after unmaximizing. #10203

Closed GiantBlargg closed 1 month ago

GiantBlargg commented 1 month ago

On Wayland windows will shrink in size by few pixels after being maximized and un-maximized. In some cases this can allow the window to have zero area, causing a crash.

After unmaximizing 2 resize events are emitted. On SDL2 a slightly too large size is sent before the correct size. But SDL3 sends the correct size followed by a slightly too small size.

If SDL uses X11 (XWayland), instead of shrinking the restored window will be further down the screen.

Neither issue occurs with a borderless window, which makes me wonder if it's some problematic border-correction routine.

Neither of these problems appear in SDL2.

I haven't tested with other window managers so I don't know if this is KWin specific.

SDL3 d604555 KWin 6.1.1

Test program:

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

int main() {
    SDL_Init(SDL_INIT_VIDEO);

    SDL_Window* window;
    SDL_Renderer* render;
    SDL_CreateWindowAndRenderer("Test", 640, 480, SDL_WINDOW_RESIZABLE, &window, &render);

    SDL_bool running = SDL_TRUE;
    while (running) {
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_EVENT_QUIT:
                running = SDL_FALSE;
                break;
            case SDL_EVENT_WINDOW_RESIZED:
                printf("(%d,%d)\n", event.window.data1, event.window.data2);
                break;
            }
        }

        SDL_RenderClear(render);
        SDL_RenderPresent(render);
    }

    SDL_Quit();
}
Kontrabant commented 1 month ago

Weird, here's what is happening when the 640x480 window is restored after being maximized:

  1. KWin sends a configure event with a size of 643x482 (???)
  2. The SDL application ignores the size hint in this case, because it knows that the floating window size should be 640x480
  3. The window is configured to be 640x480 and a buffer is attached
  4. KWin then sends a 'corrected' configure event with current dimensions offset by -3,-2 to fix the previously requested window size, but that ends up making the window 637x478, since the geometry was already corrected by SDL.

KDE's behavior seems wrong here, as in the floating state, the size is just a hint that the client is free to ignore.

Kontrabant commented 1 month ago

KDE bug: https://bugs.kde.org/show_bug.cgi?id=489983

Kontrabant commented 1 month ago

KDE fixed the negative extents bug, but SDL needs some cleanup around this too.