summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp29
1 files 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 <algorithm>
#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.