Switch 2 Pro Controller over USB: turn on SDL's HIDAPI libusb backend

Aperta Adatta ai principianti
#522 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cmake
Ambito
build-system

Direzione di ricerca

Inizia da runtime/cmake/gfx_deps.cmake e dalle opzioni SDL vicino a set(SDL_VENDOR_INFO ...); l’issue specifica le tre opzioni da abilitare prima di FetchContent_MakeAvailable(...). Controlla come la configurazione fornisce gli header e la libreria di importazione di libusb 1.0 e come make-release.ps1 raccoglie i file di runtime. Il lavoro è completato quando la build Windows rileva il controller collegato via USB e il pacchetto di rilascio include la DLL libusb richiesta e la licenza.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
What you would like

On Windows, a Switch 2 Pro Controller (USB 057e:2069) connected by USB cable is not picked up. SDL 3.4.18 already has a driver for it (SDL_hidapi_switch2.c), but on Windows it reaches the controller through its libusb path, and that path is off in Recompia's SDL build.

Turning it on works. Add three lines to runtime/cmake/gfx_deps.cmake. Anywhere among the other SDL options works, as long as they come before FetchContent_MakeAvailable(...). We put them after set(SDL_VENDOR_INFO ...):

set(SDL_HIDAPI ON CACHE BOOL "" FORCE)
set(SDL_HIDAPI_LIBUSB ON CACHE BOOL "" FORCE)
set(SDL_HIDAPI_LIBUSB_SHARED ON CACHE BOOL "" FORCE)

The configure step also needs libusb 1.0 headers and an import library (LibUSB_INCLUDE_PATH, LibUSB_LIBRARY), and libusb-1.0.dll goes next to pkp.exe. With _SHARED, SDL loads libusb-1.0.dll at run time, so pkp_rt.dll's import table stays the same as today.

We rebuilt pkp_rt.dll from v0.10.3 with only these lines and libusb 1.0.30, then did the same with v0.10.4-beta.1. On Windows 11, with the Switch 2 Pro Controller connected by USB cable and Steam closed:

  • With the change, on both: gamepad 4 added: "Nintendo Switch Pro Controller" kind=Switch rumble=1 gyro=1. Switch button prompts show and the controls work. The beta's new capabilities line also shows gamepad 4 caps: type=7 real_type=7 vid=057e pid=2069 ....
  • With v0.10.4-beta.1's own release pkp_rt.dll, same PC and controller: no gamepad ... added line, and the prompts stay on keyboard.
Anything else

The release package would need libusb-1.0.dll and its licence (LGPL-2.1). make-release.ps1 takes files like that from the base package, so packaging is your call. This covers USB only, not Bluetooth.

Recommended as a precaution: ship libusb-1.0.dll in the same folder as pkp.exe rather than leaving it to the player's system. SDL loads it by name only (LoadLibraryW("libusb-1.0.dll")), so Windows looks next to the exe first, then the system folders, then PATH. Without a bundled copy, another program's libusb-1.0.dll on PATH could get loaded instead.

This change and its testing were done with the help of Claude (the AI assistant); the build and controller tests were run on real hardware.

Before you send
  • I searched the open and closed issues and this is not already requested.
Lingua principale
C++
Stelle
224
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di featureJosh/Recompia

Tutte le issue di featureJosh/Recompia

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.