From 049f852a9c5df90d1d9327684a5c22bae78d1da4 Mon Sep 17 00:00:00 2001 From: MSuih Date: Fri, 3 Jan 2020 22:07:40 +0200 Subject: [PATCH] Slight cleanup of mousewheel pr Fixes theoretical uninitialized variable and micro-optimizes scrollwheel stop code --- rpcs3/Input/keyboard_pad_handler.cpp | 22 +++++++++++----------- rpcs3/rpcs3qt/pad_settings_dialog.cpp | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index 9fe90bf064..1816bf9897 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -705,27 +705,27 @@ void keyboard_pad_handler::ThreadProc() // Releases the wheel buttons 0,1 sec after they've been triggered // Next activation is set to distant future to avoid activating this on every proc - std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); - const auto update_treshold = std::chrono::milliseconds(100); - const auto delay = std::chrono::hours(24); - if (now >= m_last_wheel_move_up + update_treshold) + const auto now = std::chrono::steady_clock::now(); + const auto update_threshold = now - std::chrono::milliseconds(100); + const auto distant_future = now + std::chrono::hours(24); + if (update_threshold >= m_last_wheel_move_up) { Key(mouse::wheel_up, false); - m_last_wheel_move_up = now + delay; + m_last_wheel_move_up = distant_future; } - if (now >= m_last_wheel_move_down + update_treshold) + if (update_threshold >= m_last_wheel_move_down) { Key(mouse::wheel_down, false); - m_last_wheel_move_down = now + delay; + m_last_wheel_move_down = distant_future; } - if (now >= m_last_wheel_move_left + update_treshold) + if (update_threshold >= m_last_wheel_move_left) { Key(mouse::wheel_left, false); - m_last_wheel_move_left = now + delay; + m_last_wheel_move_left = distant_future; } - if (now >= m_last_wheel_move_right + update_treshold) + if (update_threshold >= m_last_wheel_move_right) { Key(mouse::wheel_right, false); - m_last_wheel_move_right = now + delay; + m_last_wheel_move_right = distant_future; } } diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.cpp b/rpcs3/rpcs3qt/pad_settings_dialog.cpp index 69f8f52d1e..18af091213 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/pad_settings_dialog.cpp @@ -730,8 +730,9 @@ void pad_settings_dialog::wheelEvent(QWheelEvent *event) key = mouse::wheel_right; } } - if (const int y = direction.y()) + else { + const int y = direction.y(); bool to_up = event->inverted() ? y < 0 : y > 0; if (to_up) {