Skip to content

Commit

Permalink
Merge pull request #6952 from spycrab/qt_map_all
Browse files Browse the repository at this point in the history
Qt/Mapping: Add option to map all devices at once
  • Loading branch information
spycrab committed May 23, 2018
2 parents dfb1dba + 574c609 commit 4c1425b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
59 changes: 55 additions & 4 deletions Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions Source/Core/DolphinQt2/Config/Mapping/MappingWindow.cpp
Expand Up @@ -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();
Expand All @@ -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);
}); });
} }
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt2/Config/Mapping/MappingWindow.h
Expand Up @@ -52,6 +52,7 @@ class MappingWindow final : public QDialog
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();
Expand Down

0 comments on commit 4c1425b

Please sign in to comment.