libsdl-org / SDL

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

Gamepad not recognized by SDL but via Linux and gtk #10281

Closed Citrodata closed 1 month ago

Citrodata commented 1 month ago

OS: Manjaro (Linux) SDL Version: 2.30.3 Kernel: 6.8.12-3-MANJARO

Controller got recognized by gamepad-tool. Its a normal Xbox 360 Controller. GUID String 03000c3a5e0400008e02000010016800,Xbox 360 Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,crc:3a0c,platform:Linux

Used this code to check if its found

#include <stdio.h>
#include <SDL2/SDL.h>

int main() {

    printf("Initializing SDL...\n");

        if (SDL_Init( SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK ) < 0) {
                fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
                exit(1);
        }

                printf("SDL initialized.\n");
                SDL_GameControllerAddMappingsFromFile("/home/max/gamecontrollerdb.txt");

        printf("%i joysticks were found.\n\n", SDL_NumJoysticks() );
        printf("The names of the joysticks are:\n");

        SDL_GameController *controller = NULL;
        for(int i=0; i < SDL_NumJoysticks(); i++ ) {

                SDL_Joystick *joystick = SDL_JoystickOpen(i);
                printf("%s\n\n", SDL_JoystickName(joystick));
                SDL_JoystickClose(joystick);

                printf("IsGameController: %i\n",SDL_IsGameController(i));

                SDL_GameController *controller = NULL;
                controller = SDL_GameControllerOpen(i);
                if (controller) {
                        printf("GameControllerName: %s\n",SDL_GameControllerName(controller));
                        SDL_GameControllerClose(controller);
                        controller = NULL;
                } else {
                        printf("Failed to open GameController %i\n",i);
                }
        }

    printf("Quitting SDL...\n");
        SDL_Quit();

        return 0;
}

SDL_NumJoysticks returns 0 and even when I load SDL_GameControllerAddMappingsFromFile with the GUID entry its still shows 0.

slouken commented 1 month ago

It seems like this should work. Have you tried debugging to see what's going on?

Citrodata commented 1 month ago

Okay after upgrading my Distro's SDL version to 2.30.5 its works now again. Maybe just a weird buk with Manjaro. Sorry to bother you guys.