libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.92k stars 1.84k forks source link

[Windows 10] Most joystick events do not show up unless initalized with SDL_INIT_VIDEO #10576

Open weirddan455 opened 2 months ago

weirddan455 commented 2 months ago

Tested with an Xbox One S controller on Windows 10. For some reason, only my trigger button events show up (axis 4 and axis 5 for this controller). Other buttons and axes do not generate events when pressed.

Linux does not have this issue. All buttons and axes show up correctly even without the video being initialized.

Reproduction case follows. Replacing the first line with SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK); allows all buttons and axes to generate events.

#include <SDL2/SDL.h>

int main(int argc, char *argv[])
{
    SDL_Init(SDL_INIT_JOYSTICK);
    SDL_JoystickOpen(0);

    SDL_Event event;
    while (SDL_WaitEvent(&event)) {
        switch(event.type) {
            case SDL_QUIT:
                return 0;
            case SDL_JOYAXISMOTION:
                printf("Axis %hhu: %hd\n", event.jaxis.axis, event.jaxis.value);
                break;
            default:
                printf("Event: %u\n", event.type);
        }
    }
}
slouken commented 2 months ago

Try setting SDL_HINT_JOYSTICK_THREAD?

Levi-Lesches commented 1 month ago

Can reproduce this and I can also confirm that adding the hint fixes that.

@slouken, why is that? The only documentation I have found is that this processes events on a new thread, but nothing on why events can't be processed on Windows without it. I have tried manually calling updateGamepad, PollEvent, and PumpEvents() to no luck, only adding _INIT_VIDEO or the THREAD hint as you mentioned actually work.

I can also confirm this works on Linux without video or the hint as well