summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
diff options
context:
space:
mode:
authorFiloppi <filippotarpini@hotmail.it>2021-05-15 12:14:11 +0300
committerFiloppi <filippotarpini@hotmail.it>2021-06-07 11:07:06 +0300
commitdcc345400e38e54ac84819e5cbcdf65c9cd95f96 (patch)
treefdba03b6c2fcd0b94d75fb8792639990d1236a03 /Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
parent0718cfd7d781952eff53f052466faaea6b5f3a2f (diff)
ControllerInterface: devices population is now async so implement devices sorting priority
This helps us keeping the most important devices (e.g. Mouse and Keyboard) on the top of the list of devices (they still are on all OSes supported by dolphin and to make hotplug devices like DSU appear at the bottom.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
index cb4eae1472..dd22ffe730 100644
--- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
@@ -319,6 +319,19 @@ bool ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Added device: {}", device->GetQualifiedName());
m_devices.emplace_back(std::move(device));
+
+ // We can't (and don't want) to control the order in which devices are added, but we
+ // need their order to be consistent, and we need the same one to always be the first, where
+ // present (the keyboard and mouse device usually). This is because when defaulting a
+ // controller profile, it will automatically select the first device in the list as its default.
+ std::stable_sort(m_devices.begin(), m_devices.end(),
+ [](const std::shared_ptr<ciface::Core::Device>& a,
+ const std::shared_ptr<ciface::Core::Device>& b) {
+ // It would be nice to sort devices by Source then Name then ID but it's
+ // better to leave them sorted by the add order, which also avoids breaking
+ // the order on other platforms that are less tested.
+ return a->GetSortPriority() > b->GetSortPriority();
+ });
}
if (!m_populating_devices_counter)