From bb9d12ba228a0c82ba34c5d1cd58406e776ff8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Hamil?= Date: Wed, 11 Feb 2026 11:24:57 +0300 Subject: [PATCH] Address review comments --- rpcs3/Input/hid_instance.cpp | 100 ++++++++++---------------------- rpcs3/Input/hid_instance.h | 3 - rpcs3/Input/hid_pad_handler.cpp | 2 + rpcs3/Input/wiimote_handler.cpp | 20 ++++--- rpcs3/rpcs3qt/gui_application.h | 1 - 5 files changed, 46 insertions(+), 80 deletions(-) diff --git a/rpcs3/Input/hid_instance.cpp b/rpcs3/Input/hid_instance.cpp index ff0479116a..f462db5515 100644 --- a/rpcs3/Input/hid_instance.cpp +++ b/rpcs3/Input/hid_instance.cpp @@ -8,6 +8,8 @@ #include "3rdparty/hidapi/hidapi/mac/hidapi_darwin.h" #endif +LOG_CHANNEL(hid_log, "HID"); + std::mutex g_hid_mutex; hid_instance::~hid_instance() @@ -68,96 +70,58 @@ bool hid_instance::initialize() hid_device_info* hid_instance::enumerate(u16 vid, u16 pid) { - hid_device_info* devs = nullptr; -#if defined(__APPLE__) - if (thread_ctrl::is_main()) - { - std::lock_guard lock(g_hid_mutex); - devs = hid_enumerate(vid, pid); - } - else - { - Emu.BlockingCallFromMainThread([&]() - { - std::lock_guard lock(g_hid_mutex); - devs = hid_enumerate(vid, pid); - }, false); - } -#else std::lock_guard lock(g_hid_mutex); - devs = hid_enumerate(vid, pid); +#if defined(__APPLE__) + if (!thread_ctrl::is_main()) + { + hid_device_info* devs = nullptr; + Emu.BlockingCallFromMainThread([&]() { devs = hid_enumerate(vid, pid); }, false); + return devs; + } #endif - return devs; + return hid_enumerate(vid, pid); } void hid_instance::free_enumeration(hid_device_info* devs) { if (!devs) return; -#if defined(__APPLE__) - if (thread_ctrl::is_main()) - { - std::lock_guard lock(g_hid_mutex); - hid_free_enumeration(devs); - } - else - { - Emu.BlockingCallFromMainThread([&]() - { - std::lock_guard lock(g_hid_mutex); - hid_free_enumeration(devs); - }, false); - } -#else std::lock_guard lock(g_hid_mutex); - hid_free_enumeration(devs); +#if defined(__APPLE__) + if (!thread_ctrl::is_main()) + { + Emu.BlockingCallFromMainThread([&]() { hid_free_enumeration(devs); }, false); + return; + } #endif + hid_free_enumeration(devs); } hid_device* hid_instance::open_path(const char* path) { - hid_device* dev = nullptr; -#if defined(__APPLE__) - if (thread_ctrl::is_main()) - { - std::lock_guard lock(g_hid_mutex); - dev = hid_open_path(path); - } - else - { - Emu.BlockingCallFromMainThread([&]() - { - std::lock_guard lock(g_hid_mutex); - dev = hid_open_path(path); - }, false); - } -#else std::lock_guard lock(g_hid_mutex); - dev = hid_open_path(path); +#if defined(__APPLE__) + if (!thread_ctrl::is_main()) + { + hid_device* dev = nullptr; + Emu.BlockingCallFromMainThread([&]() { dev = hid_open_path(path); }, false); + return dev; + } #endif - return dev; + return hid_open_path(path); } void hid_instance::close(hid_device* dev) { if (!dev) return; -#if defined(__APPLE__) - if (thread_ctrl::is_main()) - { - std::lock_guard lock(g_hid_mutex); - hid_close(dev); - } - else - { - Emu.BlockingCallFromMainThread([&]() - { - std::lock_guard lock(g_hid_mutex); - hid_close(dev); - }, false); - } -#else std::lock_guard lock(g_hid_mutex); - hid_close(dev); +#if defined(__APPLE__) + if (!thread_ctrl::is_main()) + { + Emu.BlockingCallFromMainThread([&]() { hid_close(dev); }, false); + return; + } #endif + hid_close(dev); } diff --git a/rpcs3/Input/hid_instance.h b/rpcs3/Input/hid_instance.h index 5f8c474d51..9c851bdc77 100644 --- a/rpcs3/Input/hid_instance.h +++ b/rpcs3/Input/hid_instance.h @@ -1,12 +1,9 @@ #pragma once #include "util/types.hpp" -#include "util/logs.hpp" #include #include -LOG_CHANNEL(hid_log, "HID"); - struct hid_instance { public: diff --git a/rpcs3/Input/hid_pad_handler.cpp b/rpcs3/Input/hid_pad_handler.cpp index f8f77045a1..b080c725cb 100644 --- a/rpcs3/Input/hid_pad_handler.cpp +++ b/rpcs3/Input/hid_pad_handler.cpp @@ -12,6 +12,8 @@ #include #include +LOG_CHANNEL(hid_log, "HID"); + #ifdef ANDROID std::vector g_android_usb_devices; std::mutex g_android_usb_devices_mutex; diff --git a/rpcs3/Input/wiimote_handler.cpp b/rpcs3/Input/wiimote_handler.cpp index 111dff7801..8a6afeaf26 100644 --- a/rpcs3/Input/wiimote_handler.cpp +++ b/rpcs3/Input/wiimote_handler.cpp @@ -6,6 +6,8 @@ #include "util/yaml.hpp" #include "util/logs.hpp" #include +#include +#include LOG_CHANNEL(wiimote_log, "Wiimote"); @@ -364,7 +366,7 @@ void wiimote_handler::thread_proc() // Scan every 2 seconds if (counter++ % 200 == 0) { - const auto scan_and_add = [&](u16 vid, u16 pid_start, u16 pid_end) + const auto scan_and_add = [&](u16 vid, std::initializer_list> ranges) { struct info_t { @@ -377,9 +379,13 @@ void wiimote_handler::thread_proc() hid_device_info* devs = hid_instance::enumerate(vid, 0); for (hid_device_info* cur = devs; cur; cur = cur->next) { - if (cur->product_id >= pid_start && cur->product_id <= pid_end) + for (const auto& range : ranges) { - candidates.push_back({cur->path, cur->product_id, cur->serial_number ? cur->serial_number : L""}); + if (cur->product_id >= range.first && cur->product_id <= range.second) + { + candidates.push_back({cur->path, cur->product_id, cur->serial_number ? cur->serial_number : L""}); + break; + } } } hid_instance::free_enumeration(devs); @@ -447,12 +453,10 @@ void wiimote_handler::thread_proc() } }; - // Generic Wiimote / DolphinBar Mode 4 (Normal) - scan_and_add(VID_NINTENDO, PID_WIIMOTE, PID_WIIMOTE); - // Wiimote Plus - scan_and_add(VID_NINTENDO, PID_WIIMOTE_PLUS, PID_WIIMOTE_PLUS); + // Generic Wiimote / Wiimote Plus / DolphinBar Mode 4 (Normal) + scan_and_add(VID_NINTENDO, {{PID_WIIMOTE, PID_WIIMOTE}, {PID_WIIMOTE_PLUS, PID_WIIMOTE_PLUS}}); // Mayflash DolphinBar Mode 4 (Custom VID/PIDs) - scan_and_add(VID_MAYFLASH, PID_DOLPHINBAR_START, PID_DOLPHINBAR_END); + scan_and_add(VID_MAYFLASH, {{PID_DOLPHINBAR_START, PID_DOLPHINBAR_END}}); } // Update all devices at 100Hz diff --git a/rpcs3/rpcs3qt/gui_application.h b/rpcs3/rpcs3qt/gui_application.h index 609072a856..948965ef47 100644 --- a/rpcs3/rpcs3qt/gui_application.h +++ b/rpcs3/rpcs3qt/gui_application.h @@ -13,7 +13,6 @@ #include "main_application.h" #include "Emu/System.h" -#include "Input/wiimote_handler.h" #include "Input/raw_mouse_handler.h" #include