SDL_SetWindowPosition(3)

πŸ’– SDL_SetWindowPosition(3) πŸ’–

okay bestie, this one lives in the SDL3 FUNCTIONS section of the SDL3 manual, and it's literally just "hey can u move this window pls" but make it a syscall. πŸͺŸβœ¨


🌸 NAME 🌸

SDL_SetWindowPosition β€” ask politely for the window's position to be set. that's it, that's the whole vibe. πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_video.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

so, if the window is in an exclusive fullscreen or maximized state? yeah no, this request just has no effect. the window is booked and busy, it's not taking requests rn. πŸ’€

but here's the tea: you can use this to reposition fullscreen-desktop windows onto a different display. however (and this is important, bestie, don't skip it), exclusive fullscreen windows are locked to a specific display, so the only way to move those programmatically is through SDL_SetWindowFullscreenMode(). that's the one (and only) door. πŸšͺ

now, on some windowing systems this request is asynchronous, meaning the new coordinates may not have been applied immediately upon the return of this function. like, the function said "k done" but the window is still mid-makeover. if you need the change to be immediate, call SDL_SyncWindow() to block until the changes have actually taken effect. blocking = waiting = patience, iykyk. 🫢

when the window position changes, an SDL_EVENT_WINDOW_MOVED event gets emitted with the window's new coordinates. but β€” and this is the plot twist β€” those new coordinates may not match the exact coordinates you requested, because some windowing systems can restrict the position of the window in certain scenarios (like, say, constraining the position so the window is always within desktop bounds). also, since this is literally just a request, the windowing system can flat-out deny it. not me asking nicely and getting left on read. πŸ™ˆ


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • window β€” the window you wanna reposition. the main character of this operation. πŸ‘‘
  • x β€” the x coordinate of the window, or SDL_WINDOWPOS_CENTERED or SDL_WINDOWPOS_UNDEFINED.
  • y β€” the y coordinate of the window, or SDL_WINDOWPOS_CENTERED or SDL_WINDOWPOS_UNDEFINED.

⭐ RETURN VALUE ⭐

returns true on success or false on failure. and if it fails? call SDL_GetError() for more information, bestie, it'll tell you what went wrong. πŸ”


🌈 THREAD SAFETY 🌈

this function should only be called on the main thread. no side quests, no background threads, no sneaky little calls from somewhere else. main thread only, periodt. πŸ’…


πŸ”₯ AVAILABILITY πŸ”₯

this function is available since SDL 3.2.0. so if you're on something older, no window-moving for you, sorry babe. 😭


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie!! πŸŽ€βœ¨ written by Simple Directmedia Layer, brought to you by SDL 3.4.18 β€” go move some windows, you got this, slay. πŸ’–πŸ¦‹

πŸ“¦ where this page comes from