Ver Fonte

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.
Sam Lantinga há 1 dia atrás
pai
commit
a45ef5dc64

+ 7 - 1
src/events/SDL_mouse.c

@@ -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;

+ 2 - 0
src/video/SDL_video.c

@@ -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)

+ 1 - 1
src/video/windows/SDL_windowsrawinput.c

@@ -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;