Qt/input: Do not send gui input release events until there was at least one button press

This commit is contained in:
Megamouse 2026-03-23 18:35:58 +01:00
parent 53c33cd812
commit 6a89764516
2 changed files with 14 additions and 4 deletions

View File

@ -109,9 +109,8 @@ bool gui_pad_thread::init()
{
m_handler.reset();
m_pad.reset();
m_last_button_state.clear();
// Initialize last button states as pressed to avoid unwanted button presses when starting the thread.
m_last_button_state.fill(true);
m_timestamp = steady_clock::now();
m_initial_timestamp = steady_clock::now();
m_last_auto_repeat_button = pad_button::pad_button_max_enum;
@ -412,7 +411,18 @@ void gui_pad_thread::process_input()
return;
}
bool& last_state = m_last_button_state[static_cast<u32>(button_id)];
if (!m_last_button_state.contains(button_id))
{
// Ignore button presses and releases if there was no release detected at least once.
if (!pressed)
{
m_last_button_state[button_id] = false;
}
return;
}
bool& last_state = m_last_button_state[button_id];
if (pressed)
{

View File

@ -65,7 +65,7 @@ protected:
atomic_t<bool> m_allow_global_input = false;
static atomic_t<bool> m_reset;
std::array<bool, static_cast<u32>(pad_button::pad_button_max_enum)> m_last_button_state{};
std::map<pad_button, bool> m_last_button_state{};
steady_clock::time_point m_timestamp;
steady_clock::time_point m_initial_timestamp;