From d57d04bb047047bf58849a1a37703ce9d218e39a Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Fri, 15 Jul 2022 21:32:19 +0200 Subject: [PATCH] DInput: Handle mouse centering hotkey. --- .../DInput/DInputKeyboardMouse.cpp | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 3fe850715c..551afde423 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -6,7 +6,9 @@ #include #include "Common/Logging/Log.h" + #include "Core/Core.h" +#include "Core/Host.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/DInput/DInput.h" @@ -168,13 +170,6 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, void KeyboardMouse::UpdateCursorInput() { - POINT point = {}; - GetCursorPos(&point); - - // Get the cursor position relative to the upper left corner of the current window - // (separate or render to main) - ScreenToClient(s_hwnd, &point); - // Get the size of the current window (in my case Rect.top and Rect.left was zero). RECT rect; GetClientRect(s_hwnd, &rect); @@ -183,6 +178,26 @@ void KeyboardMouse::UpdateCursorInput() const auto win_width = std::max(rect.right - rect.left, 1l); const auto win_height = std::max(rect.bottom - rect.top, 1l); + POINT point = {}; + if (g_controller_interface.IsMouseCenteringRequested() && Host_RendererHasFocus()) + { + point.x = win_width / 2; + point.y = win_height / 2; + + POINT screen_point = point; + ClientToScreen(s_hwnd, &screen_point); + SetCursorPos(screen_point.x, screen_point.y); + g_controller_interface.SetMouseCenteringRequested(false); + } + else + { + GetCursorPos(&point); + + // Get the cursor position relative to the upper left corner of the current window + // (separate or render to main) + ScreenToClient(s_hwnd, &point); + } + const auto window_scale = g_controller_interface.GetWindowInputScale(); // Convert the cursor position to a range from -1 to 1.