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 β€” true to enable relative mode, false to 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 πŸ‘‘


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