SDL_CreateWindow with SDL_WINDOWPOS_UNDEFINED always centers windows

Hi,

I’m programming with SDL in Linux. I would have thought, that if i set SDL_WINDOWPOS_UNDEFINED for x and y in SDL_CreateWindow(), the window position is chosen by the window manager (XFCE4 here). But windows always open in the center of the screen. Is this correct – and how can I get the desired behaviour?

This glitching also occurs in Win32. In SDL2, both SDL_WINDOWPOS_UNDEFINED and SDL_WINDOWPOS_CENTERED make it centered window at the cross-platform level:


    if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) ||
        SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
        int displayIndex;
        SDL_Rect bounds;

        displayIndex = SDL_GetIndexOfDisplay(display);
        SDL_GetDisplayBounds(displayIndex, &bounds);
        if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
            window->x = bounds.x + (bounds.w - w) / 2;
        }
        if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) {
            window->y = bounds.y + (bounds.h - h) / 2;
        }
    }

However, in Win32, passing CW_USEDEFAULT to the x and y parameters of CreateWindow makes it create a window at Microsoft’s position which is much more natural than centered window. Is this going to be bugfixed in SDL3?

Yep!
Added handling for undefined window position on Windows · libsdl-org/SDL@3bfd596 (github.com)

also:
Added handling for undefined window position on X11 · libsdl-org/SDL@4d9d343 (github.com)