Controller-gen should only return valid controllers.

This commit is contained in:
fewtarius 2024-02-08 12:54:50 +00:00
parent 0808fcb676
commit 3b4458caa8
No known key found for this signature in database
GPG key ID: F4AE55305D1B8C1A

View file

@ -7,7 +7,9 @@
int main()
{
SDL_Init(SDL_INIT_JOYSTICK);
SDL_GameControllerAddMappingsFromFile("/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt");
SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
atexit(SDL_Quit);
int num_joysticks = SDL_NumJoysticks();
@ -18,13 +20,17 @@ int main()
if (js)
{
SDL_JoystickGUID guid = SDL_JoystickGetGUID(js);
bool is_controller = SDL_IsGameController(i);
char guid_str[1024];
SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str));
const char* name = SDL_JoystickName(js);
printf("controlfolder=\"/storage/.config/gptokeyb\"\nESUDO=\"sudo\"\nESUDOKILL=\"-sudokill\"\nexport SDL_GAMECONTROLLERCONFIG_FILE=\"$controlfolder/gamecontrollerdb.txt\"\nSDLDBFILE=\"${SDL_GAMECONTROLLERCONFIG_FILE}\"\n[ -z \"${SDLDBFILE}\" ] && SDLDBFILE=\"${controlfolder}/gamecontrollerdb.txt\"\nSDLDBUSERFILE=\"/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt\"\nget_controls() {\nANALOGSTICKS=\"2\"\nDEVICE=\"%s\"\nparam_device=\"%s\"\n}\nGPTOKEYB=\"$controlfolder/gptokeyb $ESUDOKILL\"",
guid_str, name);
if (is_controller)
{
const char* name = SDL_JoystickName(js);
printf("controlfolder=\"/storage/.config/gptokeyb\"\nESUDO=\"sudo\"\nESUDOKILL=\"-sudokill\"\nexport SDL_GAMECONTROLLERCONFIG_FILE=\"$controlfolder/gamecontrollerdb.txt\"\nSDLDBFILE=\"${SDL_GAMECONTROLLERCONFIG_FILE}\"\n[ -z \"${SDLDBFILE}\" ] && SDLDBFILE=\"${controlfolder}/gamecontrollerdb.txt\"\nSDLDBUSERFILE=\"/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt\"\nget_controls() {\nANALOGSTICKS=\"2\"\nDEVICE=\"%s\"\nparam_device=\"%s\"\n}\nGPTOKEYB=\"$controlfolder/gptokeyb $ESUDOKILL\"",
guid_str, name);
}
SDL_JoystickClose(js);
}
}