diff --git a/app/src/main/cpp/skyline/input/npad.cpp b/app/src/main/cpp/skyline/input/npad.cpp index 867a2ed8..00dcefeb 100644 --- a/app/src/main/cpp/skyline/input/npad.cpp +++ b/app/src/main/cpp/skyline/input/npad.cpp @@ -69,14 +69,7 @@ namespace skyline::input { // We do this to prevent triggering the event unless there's a real change in a device's style, which would be caused if we disconnected all controllers then reconnected them for (auto &device : npads) { - bool connected{}; - for (const auto &controller : controllers) { - if (controller.device == &device) { - connected = true; - break; - } - } - if (!connected) + if (!ranges::any_of(controllers, [&](auto &controller) { return controller.device == &device; })) device.Disconnect(); } } diff --git a/app/src/main/cpp/skyline/input/npad.h b/app/src/main/cpp/skyline/input/npad.h index 7475f049..4fbbc085 100644 --- a/app/src/main/cpp/skyline/input/npad.h +++ b/app/src/main/cpp/skyline/input/npad.h @@ -3,6 +3,7 @@ #pragma once +#include #include "npad_device.h" namespace skyline::input { @@ -69,6 +70,16 @@ namespace skyline::input { return npads.operator[](Translate(id)); } + /** + * @brief Counts the number of currently connected controllers + */ + size_t GetConnectedControllerCount() { + std::scoped_lock lock{mutex}; + return static_cast(ranges::count_if(controllers, [](const auto &controller) { + return controller.device != nullptr && controller.device->connectionState.connected; + })); + } + /** * @brief Deduces all the mappings from guest controllers -> players based on the configuration supplied by HID services and available controllers * @note If any class members were edited, the mutex shouldn't be released till this is called