From e3d4c067df2babbaca01029ad5977e18e82d2042 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Wed, 14 Feb 2024 19:26:27 +0100 Subject: [PATCH] raw_mouse: adjust relative mouse position if the window size changed --- rpcs3/Input/raw_mouse_handler.cpp | 10 ++++++++++ rpcs3/Input/raw_mouse_handler.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/rpcs3/Input/raw_mouse_handler.cpp b/rpcs3/Input/raw_mouse_handler.cpp index 2bf44453c6..f8536fb716 100644 --- a/rpcs3/Input/raw_mouse_handler.cpp +++ b/rpcs3/Input/raw_mouse_handler.cpp @@ -159,6 +159,16 @@ void raw_mouse::update_values(const RAWMOUSE& state) const int delta_x = static_cast(state.lLastX * m_mouse_acceleration); const int delta_y = static_cast(state.lLastY * m_mouse_acceleration); + // Adjust mouse position if the window size changed + if (m_window_width_old != m_window_width || m_window_height_old != m_window_height) + { + m_pos_x = static_cast(std::round((m_pos_x / static_cast(m_window_width_old)) * m_window_width)); + m_pos_y = static_cast(std::round((m_pos_y / static_cast(m_window_height_old)) * m_window_height)); + + m_window_width_old = m_window_width; + m_window_height_old = m_window_height; + } + // Calculate new position m_pos_x = std::max(0, std::min(m_pos_x + delta_x, m_window_width - 1)); m_pos_y = std::max(0, std::min(m_pos_y + delta_y, m_window_height - 1)); diff --git a/rpcs3/Input/raw_mouse_handler.h b/rpcs3/Input/raw_mouse_handler.h index 454e93bae1..f154b60e1d 100644 --- a/rpcs3/Input/raw_mouse_handler.h +++ b/rpcs3/Input/raw_mouse_handler.h @@ -32,6 +32,8 @@ private: display_handle_t m_window_handle{}; int m_window_width{}; int m_window_height{}; + int m_window_width_old{}; + int m_window_height_old{}; int m_pos_x{}; int m_pos_y{}; float m_mouse_acceleration = 1.0f;