RMG-Input: fix handling InputProfileDB with automatic device

This commit is contained in:
Rosalie Wanders
2025-10-19 16:51:21 +02:00
parent c991721faf
commit 5ccf15b852
3 changed files with 19 additions and 20 deletions
@@ -128,14 +128,14 @@ void MainDialog::openInputDevice(InputDevice device)
{
Widget::ControllerWidget* controllerWidget;
controllerWidget = this->controllerWidgets.at(this->tabWidget->currentIndex());
InputProfileDBEntry inputProfile = {};
// we don't need to open a non-joystick device
if (device.type != InputDeviceType::Automatic &&
device.type != InputDeviceType::Joystick)
{
this->currentDevice = { };
controllerWidget->SetCurrentJoystickID(this->currentDevice.id);
controllerWidget->SetCurrentJoystick(nullptr, nullptr);
controllerWidget->SetCurrentInputDevice(this->currentDevice.id, nullptr, nullptr, inputProfile);
return;
}
@@ -146,12 +146,12 @@ void MainDialog::openInputDevice(InputDevice device)
if (currentIndex < this->inputDeviceList.size())
{ // use device when there's one
device.id = this->inputDeviceList.at(currentIndex).id;
inputProfile = this->inputProfileDB.FindEntry(this->inputDeviceList.at(currentIndex));
}
else
{ // no device found, fallback to keyboard
this->currentDevice = { InputDeviceType::Keyboard, "Keyboard" };
controllerWidget->SetCurrentJoystickID(this->currentDevice.id);
controllerWidget->SetCurrentJoystick(nullptr, nullptr);
controllerWidget->SetCurrentInputDevice(this->currentDevice.id, nullptr, nullptr, inputProfile);
return;
}
}
@@ -170,9 +170,7 @@ void MainDialog::openInputDevice(InputDevice device)
}
this->currentDevice = device;
controllerWidget->SetCurrentJoystickID(device.id);
controllerWidget->SetIsCurrentJoystickGamepad(currentGamepad != nullptr);
controllerWidget->SetCurrentJoystick(this->currentJoystick, this->currentGamepad);
controllerWidget->SetCurrentInputDevice(device.id, this->currentJoystick, this->currentGamepad, inputProfile);
}
void MainDialog::closeInputDevice()
@@ -2025,23 +2025,25 @@ void ControllerWidget::RevertSettings()
}
}
void ControllerWidget::SetCurrentJoystickID(SDL_JoystickID joystickId)
void ControllerWidget::SetCurrentInputDevice(SDL_JoystickID joystickId, SDL_Joystick* joystick,
SDL_Gamepad* gamepad, const InputProfileDBEntry& inputProfile)
{
this->currentJoystickId = joystickId;
}
void ControllerWidget::SetIsCurrentJoystickGamepad(bool isGamepad)
{
this->isCurrentJoystickGamepad = isGamepad;
}
void ControllerWidget::SetCurrentJoystick(SDL_Joystick* joystick, SDL_Gamepad* gamepad)
{
this->currentJoystick = joystick;
this->currentGamepad = gamepad;
this->isCurrentJoystickGamepad = (gamepad != nullptr);
// we can enable the auto-configure button when we have a gamepad
this->autoConfigButton->setEnabled(gamepad != nullptr);
// update input profile when needed
if (inputProfile.valid)
{
int currentIndex = this->inputDeviceComboBox->currentIndex();
inputDeviceData deviceData = this->inputDeviceComboBox->itemData(currentIndex).value<inputDeviceData>();
deviceData.inputProfile = inputProfile;
this->inputDeviceComboBox->setItemData(currentIndex, QVariant::fromValue<inputDeviceData>(deviceData));
}
}
void ControllerWidget::AddUserProfile(QString name, QString section)
@@ -159,9 +159,8 @@ public:
void RevertSettings();
void SetCurrentJoystickID(SDL_JoystickID joystickId);
void SetIsCurrentJoystickGamepad(bool isGamepad);
void SetCurrentJoystick(SDL_Joystick* joystick, SDL_Gamepad* gamepad);
void SetCurrentInputDevice(SDL_JoystickID joystickId, SDL_Joystick* joystick,
SDL_Gamepad* gamepad, const InputProfileDBEntry& inputProfile);
void AddUserProfile(QString name, QString section);
void RemoveUserProfile(QString name, QString section);