Skip to content

Commit

Permalink
Cache the fact that a device didn't look like a joystick
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken authored and creichen committed Apr 10, 2022
1 parent 18a1e8a commit 3d01b14
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/joystick/linux/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ typedef struct SDL_joylist_item
/* Steam Controller support */
SDL_bool m_bSteamController;

SDL_bool checked_mapping;
SDL_GamepadMapping *mapping;
} SDL_joylist_item;

Expand Down Expand Up @@ -1573,9 +1574,13 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
SDL_Joystick *joystick;
SDL_joylist_item *item = JoystickByDevIndex(device_index);

if (item->mapping) {
SDL_memcpy(out, item->mapping, sizeof(*out));
return SDL_TRUE;
if (item->checked_mapping) {
if (item->mapping) {
SDL_memcpy(out, item->mapping, sizeof(*out));
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}

/* We temporarily open the device to check how it's configured. Make
Expand All @@ -1595,6 +1600,8 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
return SDL_FALSE;
}

item->checked_mapping = SDL_TRUE;

if (PrepareJoystickHwdata(joystick, item) == -1) {
SDL_free(joystick->hwdata);
SDL_free(joystick);
Expand Down

0 comments on commit 3d01b14

Please sign in to comment.