Added RIDEV_NOLEGACY to improve performance in mouse relative mode (thanks @whrvt!)

This change also makes it so relative mode doesn't kick in until the mouse enters the window client area. This prevents relative mode from kicking in while clicking and dragging on the title bar, etc.
This commit is contained in:
Sam Lantinga
2026-06-22 20:33:27 -07:00
parent e300b87e35
commit a45ef5dc64
3 changed files with 10 additions and 2 deletions

View File

@@ -1419,7 +1419,13 @@ bool SDL_UpdateRelativeMouseMode(void)
{
SDL_Mouse *mouse = SDL_GetMouse();
SDL_Window *focus = SDL_GetKeyboardFocus();
bool relative_mode = (focus && (focus->flags & SDL_WINDOW_MOUSE_RELATIVE_MODE));
bool relative_mode = false;
if (focus &&
(focus->flags & SDL_WINDOW_MOUSE_RELATIVE_MODE) &&
(focus->flags & SDL_WINDOW_MOUSE_FOCUS)) {
relative_mode = true;
}
if (relative_mode == mouse->relative_mode) {
return true;

View File

@@ -4416,10 +4416,12 @@ void SDL_OnWindowEnter(SDL_Window *window)
if (_this->OnWindowEnter) {
_this->OnWindowEnter(_this, window);
}
SDL_UpdateRelativeMouseMode();
}
void SDL_OnWindowLeave(SDL_Window *window)
{
SDL_UpdateRelativeMouseMode();
}
void SDL_OnWindowFocusGained(SDL_Window *window)

View File

@@ -98,7 +98,7 @@ static bool UpdateRawInputDeviceFlags(HWND window, Uint32 last_flags, Uint32 new
devices[count].usUsage = USB_USAGE_GENERIC_MOUSE;
if (new_flags & ENABLE_RAW_MOUSE_INPUT) {
devices[count].dwFlags = 0;
devices[count].dwFlags = RIDEV_NOLEGACY;
devices[count].hwndTarget = window;
} else {
devices[count].dwFlags = RIDEV_REMOVE;