This commit is contained in:
Squall Leonhart 2026-04-04 19:33:54 -03:00 committed by GitHub
commit 5f85140070
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 12 deletions

View File

@ -76,6 +76,8 @@ add_library(CemuWxGui STATIC
input/InputAPIAddWindow.h
input/InputSettings2.cpp
input/InputSettings2.h
input/PairingDialog.cpp
input/PairingDialog.h
input/panels/ClassicControllerInputPanel.cpp
input/panels/ClassicControllerInputPanel.h
input/panels/InputPanel.cpp
@ -124,10 +126,11 @@ if (ENABLE_METAL)
endif()
if (ENABLE_BLUEZ)
target_sources(CemuWxGui PRIVATE
input/PairingDialog.cpp
input/PairingDialog.h
)
target_compile_definitions(CemuWxGui PRIVATE HAS_BLUEZ)
endif()
if (SUPPORTS_WIIMOTE)
target_compile_definitions(CemuWxGui PRIVATE SUPPORTS_WIIMOTE)
endif()
set_property(TARGET CemuWxGui PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

View File

@ -21,9 +21,7 @@
#include "wxgui/input/InputAPIAddWindow.h"
#include "input/ControllerFactory.h"
#ifdef HAS_BLUEZ
#include "wxgui/input/PairingDialog.h"
#endif
#include "wxgui/input/panels/VPADInputPanel.h"
#include "wxgui/input/panels/ProControllerInputPanel.h"
@ -257,14 +255,12 @@ wxWindow* InputSettings2::initialize_page(size_t index)
page_data.m_controller_api_remove = remove_api;
}
#ifdef HAS_BLUEZ
auto* pairingDialog = new wxButton(page, wxID_ANY, _("Pair Wii/Wii U Controller"));
pairingDialog->Bind(wxEVT_BUTTON, [this](wxEvent&) {
PairingDialog pairing_dialog(this);
pairing_dialog.ShowModal();
});
sizer->Add(pairingDialog, wxGBPosition(5, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxALL, 5);
#endif
// controller
auto* controller_bttns = new wxBoxSizer(wxHORIZONTAL);

View File

@ -4,7 +4,7 @@
#if BOOST_OS_WINDOWS
#include <bluetoothapis.h>
#endif
#if BOOST_OS_LINUX
#ifdef HAS_BLUEZ
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
@ -157,6 +157,7 @@ void PairingDialog::WorkerThread()
DWORD result = BluetoothGetRadioInfo(radio, &radioInfo);
if (result != ERROR_SUCCESS)
{
CloseHandle(radio);
UpdateCallback(PairingState::NoBluetoothAvailable);
return;
}
@ -165,8 +166,8 @@ void PairingDialog::WorkerThread()
{
.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS),
.fReturnAuthenticated = FALSE,
.fReturnRemembered = FALSE,
.fReturnAuthenticated = TRUE,
.fReturnRemembered = TRUE,
.fReturnUnknown = TRUE,
.fReturnConnected = FALSE,
@ -184,22 +185,51 @@ void PairingDialog::WorkerThread()
HBLUETOOTH_DEVICE_FIND deviceFind = BluetoothFindFirstDevice(&searchParams, &info);
if (deviceFind == nullptr)
{
CloseHandle(radio);
UpdateCallback(PairingState::SearchFailed);
return;
}
while (!m_threadShouldQuit)
{
if (info.szName == wiimoteName || info.szName == wiiUProControllerName)
if (wcscmp(info.szName, wiimoteName.c_str()) == 0 || wcscmp(info.szName, wiiUProControllerName.c_str()) == 0)
{
BluetoothFindDeviceClose(deviceFind);
if (info.fAuthenticated)
{
DWORD bthResult = BluetoothSetServiceState(radio, &info, &bthHidGuid, BLUETOOTH_SERVICE_ENABLE);
if (bthResult != ERROR_SUCCESS)
{
CloseHandle(radio);
UpdateCallback(PairingState::PairingFailed);
return;
}
CloseHandle(radio);
UpdateCallback(PairingState::Finished);
return;
}
if (info.fRemembered && !info.fAuthenticated)
{
BluetoothRemoveDevice(&info.Address);
Sleep(500);
}
UpdateCallback(PairingState::Pairing);
wchar_t passwd[6] = {radioInfo.address.rgBytes[0], radioInfo.address.rgBytes[1], radioInfo.address.rgBytes[2], radioInfo.address.rgBytes[3], radioInfo.address.rgBytes[4], radioInfo.address.rgBytes[5]};
DWORD bthResult = BluetoothAuthenticateDevice(nullptr, radio, &info, passwd, 6);
if (bthResult != ERROR_SUCCESS)
{
wchar_t passwd2[6] = {info.Address.rgBytes[0], info.Address.rgBytes[1], info.Address.rgBytes[2], info.Address.rgBytes[3], info.Address.rgBytes[4], info.Address.rgBytes[5]};
bthResult = BluetoothAuthenticateDevice(nullptr, radio, &info, passwd2, 6);
}
if (bthResult != ERROR_SUCCESS)
{
CloseHandle(radio);
UpdateCallback(PairingState::PairingFailed);
return;
}
@ -207,10 +237,12 @@ void PairingDialog::WorkerThread()
bthResult = BluetoothSetServiceState(radio, &info, &bthHidGuid, BLUETOOTH_SERVICE_ENABLE);
if (bthResult != ERROR_SUCCESS)
{
CloseHandle(radio);
UpdateCallback(PairingState::PairingFailed);
return;
}
CloseHandle(radio);
UpdateCallback(PairingState::Finished);
return;
}
@ -224,6 +256,8 @@ void PairingDialog::WorkerThread()
BluetoothFindDeviceClose(deviceFind);
}
CloseHandle(radio);
}
#elif defined(HAS_BLUEZ)
void PairingDialog::WorkerThread()