aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlizzie <lizzie@eden-emu.dev>2026-10-14 21:24:58 +0200
committercrueter <crueter@eden-emu.dev>2026-10-14 21:24:58 +0200
commit14da4482a4668928bad43bb67ef12f96b9c9d972 (patch)
tree8b98b663e008b3286d747b774a08c7befd55b791
parentfb51a1253447a2655382d3cf952c4c470a1d96c6 (diff)
[input_common/joycon] Enumerate SDL devices iff SDL signals change (#4486)
As per SDL documentation this is the "desired" loop. > Enumerating the HID devices is an expensive operation, so you can call this to see if there have been any system device changes since the last call to this function. A change in the counter returned doesn't necessarily mean that anything has changed, but you can call SDL_hid_enumerate() to get an updated device list. https://wiki.libsdl.org/SDL3/SDL_hid_device_change_count Signed-off-by: lizzie <lizzie@eden-emu.dev> - [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4486 Reviewed-by: Maufeat <sahyno1996@gmail.com> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
-rw-r--r--src/input_common/drivers/joycon.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp
index fb2d75e384..047e7eb6d8 100644
--- a/src/input_common/drivers/joycon.cpp
+++ b/src/input_common/drivers/joycon.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 2022 yuzu Emulator Project
@@ -83,20 +83,21 @@ void Joycons::ScanThread(std::stop_token stop_token) {
constexpr u16 nintendo_vendor_id = 0x057e;
Common::SetCurrentThreadName("JoyconScanThread");
+ auto last_ret = 0u;
do {
- SDL_hid_device_info* devs = SDL_hid_enumerate(nintendo_vendor_id, 0x0);
- SDL_hid_device_info* cur_dev = devs;
-
- while (cur_dev) {
- if (IsDeviceNew(cur_dev)) {
- LOG_DEBUG(Input, "Device Found,type : {:04X} {:04X}", cur_dev->vendor_id,
- cur_dev->product_id);
- RegisterNewDevice(cur_dev);
+ auto ret = SDL_hid_device_change_count();
+ if (last_ret == 0u || last_ret != ret) {
+ last_ret = ret;
+ SDL_hid_device_info* devs = SDL_hid_enumerate(nintendo_vendor_id, 0x0);
+ for (auto* cur_dev = devs; cur_dev; cur_dev = cur_dev->next) {
+ if (IsDeviceNew(cur_dev)) {
+ LOG_DEBUG(Input, "Device Found,type : {:04X} {:04X}", cur_dev->vendor_id, cur_dev->product_id);
+ RegisterNewDevice(cur_dev);
+ }
+ cur_dev = cur_dev->next;
}
- cur_dev = cur_dev->next;
+ SDL_hid_free_enumeration(devs);
}
-
- SDL_hid_free_enumeration(devs);
} while (Common::StoppableTimedWait(stop_token, std::chrono::seconds{5}));
}