mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-08-31 10:36:56 +00:00
[input_common] Fix GetButtonMappingForDevice() when joystick doesn't have a gamepad associated with it (#4172)
from PS4 PR - this should help fix the case where a controller doesn't have an associated gamepad and thus its not automatically configured. this should fix that :) Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4172 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
This commit is contained in:
@@ -948,34 +948,39 @@ ButtonMapping SDLDriver::GetButtonMappingForDevice(const Common::ParamPackage& p
|
|||||||
}
|
}
|
||||||
const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
|
const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
|
||||||
|
|
||||||
auto* controller = joystick->GetSDLGameController();
|
|
||||||
if (controller == nullptr) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// This list is missing ZL/ZR since those are not considered buttons in SDL GameController.
|
// This list is missing ZL/ZR since those are not considered buttons in SDL GameController.
|
||||||
// We will add those afterwards
|
// We will add those afterwards
|
||||||
ButtonBindings switch_to_sdl_button;
|
ButtonBindings switch_to_sdl_button = GetDefaultButtonBinding(joystick);
|
||||||
|
|
||||||
switch_to_sdl_button = GetDefaultButtonBinding(joystick);
|
|
||||||
|
|
||||||
// Add the missing bindings for ZL/ZR
|
// Add the missing bindings for ZL/ZR
|
||||||
static constexpr ZButtonBindings switch_to_sdl_axis{{
|
static constexpr ZButtonBindings switch_to_sdl_axis{{
|
||||||
{Settings::NativeButton::ZL, SDL_GAMEPAD_AXIS_LEFT_TRIGGER},
|
{Settings::NativeButton::ZL, SDL_GAMEPAD_AXIS_LEFT_TRIGGER},
|
||||||
{Settings::NativeButton::ZR, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER},
|
{Settings::NativeButton::ZR, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER},
|
||||||
}};
|
}};
|
||||||
|
if (auto* controller = joystick->GetSDLGameController(); controller) {
|
||||||
// Parameters contain two joysticks return dual
|
// Parameters contain two joysticks return dual
|
||||||
if (params.Has("guid2")) {
|
if (params.Has("guid2")) {
|
||||||
const auto joystick2 = GetSDLJoystickByGUID(params.Get("guid2", ""), params.Get("port", 0));
|
const auto joystick2 = GetSDLJoystickByGUID(params.Get("guid2", ""), params.Get("port", 0));
|
||||||
|
if (joystick2->GetSDLGameController())
|
||||||
if (joystick2->GetSDLGameController() != nullptr) {
|
return GetDualControllerMapping(joystick, joystick2, switch_to_sdl_button, switch_to_sdl_axis);
|
||||||
return GetDualControllerMapping(joystick, joystick2, switch_to_sdl_button,
|
|
||||||
switch_to_sdl_axis);
|
|
||||||
}
|
}
|
||||||
|
return GetSingleControllerMapping(joystick, switch_to_sdl_button, switch_to_sdl_axis);
|
||||||
}
|
}
|
||||||
|
// Default mappings for when the controller doesn't have an associated gamepad
|
||||||
return GetSingleControllerMapping(joystick, switch_to_sdl_button, switch_to_sdl_axis);
|
// This fixes issues where SDL uses a backend which doesn't support gamepad remappings
|
||||||
|
ButtonMapping mapping;
|
||||||
|
for (const auto& pair : switch_to_sdl_button) {
|
||||||
|
SDL_GamepadBinding binding{};
|
||||||
|
binding.input_type = SDL_GAMEPAD_BINDTYPE_BUTTON;
|
||||||
|
binding.input.button = pair.second;
|
||||||
|
mapping.insert_or_assign(pair.first, BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding));
|
||||||
|
}
|
||||||
|
for (const auto& pair : switch_to_sdl_axis) {
|
||||||
|
SDL_GamepadBinding binding{};
|
||||||
|
binding.input_type = SDL_GAMEPAD_BINDTYPE_AXIS;
|
||||||
|
binding.input.axis.axis = pair.second;
|
||||||
|
mapping.insert_or_assign(pair.first, BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding));
|
||||||
|
}
|
||||||
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonBindings SDLDriver::GetDefaultButtonBinding(
|
ButtonBindings SDLDriver::GetDefaultButtonBinding(
|
||||||
|
|||||||
Reference in New Issue
Block a user