mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 13:57:57 -07:00
Merge pull request #6952 from spycrab/qt_map_all
Qt/Mapping: Add option to map all devices at once
This commit is contained in:
commit
4c1425b419
@ -2,7 +2,9 @@
|
|||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <future>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
@ -108,15 +110,64 @@ void MappingButton::Detect()
|
|||||||
|
|
||||||
// Make sure that we don't block event handling
|
// Make sure that we don't block event handling
|
||||||
std::thread thread([this] {
|
std::thread thread([this] {
|
||||||
const auto dev = m_parent->GetDevice();
|
|
||||||
|
|
||||||
setText(QStringLiteral("..."));
|
setText(QStringLiteral("..."));
|
||||||
|
|
||||||
// Avoid that the button press itself is registered as an event
|
// Avoid that the button press itself is registered as an event
|
||||||
Common::SleepCurrentThread(100);
|
Common::SleepCurrentThread(100);
|
||||||
|
|
||||||
const auto expr = MappingCommon::DetectExpression(
|
std::vector<std::future<std::pair<QString, QString>>> futures;
|
||||||
m_reference, dev.get(), m_parent->GetController()->GetDefaultDevice());
|
QString expr;
|
||||||
|
|
||||||
|
if (m_parent->GetParent()->IsMappingAllDevices())
|
||||||
|
{
|
||||||
|
for (const std::string& device_str : g_controller_interface.GetAllDeviceStrings())
|
||||||
|
{
|
||||||
|
ciface::Core::DeviceQualifier devq;
|
||||||
|
devq.FromString(device_str);
|
||||||
|
|
||||||
|
auto dev = g_controller_interface.FindDevice(devq);
|
||||||
|
|
||||||
|
auto future = std::async(std::launch::async, [this, devq, dev, device_str] {
|
||||||
|
return std::make_pair(
|
||||||
|
QString::fromStdString(device_str),
|
||||||
|
MappingCommon::DetectExpression(m_reference, dev.get(),
|
||||||
|
m_parent->GetController()->GetDefaultDevice()));
|
||||||
|
});
|
||||||
|
|
||||||
|
futures.push_back(std::move(future));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool done = false;
|
||||||
|
|
||||||
|
while (!done)
|
||||||
|
{
|
||||||
|
for (auto& future : futures)
|
||||||
|
{
|
||||||
|
const auto status = future.wait_for(std::chrono::milliseconds(10));
|
||||||
|
if (status == std::future_status::ready)
|
||||||
|
{
|
||||||
|
const auto pair = future.get();
|
||||||
|
|
||||||
|
done = true;
|
||||||
|
|
||||||
|
if (pair.second.isEmpty())
|
||||||
|
break;
|
||||||
|
|
||||||
|
expr = QStringLiteral("`%1:%2`")
|
||||||
|
.arg(pair.first)
|
||||||
|
.arg(pair.second.startsWith(QLatin1Char('`')) ? pair.second.mid(1) :
|
||||||
|
pair.second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto dev = m_parent->GetDevice();
|
||||||
|
expr = MappingCommon::DetectExpression(m_reference, dev.get(),
|
||||||
|
m_parent->GetController()->GetDefaultDevice());
|
||||||
|
}
|
||||||
|
|
||||||
releaseMouse();
|
releaseMouse();
|
||||||
releaseKeyboard();
|
releaseKeyboard();
|
||||||
|
@ -222,10 +222,18 @@ void MappingWindow::OnSaveProfilePressed()
|
|||||||
|
|
||||||
void MappingWindow::OnDeviceChanged(int index)
|
void MappingWindow::OnDeviceChanged(int index)
|
||||||
{
|
{
|
||||||
|
if (IsMappingAllDevices())
|
||||||
|
return;
|
||||||
|
|
||||||
const auto device = m_devices_combo->currentText().toStdString();
|
const auto device = m_devices_combo->currentText().toStdString();
|
||||||
m_controller->SetDefaultDevice(device);
|
m_controller->SetDefaultDevice(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MappingWindow::IsMappingAllDevices() const
|
||||||
|
{
|
||||||
|
return m_devices_combo->currentIndex() == m_devices_combo->count() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
void MappingWindow::RefreshDevices()
|
void MappingWindow::RefreshDevices()
|
||||||
{
|
{
|
||||||
m_devices_combo->clear();
|
m_devices_combo->clear();
|
||||||
@ -245,6 +253,8 @@ void MappingWindow::RefreshDevices()
|
|||||||
m_devices_combo->addItem(QString::fromStdString(name));
|
m_devices_combo->addItem(QString::fromStdString(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_devices_combo->addItem(tr("All devices"));
|
||||||
|
|
||||||
m_devices_combo->setCurrentIndex(0);
|
m_devices_combo->setCurrentIndex(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
std::shared_ptr<ciface::Core::Device> GetDevice() const;
|
std::shared_ptr<ciface::Core::Device> GetDevice() const;
|
||||||
ControllerEmu::EmulatedController* GetController() const;
|
ControllerEmu::EmulatedController* GetController() const;
|
||||||
bool IsIterativeInput() const;
|
bool IsIterativeInput() const;
|
||||||
|
bool IsMappingAllDevices() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void Update();
|
void Update();
|
||||||
|
Loading…
Reference in New Issue
Block a user