Windows & displaysSDL 3.2

SDL_SetWindowPosition

Asks to move the window. SDL_WINDOWPOS_CENTERED centers it on its display.

Signature

bool SDL_SetWindowPosition(SDL_Window *window, int x, int y);

How it works

x and y are the top-left corner of the content area, in desktop coordinates. Instead of numbers you can pass SDL_WINDOWPOS_CENTERED for either axis, and SDL does the centering math for you.

It is a request. On some systems the move happens later (wait for SDL_EVENT_WINDOW_MOVED), the system may keep the window on screen, and Wayland does not let applications place windows at all.

Parameters

windowSDL_Window *

The window to move.

xint

New x, or SDL_WINDOWPOS_CENTERED / SDL_WINDOWPOS_UNDEFINED.

yint

New y (down is positive), or SDL_WINDOWPOS_CENTERED / SDL_WINDOWPOS_UNDEFINED.

Return value

true if the request was made, false on failure.

Example

example.cpp
1SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
Official SDL wiki