summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/DInput
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2022-07-26 12:52:33 +0200
committerGitHub <noreply@github.com>2022-07-26 12:52:33 +0200
commit9d15a1c5a1e6183a0e98165ac093e74ca8e4894e (patch)
treebb9806ee563adf38a74e55506f1e387e0bd08b72 /Source/Core/InputCommon/ControllerInterface/DInput
parentc7752f80e4803362c58c03e0510680e95f4061c6 (diff)
parentd14bd10cd74ecfb9777e19dde842fe64d7681605 (diff)
Merge pull request #10858 from AdmiralCurtiss/mouse-center-hotkey
Add hotkey for centering mouse in render window.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/DInput')
-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.