SDL_SETWINDOWRELATIVEMOUSEMODE(3)
π SDL_SetWindowRelativeMouseMode π
okay bestie, welcome to the SDL_SetWindowRelativeMouseMode(3) page β it's part of the SDL3 FUNCTIONS family, and yes it's exactly the glow-up you think it is β¨
β¨ NAME β¨
SDL_SetWindowRelativeMouseMode β Set relative mouse mode for a window. π±οΈπ
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_mouse.h>
bool SDL_SetWindowRelativeMouseMode(SDL_Window *window, bool enabled);
like. look at it. two args, one bool back. so clean, so iconic π
π¦ DESCRIPTION π¦
okay so here's the vibe: while the window has focus AND relative mouse mode is enabled, a few things happen all at once, and they're all lowkey amazing:
- the cursor is hidden π
- the mouse position is constrained to the window
- and SDL will report continuous relative mouse motion even if the mouse is at the edge of the window π₯
yes bestie, even at the edge. it just keeps going. main character energy fr fr.
now, if you'd like to keep the mouse position fixed while you're in relative mode, you can use SDL_SetWindowMouseRect(). π§ and if you want the cursor to be at a specific location when relative mode ends, you should use SDL_WarpMouseInWindow() before disabling relative mode. order matters, bestie, it's giving choreography.
also β and this is the part people forget β this function will flush any pending mouse motion for this window. π«Ά
π FUNCTION PARAMETERS π
windowβ the window to change. that's the one, yep, that one right there πenabledβtrueto enable relative mode,falseto disable. it's a whole binary mood.
β RETURN VALUE β
Returns true on success or false on failure. π and if it fails, pls pls pls call SDL_GetError() for more information β it will tell you what went wrong, no cap.
π THREAD SAFETY π
This function should only be called on the main thread. periodt. don't be chaotic about it.
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on something olderβ¦ bestie. upgrade. π
π SEE ALSO π
SDL_GetWindowRelativeMouseMode(3)β the other half of the duo, iykyk π¦
and that's the whole page!! tysm for reading, go make something cute with your mouse pointer πβ¨π
β with love from the Simple Directmedia Layer girlies, SDL 3.4.18 edition πΈπ«Ά
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms