VERY experimental Nintendo Switch 2 emulator
C++
[core/hle/services/am] nuke ButtonPoller and Mouse thread (#4229)
lizzie39763e7321fa
diff --git a/src/core/hle/service/am/button_poller.cpp b/src/core/hle/service/am/button_poller.cppindex 6999acfa12..825d28f5f0 100644--- a/src/core/hle/service/am/button_poller.cpp+++ b/src/core/hle/service/am/button_poller.cpp@@ -41,7 +41,6 @@ ButtonPoller::ButtonPoller(Core::System& system, WindowSystem& window_system) {Core::HID::ControllerUpdateCallback engine_callback{.on_change = [this, &window_system](Core::HID::ControllerTriggerType type) {if (type == Core::HID::ControllerTriggerType::Button) {- std::unique_lock lk{m_mutex};OnButtonStateChanged(window_system);}},@@ -52,29 +51,11 @@ ButtonPoller::ButtonPoller(Core::System& system, WindowSystem& window_system) {m_handheld_key = m_handheld->SetCallback(engine_callback);m_player1 = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);m_player1_key = m_player1->SetCallback(engine_callback);-- m_thread = std::jthread([this, &window_system](std::stop_token stop_token) {- Common::SetCurrentThreadName("ButtonPoller");- while (!stop_token.stop_requested()) {- using namespace std::chrono_literals;- std::unique_lock lk{m_mutex};- m_cv.wait_for(lk, 50ms);- if (stop_token.stop_requested())- break;- OnButtonStateChanged(window_system);- std::this_thread::sleep_for(5ms);- }- });}ButtonPoller::~ButtonPoller() {m_handheld->DeleteCallback(m_handheld_key);m_player1->DeleteCallback(m_player1_key);- m_cv.notify_all();- if (m_thread.joinable()) {- m_thread.request_stop();- m_thread.join();- }}void ButtonPoller::OnButtonStateChanged(WindowSystem& window_system) {diff --git a/src/core/hle/service/am/button_poller.h b/src/core/hle/service/am/button_poller.hindex 11d147d328..f5f12a13b2 100644--- a/src/core/hle/service/am/button_poller.h+++ b/src/core/hle/service/am/button_poller.h@@ -33,9 +33,6 @@ public:void OnButtonStateChanged(WindowSystem& window_system);private:- std::mutex m_mutex;- std::condition_variable m_cv;- std::jthread m_thread;std::optional<std::chrono::steady_clock::time_point> m_home_button_press_start{};std::optional<std::chrono::steady_clock::time_point> m_capture_button_press_start{};std::optional<std::chrono::steady_clock::time_point> m_power_button_press_start{};diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cppindex 7e029d2cdf..00b7220c1e 100644--- a/src/input_common/drivers/mouse.cpp+++ b/src/input_common/drivers/mouse.cpp@@ -1,4 +1,4 @@-// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project+// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project// SPDX-License-Identifier: GPL-3.0-or-later// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project@@ -72,15 +72,6 @@ Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_))wheel_position = {};last_mouse_change = {};last_motion_change = {};-- update_thread = std::jthread([this](std::stop_token stop_token) {- Common::SetCurrentThreadName("Mouse");- while (!stop_token.stop_requested()) {- UpdateStickInput();- UpdateMotionInput();- std::this_thread::sleep_for(std::chrono::milliseconds(update_time));- }- });}void Mouse::UpdateStickInput() {@@ -185,6 +176,11 @@ void Mouse::Move(int x, int y, int center_x, int center_y) {}}+void Mouse::NotifyChanged() {+ UpdateStickInput();+ UpdateMotionInput();+}+void Mouse::MouseMove(f32 touch_x, f32 touch_y) {SetAxis(real_mouse_identifier, mouse_axis_x, touch_x);SetAxis(real_mouse_identifier, mouse_axis_y, touch_y);diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.hindex 2e5e989067..166168c824 100644--- a/src/input_common/drivers/mouse.h+++ b/src/input_common/drivers/mouse.h@@ -1,4 +1,4 @@-// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project+// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project// SPDX-License-Identifier: GPL-3.0-or-later// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project@@ -93,6 +93,9 @@ public:void ReleaseAllButtons();+ /// @brief Notifies we changed something about the mouse state and we must update+ void NotifyChanged();+std::vector<Common::ParamPackage> GetInputDevices() const override;AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override;Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override;@@ -110,7 +113,6 @@ private:Common::Vec3<float> last_motion_change;Common::Vec2<int> wheel_position;bool button_pressed = false;- std::jthread update_thread;};} // namespace InputCommondiff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cppindex 248e302aa5..f9c0233901 100644--- a/src/yuzu/bootmanager.cpp+++ b/src/yuzu/bootmanager.cpp@@ -487,6 +487,7 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) {input_subsystem->GetMouse()->PressMouseButton(button);input_subsystem->GetMouse()->PressButton(pos.x(), pos.y(), button);input_subsystem->GetMouse()->PressTouchButton(touch_x, touch_y, button);+ input_subsystem->GetMouse()->NotifyChanged();emit MouseActivity();}@@ -507,6 +508,7 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {input_subsystem->GetMouse()->MouseMove(touch_x, touch_y);input_subsystem->GetMouse()->TouchMove(touch_x, touch_y);input_subsystem->GetMouse()->Move(pos.x(), pos.y(), center_x, center_y);+ input_subsystem->GetMouse()->NotifyChanged();// Center mouse for mouse panningif (Settings::values.mouse_panning && !Settings::values.mouse_enabled) {@@ -532,6 +534,7 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {const auto button = QtButtonToMouseButton(event->button());input_subsystem->GetMouse()->ReleaseButton(button);+ input_subsystem->GetMouse()->NotifyChanged();}void GRenderWindow::ConstrainMouse() {@@ -564,6 +567,7 @@ void GRenderWindow::wheelEvent(QWheelEvent* event) {const int x = event->angleDelta().x();const int y = event->angleDelta().y();input_subsystem->GetMouse()->MouseWheelChange(x, y);+ input_subsystem->GetMouse()->NotifyChanged();}void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) {@@ -710,8 +714,9 @@ bool GRenderWindow::event(QEvent* event) {void GRenderWindow::focusOutEvent(QFocusEvent* event) {QWidget::focusOutEvent(event);input_subsystem->GetKeyboard()->ReleaseAllKeys();- input_subsystem->GetMouse()->ReleaseAllButtons();input_subsystem->GetTouchScreen()->ReleaseAllTouch();+ input_subsystem->GetMouse()->ReleaseAllButtons();+ input_subsystem->GetMouse()->NotifyChanged();}void GRenderWindow::resizeEvent(QResizeEvent* event) {diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cppindex 821825f6e1..2750cd4a13 100644--- a/src/yuzu/configuration/configure_input_player.cpp+++ b/src/yuzu/configuration/configure_input_player.cpp@@ -1546,12 +1546,14 @@ void ConfigureInputPlayer::mousePressEvent(QMouseEvent* event) {const auto button = GRenderWindow::QtButtonToMouseButton(event->button());input_subsystem->GetMouse()->PressButton(0, 0, button);+ input_subsystem->GetMouse()->NotifyChanged();}void ConfigureInputPlayer::wheelEvent(QWheelEvent* event) {const int x = event->angleDelta().x();const int y = event->angleDelta().y();input_subsystem->GetMouse()->MouseWheelChange(x, y);+ input_subsystem->GetMouse()->NotifyChanged();}void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) {diff --git a/src/yuzu/configuration/configure_ringcon.cpp b/src/yuzu/configuration/configure_ringcon.cppindex 4c842bd069..d722eba07b 100644--- a/src/yuzu/configuration/configure_ringcon.cpp+++ b/src/yuzu/configuration/configure_ringcon.cpp@@ -378,6 +378,7 @@ void ConfigureRingController::mousePressEvent(QMouseEvent* event) {const auto button = GRenderWindow::QtButtonToMouseButton(event->button());input_subsystem->GetMouse()->PressButton(0, 0, button);+ input_subsystem->GetMouse()->NotifyChanged();}void ConfigureRingController::keyPressEvent(QKeyEvent* event) {diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl3.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl3.cppindex cd390d29f9..16a54412e5 100644--- a/src/yuzu_cmd/emu_window/emu_window_sdl3.cpp+++ b/src/yuzu_cmd/emu_window/emu_window_sdl3.cpp@@ -74,6 +74,7 @@ void EmuWindow_SDL3::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {} else {input_subsystem->GetMouse()->ReleaseButton(mouse_button);}+ input_subsystem->GetMouse()->NotifyChanged();}void EmuWindow_SDL3::OnMouseMotion(s32 x, s32 y) {@@ -81,6 +82,7 @@ void EmuWindow_SDL3::OnMouseMotion(s32 x, s32 y) {input_subsystem->GetMouse()->Move(x, y, 0, 0);input_subsystem->GetMouse()->MouseMove(touch_x, touch_y);input_subsystem->GetMouse()->TouchMove(touch_x, touch_y);+ input_subsystem->GetMouse()->NotifyChanged();}void EmuWindow_SDL3::OnFingerDown(float x, float y, std::size_t id) {