SDL_SetWindowParent(3)

πŸ’– SDL_SetWindowParent πŸ’–

okay bestie, welcome to another episode of SDL3 FUNCTIONS, the manual-page cinematic universe where we make windows adopt other windows. yes fr fr, this is a real function, and it's lowkey iconic. sit down, grab a πŸ“, let's get into it.


✨ NAME ✨

SDL_SetWindowParent β€” set the window as a child of a parent window. it's giving family tree energy πŸŒ³πŸ‘‘


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_video.h>

bool SDL_SetWindowParent(SDL_Window *window, SDL_Window *parent);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜•. If the window is already the child of an existing window, it will be reparented to the new owner. no drama, it just switches parents. and if you set the parent window to NULL? boom, the window gets unparented and its child window status is removed. free agent era. πŸ•ŠοΈ

now, the recursive part, and this one's important so pay attention bestie:

If a parent window is hidden or destroyed, the operation will be recursively applied to child windows. Child windows hidden with the parent that did not have their hidden status explicitly set will be restored when the parent is shown. so basically the kids go where the parent goes β€” but the ones who never explicitly set their own hidden status come back when the parent comes back. main character parent energy honestly. ✨

🚫 Attempting to set the parent of a window that is currently in the modal state will fail. Use SDL_SetWindowModal() to cancel the modal status before attempting to change the parent. like, deal with the modal situation first, bestie, don't just yolo it.
🚫 Popup windows cannot change parents and attempts to do so will fail. popups said "no thank you, I'm staying right here" πŸ’…
πŸ’€ Setting a parent window that is currently the sibling or descendent of the child window results in undefined behavior. not "probably fine", not "usually works" β€” undefined behavior. do not do this. no cap. this is the part where you go "not me doing that" and then don't do that.

πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • window β€” the window that should become the child of a parent. the baby of the family 🍼
  • parent β€” the new parent window for the child window. the one taking custody πŸ‘‘

πŸ”₯ RETURN VALUE πŸ”₯

Returns true on success or false on failure β€” and if it fails, call SDL_GetError() for more information. always check your return value bestie, it's self-care. πŸ’…


🧚 THREAD SAFETY 🧚

This function should only be called on the main thread. so no sneaking it onto a worker thread, okay? main thread only, periodt. 🚨


⭐ AVAILABILITY ⭐

This function is available since SDL 3.2.0. if you're on something older, sorry bestie, you're getting nothing πŸ™ˆ


🌈 SEE ALSO 🌈

  • SDL_SetWindowModal(3) β€” the one you need when a window is being all modal and refusing to get reparented 🫢

and that's the whole vibe check, bestie! go forth and parent your windows responsibly. mwah πŸ’–

β€” with love from the Simple Directmedia Layer crew, SDL 3.4.18, and the SDL_SetWindowParent(3) page itself, which slayed βœ¨πŸ‘‘πŸ’…

πŸ“¦ where this page comes from