Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Joystick hotplug support #4141
This is my take on adding joystick hotpluging to citra.
I had to remove the SDL_JoystickUpdate calls and add the SDL_PollEvent to catch the reconnect events. The SDL_PollEvent needs to be called from the main thread so I had to add that to the qt-main-loop.
I added States for all Button/Axes/Hats to the InputCommon::SDL::SDLJoystick class. The PollEvent will update those states from the main-thread. The HID-Service well GetStatus() from the citra thread to get the state of the mapped buttons/...
I also added the GameController support of SDL2. This will enable nice naming of the joysticks for the config ui. And in a follow up PR it is planned to add auto config of joysticks which will also require the GameController support.
I hope this explains all change I made.
Disclaimer: I never wrote stuff with SDL and also the input stuff for citra was new to me. So there might be issues I didn't catch. Please consider that while reviewing.
The index / instance ID model seems broken and I can't do further review because I am puzzled lol.
@wwylele So the first time you connect a joystick SDL will give the joystick a SDL_JoystickID. When you disconnect and reconnect the joystick the event.jdevice.which will use that same SDL_JoystickID again. But SDL_JoystickInstanceID() will return an updated number and all further events will use that updated number. The only event that will always use the inital SDL_JoystickID is the SDL_JOYDEVICEADDED event. Thus I store the init_id and the changing sdl_id in the VirtualJoystick class. The first one to tie it to the SDL_JOYDEVICEADDED events and the later to tie it to all other events. I hope that cleared it up a bit.
@CodingKoopa Yes. This Pr makes it necessary to configure the input again to work. I also changed what gets displayed in the input config tab. Instead of Joystick #num - Button #num it will now display #JoystickName (#num) - Button #num.
So the only real issue I see is that SetAnalog seems to be broken. I will look into that.
Sep 8, 2018
referenced this pull request
Sep 8, 2018
I'm having an issue that's apparently related to this feature. Canary builds after 793 will not open, but 793 and earlier will work normally. There are no error messages after running the citra-qt.exe at all, the program window just never appears and the log remains empty. If I continue clicking or hitting enter on the qt.exe rapidly for an extended period, the program will occasionally open and the log will be filled in with a few details (which I've attached).
While I can eventually open Citra in this way, I use Steam to enable support for the Switch Pro controller, and Steam does not seem to be able to open Citra at all. The issue opening Citra directly by clicking the exe persists whether Steam is running or not.
I've tried disabling Windows Defender, the only antivirus I have running, with no effect. I also tried removing the qt-config.ini file to see if Citra would open and generate a new one, but it continues to fail and does not generate a new config file when I attempt to open it.