Qt/Input: Keep configured device name in config when no pad is connected

This commit is contained in:
Megamouse 2024-01-13 23:21:42 +01:00
parent 9c11840e40
commit d7aedb439e
2 changed files with 24 additions and 6 deletions

View file

@ -1519,7 +1519,8 @@ void pad_settings_dialog::ChangeHandler()
ui->chooseDevice->setPlaceholderText(tr("No Device Detected"));
}
m_device_name.clear();
// Keep the configured device name
m_device_name = GetDeviceName();
}
// Handle running timers
@ -1611,11 +1612,7 @@ void pad_settings_dialog::ChangeDevice(int index)
}
const pad_device_info info = user_data.value<pad_device_info>();
m_device_name = info.name;
if (!g_cfg_input.player[GetPlayerIndex()]->device.from_string(m_device_name))
{
cfg_log.error("Failed to convert device string: %s", m_device_name);
}
SetDeviceName(info.name);
}
void pad_settings_dialog::HandleDeviceClassChange(u32 class_id) const
@ -1949,6 +1946,21 @@ cfg_pad& pad_settings_dialog::GetPlayerConfig() const
return g_cfg_input.player[GetPlayerIndex()]->config;
}
std::string pad_settings_dialog::GetDeviceName() const
{
return g_cfg_input.player[GetPlayerIndex()]->device.to_string();
}
void pad_settings_dialog::SetDeviceName(const std::string& name)
{
m_device_name = name;
if (!g_cfg_input.player[GetPlayerIndex()]->device.from_string(m_device_name))
{
cfg_log.error("Failed to convert device string: %s", m_device_name);
}
}
void pad_settings_dialog::ResizeDialog()
{
// Widgets

View file

@ -218,6 +218,12 @@ private:
/** Returns the current player config */
cfg_pad& GetPlayerConfig() const;
/** Sets the device name (member and config) */
void SetDeviceName(const std::string& name);
/** Gets the device name from config */
std::string GetDeviceName() const;
/** Resizes the dialog. We need to do this because the main scroll area can't determine the size on its own. */
void ResizeDialog();