From aa0afc9a4e792c9e86c81ad4b180942e1713d946 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 19 Apr 2021 23:09:25 +0200 Subject: [PATCH] Input: avoid mouse events when unused --- rpcs3/Emu/Cell/Modules/cellPad.cpp | 4 +- rpcs3/Emu/Io/pad_config.h | 42 +++++++++--------- rpcs3/Input/keyboard_pad_handler.cpp | 66 ++++++++++++++++++---------- rpcs3/Input/keyboard_pad_handler.h | 1 + 4 files changed, 66 insertions(+), 47 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellPad.cpp b/rpcs3/Emu/Cell/Modules/cellPad.cpp index 542acb5ccb..e36e705754 100644 --- a/rpcs3/Emu/Cell/Modules/cellPad.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPad.cpp @@ -191,8 +191,8 @@ error_code cellPadGetData(u32 port_no, vm::ptr data) } else { - u16 d1Initial = pad->m_digital_1; - u16 d2Initial = pad->m_digital_2; + const u16 d1Initial = pad->m_digital_1; + const u16 d2Initial = pad->m_digital_2; for (Button& button : pad->m_buttons) { diff --git a/rpcs3/Emu/Io/pad_config.h b/rpcs3/Emu/Io/pad_config.h index 6cca7fca9d..b38f62b896 100644 --- a/rpcs3/Emu/Io/pad_config.h +++ b/rpcs3/Emu/Io/pad_config.h @@ -41,7 +41,7 @@ struct cfg_input final : cfg::node struct pad_config final : cfg::node { - std::string cfg_name = ""; + std::string cfg_name{}; cfg::string ls_left{ this, "Left Stick Left", "" }; cfg::string ls_down{ this, "Left Stick Down", "" }; @@ -69,14 +69,14 @@ struct pad_config final : cfg::node cfg::string l2{ this, "L2", "" }; cfg::string l3{ this, "L3", "" }; - cfg::_int<0, 200> lstickmultiplier{ this, "Left Stick Multiplier", 100 }; - cfg::_int<0, 200> rstickmultiplier{ this, "Right Stick Multiplier", 100 }; - cfg::_int<0, 1000000> lstickdeadzone{ this, "Left Stick Deadzone", 0 }; - cfg::_int<0, 1000000> rstickdeadzone{ this, "Right Stick Deadzone", 0 }; - cfg::_int<0, 1000000> ltriggerthreshold{ this, "Left Trigger Threshold", 0 }; - cfg::_int<0, 1000000> rtriggerthreshold{ this, "Right Trigger Threshold", 0 }; - cfg::_int<0, 1000000> lpadsquircling{ this, "Left Pad Squircling Factor", 0 }; - cfg::_int<0, 1000000> rpadsquircling{ this, "Right Pad Squircling Factor", 0 }; + cfg::uint<0, 200> lstickmultiplier{ this, "Left Stick Multiplier", 100 }; + cfg::uint<0, 200> rstickmultiplier{ this, "Right Stick Multiplier", 100 }; + cfg::uint<0, 1000000> lstickdeadzone{ this, "Left Stick Deadzone", 0 }; + cfg::uint<0, 1000000> rstickdeadzone{ this, "Right Stick Deadzone", 0 }; + cfg::uint<0, 1000000> ltriggerthreshold{ this, "Left Trigger Threshold", 0 }; + cfg::uint<0, 1000000> rtriggerthreshold{ this, "Right Trigger Threshold", 0 }; + cfg::uint<0, 1000000> lpadsquircling{ this, "Left Pad Squircling Factor", 0 }; + cfg::uint<0, 1000000> rpadsquircling{ this, "Right Pad Squircling Factor", 0 }; cfg::uint<0, 255> colorR{ this, "Color Value R", 0 }; cfg::uint<0, 255> colorG{ this, "Color Value G", 0 }; @@ -84,25 +84,25 @@ struct pad_config final : cfg::node cfg::_bool led_low_battery_blink{ this, "Blink LED when battery is below 20%", true }; cfg::_bool led_battery_indicator{ this, "Use LED as a battery indicator", false }; - cfg::_int<0, 100> led_battery_indicator_brightness{ this, "LED battery indicator brightness", 50 }; + cfg::uint<0, 100> led_battery_indicator_brightness{ this, "LED battery indicator brightness", 50 }; cfg::_bool enable_vibration_motor_large{ this, "Enable Large Vibration Motor", true }; cfg::_bool enable_vibration_motor_small{ this, "Enable Small Vibration Motor", true }; cfg::_bool switch_vibration_motors{ this, "Switch Vibration Motors", false }; - cfg::_int<0, 255> mouse_deadzone_x{ this, "Mouse Deadzone X Axis", 60 }; - cfg::_int<0, 255> mouse_deadzone_y{ this, "Mouse Deadzone Y Axis", 60 }; - cfg::_int<0, 3000> mouse_acceleration_x{ this, "Mouse Acceleration X Axis", 200 }; - cfg::_int<0, 3000> mouse_acceleration_y{ this, "Mouse Acceleration Y Axis", 250 }; + cfg::uint<0, 255> mouse_deadzone_x{ this, "Mouse Deadzone X Axis", 60 }; + cfg::uint<0, 255> mouse_deadzone_y{ this, "Mouse Deadzone Y Axis", 60 }; + cfg::uint<0, 3000> mouse_acceleration_x{ this, "Mouse Acceleration X Axis", 200 }; + cfg::uint<0, 3000> mouse_acceleration_y{ this, "Mouse Acceleration Y Axis", 250 }; - cfg::_int<0, 100> l_stick_lerp_factor{ this, "Left Stick Lerp Factor", 100 }; - cfg::_int<0, 100> r_stick_lerp_factor{ this, "Right Stick Lerp Factor", 100 }; - cfg::_int<0, 100> analog_lerp_factor{ this, "Analog Button Lerp Factor", 100 }; - cfg::_int<0, 100> trigger_lerp_factor{ this, "Trigger Lerp Factor", 100 }; + cfg::uint<0, 100> l_stick_lerp_factor{ this, "Left Stick Lerp Factor", 100 }; + cfg::uint<0, 100> r_stick_lerp_factor{ this, "Right Stick Lerp Factor", 100 }; + cfg::uint<0, 100> analog_lerp_factor{ this, "Analog Button Lerp Factor", 100 }; + cfg::uint<0, 100> trigger_lerp_factor{ this, "Trigger Lerp Factor", 100 }; - cfg::_int<0, 5> device_class_type{ this, "Device Class Type", 0 }; - cfg::_int<0, 65535> vendor_id{ this, "Vendor ID", 0 }; - cfg::_int<0, 65535> product_id{ this, "Product ID", 0 }; + cfg::uint<0, 5> device_class_type{ this, "Device Class Type", 0 }; + cfg::uint<0, 65535> vendor_id{ this, "Vendor ID", 0 }; + cfg::uint<0, 65535> product_id{ this, "Product ID", 0 }; bool exist() const; bool load(); diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index 67881fc9ab..52c555bbf1 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -454,6 +454,11 @@ void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event) void keyboard_pad_handler::mouseWheelEvent(QWheelEvent* event) { + if (!m_mouse_wheel_used) + { + return; + } + const QPoint direction = event->angleDelta(); if (direction.isNull()) @@ -695,6 +700,7 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr pad, const std:: return false; m_mouse_move_used = false; + m_mouse_wheel_used = false; m_deadzone_x = p_profile->mouse_deadzone_x; m_deadzone_y = p_profile->mouse_deadzone_y; m_multi_x = p_profile->mouse_acceleration_x / 100.0; @@ -713,6 +719,8 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr pad, const std:: key = 0; else if (!m_mouse_move_used && (key == mouse::move_left || key == mouse::move_right || key == mouse::move_up || key == mouse::move_down)) m_mouse_move_used = true; + else if (!m_mouse_wheel_used && (key == mouse::wheel_left || key == mouse::wheel_right || key == mouse::wheel_up || key == mouse::wheel_down)) + m_mouse_wheel_used = true; return key; }; @@ -777,16 +785,11 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr pad, const std:: void keyboard_pad_handler::ThreadProc() { - static const double mouse_interval = 30.0; static const double stick_interval = 10.0; static const double button_interval = 10.0; const auto now = steady_clock::now(); - const double elapsed_left = std::chrono::duration_cast(now - m_last_mouse_move_left).count() / 1000.0; - const double elapsed_right = std::chrono::duration_cast(now - m_last_mouse_move_right).count() / 1000.0; - const double elapsed_up = std::chrono::duration_cast(now - m_last_mouse_move_up).count() / 1000.0; - const double elapsed_down = std::chrono::duration_cast(now - m_last_mouse_move_down).count() / 1000.0; const double elapsed_stick = std::chrono::duration_cast(now - m_stick_time).count() / 1000.0; const double elapsed_button = std::chrono::duration_cast(now - m_button_time).count() / 1000.0; @@ -803,26 +806,36 @@ void keyboard_pad_handler::ThreadProc() m_button_time = now; } - // roughly 1-2 frames to process the next mouse move - if (elapsed_left > mouse_interval) + if (m_mouse_move_used) { - Key(mouse::move_left, false); - m_last_mouse_move_left = now; - } - if (elapsed_right > mouse_interval) - { - Key(mouse::move_right, false); - m_last_mouse_move_right = now; - } - if (elapsed_up > mouse_interval) - { - Key(mouse::move_up, false); - m_last_mouse_move_up = now; - } - if (elapsed_down > mouse_interval) - { - Key(mouse::move_down, false); - m_last_mouse_move_down = now; + static const double mouse_interval = 30.0; + + const double elapsed_left = std::chrono::duration_cast(now - m_last_mouse_move_left).count() / 1000.0; + const double elapsed_right = std::chrono::duration_cast(now - m_last_mouse_move_right).count() / 1000.0; + const double elapsed_up = std::chrono::duration_cast(now - m_last_mouse_move_up).count() / 1000.0; + const double elapsed_down = std::chrono::duration_cast(now - m_last_mouse_move_down).count() / 1000.0; + + // roughly 1-2 frames to process the next mouse move + if (elapsed_left > mouse_interval) + { + Key(mouse::move_left, false); + m_last_mouse_move_left = now; + } + if (elapsed_right > mouse_interval) + { + Key(mouse::move_right, false); + m_last_mouse_move_right = now; + } + if (elapsed_up > mouse_interval) + { + Key(mouse::move_up, false); + m_last_mouse_move_up = now; + } + if (elapsed_down > mouse_interval) + { + Key(mouse::move_down, false); + m_last_mouse_move_down = now; + } } const auto get_lerped = [](f32 v0, f32 v1, f32 lerp_factor) @@ -898,6 +911,11 @@ void keyboard_pad_handler::ThreadProc() } } + if (!m_mouse_wheel_used) + { + return; + } + // 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 const auto update_threshold = now - std::chrono::milliseconds(100); diff --git a/rpcs3/Input/keyboard_pad_handler.h b/rpcs3/Input/keyboard_pad_handler.h index 5e4f86ceec..f6ea4279ff 100644 --- a/rpcs3/Input/keyboard_pad_handler.h +++ b/rpcs3/Input/keyboard_pad_handler.h @@ -105,6 +105,7 @@ protected: private: QWindow* m_target = nullptr; bool m_mouse_move_used = false; + bool m_mouse_wheel_used = false; bool get_mouse_lock_state() const; void release_all_keys();