DolphinQt: Add buttons to create and reset Wii remote pairings on Windows.

This commit is contained in:
Jordan Woyak 2025-10-03 23:08:28 -05:00
commit 801f38d4e5
3 changed files with 96 additions and 7 deletions

View file

@ -12,6 +12,8 @@
#include <QPushButton>
#include <QRadioButton>
#include <QScreen>
#include <QTimer>
#include <QToolButton>
#include <QVBoxLayout>
#include <QVariant>
@ -39,6 +41,10 @@
#include "DolphinQt/Settings.h"
#include "DolphinQt/Settings/USBDevicePicker.h"
#if defined(_WIN32)
#include "Core/HW//WiimoteReal/IOWin.h"
#endif
WiimoteControllersWidget::WiimoteControllersWidget(QWidget* parent) : QWidget(parent)
{
CreateLayout();
@ -191,7 +197,31 @@ void WiimoteControllersWidget::CreateLayout()
m_bluetooth_adapters_refresh = new NonDefaultQPushButton(tr("Refresh"));
m_wiimote_sync = new NonDefaultQPushButton(tr("Sync"));
m_wiimote_reset = new NonDefaultQPushButton(tr("Reset"));
m_wiimote_refresh = new NonDefaultQPushButton(tr("Refresh"));
m_wiimote_refresh_indicator = new QLabel{};
m_wiimote_refresh_indicator->hide();
m_wiimote_refresh = new QToolButton();
auto* const wiimote_refresh_action = new QAction(tr("Refresh"), m_wiimote_refresh);
m_wiimote_refresh->setDefaultAction(wiimote_refresh_action);
connect(wiimote_refresh_action, &QAction::triggered, this,
&WiimoteControllersWidget::OnWiimoteRefreshPressed);
m_wiimote_refresh->setPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup);
#if defined(_WIN32)
m_wiimote_refresh_indicator->setPixmap(
style()->standardIcon(QStyle::SP_BrowserReload).pixmap(16, 16));
auto* const wiimote_sync_action = new QAction(tr("Sync"), m_wiimote_refresh);
m_wiimote_refresh->addAction(wiimote_sync_action);
connect(wiimote_sync_action, &QAction::triggered, this,
&WiimoteControllersWidget::TriggerHostWiimoteSync);
auto* const wiimote_reset_action = new QAction(tr("Reset"), m_wiimote_refresh);
m_wiimote_refresh->addAction(wiimote_reset_action);
connect(wiimote_reset_action, &QAction::triggered, this,
&WiimoteControllersWidget::TriggerHostWiimoteReset);
#endif
m_wiimote_pt_labels[0] = new QLabel(tr("Sync real Wii Remotes and pair them"));
m_wiimote_pt_labels[1] = new QLabel(tr("Reset all saved Wii Remote pairings"));
m_wiimote_emu = new QRadioButton(tr("Emulate the Wii's Bluetooth adapter"));
@ -245,7 +275,13 @@ void WiimoteControllersWidget::CreateLayout()
m_wiimote_layout->addWidget(m_wiimote_ciface, m_wiimote_layout->rowCount(), 0, 1, -1);
int continuous_scanning_row = m_wiimote_layout->rowCount();
m_wiimote_layout->addWidget(m_wiimote_continuous_scanning, continuous_scanning_row, 0, 1, 3);
auto* const left_of_refresh_button_layout = new QHBoxLayout;
left_of_refresh_button_layout->addWidget(m_wiimote_continuous_scanning);
left_of_refresh_button_layout->addStretch(1);
left_of_refresh_button_layout->addWidget(m_wiimote_refresh_indicator);
m_wiimote_layout->addLayout(left_of_refresh_button_layout, continuous_scanning_row, 0, 1, 3);
m_wiimote_layout->addWidget(m_wiimote_refresh, continuous_scanning_row, 3);
m_bluetooth_unavailable = new QLabel(tr("A supported Bluetooth device could not be found.\n"
@ -287,8 +323,6 @@ void WiimoteControllersWidget::ConnectWidgets()
&WiimoteControllersWidget::OnBluetoothPassthroughSyncPressed);
connect(m_wiimote_reset, &QPushButton::clicked, this,
&WiimoteControllersWidget::OnBluetoothPassthroughResetPressed);
connect(m_wiimote_refresh, &QPushButton::clicked, this,
&WiimoteControllersWidget::OnWiimoteRefreshPressed);
for (size_t i = 0; i < m_wiimote_groups.size(); i++)
{
@ -503,3 +537,40 @@ void WiimoteControllersWidget::SaveSettings()
SConfig::GetInstance().SaveSettings();
}
#if defined(_WIN32)
void WiimoteControllersWidget::AsyncRefreshActionHelper(std::invocable<> auto func)
{
m_wiimote_refresh->setEnabled(false);
m_wiimote_refresh_indicator->show();
auto result = std::async(std::launch::async, std::move(func));
auto* const animation = new QTimer{this};
connect(animation, &QTimer::timeout, this, [this, animation, result = std::move(result)] {
// Spin the refresh indicator.
m_wiimote_refresh_indicator->setPixmap(
m_wiimote_refresh_indicator->pixmap().transformed(QTransform().rotate(90)));
if (result.wait_for(std::chrono::seconds{}) != std::future_status::ready)
return;
// When the async task is done, re-enable the button and hide the indicator.
animation->deleteLater();
m_wiimote_refresh_indicator->hide();
m_wiimote_refresh->setEnabled(true);
});
animation->start(250);
}
void WiimoteControllersWidget::TriggerHostWiimoteSync()
{
AsyncRefreshActionHelper(WiimoteReal::WiimoteScannerWindows::FindAndAuthenticateWiimotes);
}
void WiimoteControllersWidget::TriggerHostWiimoteReset()
{
AsyncRefreshActionHelper(WiimoteReal::WiimoteScannerWindows::RemoveRememberedWiimotes);
}
#endif