From 7d78b7f6baccba5539d6195a11bc2f546e8f8347 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Fri, 27 Jun 2025 17:15:28 +0200 Subject: [PATCH] fix for combobox bounce --- client/simulator_base.cpp | 7 +++++++ client/simulator_base.hpp | 1 + client/web_socket_wrapper.cpp | 13 +++++++++++++ client/web_socket_wrapper.hpp | 2 ++ 4 files changed, 23 insertions(+) diff --git a/client/simulator_base.cpp b/client/simulator_base.cpp index 870f217..aac27c8 100644 --- a/client/simulator_base.cpp +++ b/client/simulator_base.cpp @@ -33,11 +33,13 @@ void Simulator_base::showEvent(QShowEvent *event) { QWidget::showEvent(event); SPDLOG_DEBUG("Connecting callbacks"); + m_first_load = true; connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json &j) { on_cmd_cb(j); }); connect(m_web_socket, &Web_socket_wrapper::on_event_cb, this, [=, this](json &j) { on_event_cb(j); }); connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this] { m_error_dialog->open(); }); + m_web_socket->inhibit_events(true); m_web_socket->send_command(Web_socket_wrapper::Command::get_UI_elements); this->m_timer_update->start(m_refresh_rate); m_open = true; @@ -69,6 +71,11 @@ void Simulator_base::on_cmd_cb(json &j) default: break; } + if (m_first_load) + { + m_web_socket->inhibit_events(false); + m_first_load = false; + } } void Simulator_base::on_event_cb(json &j) diff --git a/client/simulator_base.hpp b/client/simulator_base.hpp index 360d8cf..1d96a9c 100644 --- a/client/simulator_base.hpp +++ b/client/simulator_base.hpp @@ -83,6 +83,7 @@ class Simulator_base : public QMainWindow uint32_t m_refresh_rate; NetworkError *m_error_dialog; bool m_open = false; + bool m_first_load = true; std::vector m_ui_lookup; }; diff --git a/client/web_socket_wrapper.cpp b/client/web_socket_wrapper.cpp index d4edc6c..b03876c 100644 --- a/client/web_socket_wrapper.cpp +++ b/client/web_socket_wrapper.cpp @@ -70,6 +70,8 @@ void Web_socket_wrapper::send_command(Command command, QString id) void Web_socket_wrapper::send_event(Event event, size_t id) { + if (m_inhibit_events) + return; json j; switch (event) { @@ -86,6 +88,8 @@ void Web_socket_wrapper::send_event(Event event, size_t id) void Web_socket_wrapper::send_event(Event event, size_t id, double val) { + if (m_inhibit_events) + return; json j; switch (event) { @@ -102,6 +106,8 @@ void Web_socket_wrapper::send_event(Event event, size_t id, double val) void Web_socket_wrapper::send_event(Event event, size_t id, QString val) { + if (m_inhibit_events) + return; json j; switch (event) { @@ -124,6 +130,8 @@ void Web_socket_wrapper::send_event(Event event, size_t id, QString val) void Web_socket_wrapper::send_event(Event event, size_t id, uint32_t sid, uint8_t dlc, std::array payload) { + if (m_inhibit_events) + return; json j; switch (event) { @@ -189,3 +197,8 @@ void Web_socket_wrapper::m_on_pong_timeout() m_web_socket->close(); emit on_closed(); } + +void Web_socket_wrapper::inhibit_events(bool inhibit) +{ + m_inhibit_events = inhibit; +} diff --git a/client/web_socket_wrapper.hpp b/client/web_socket_wrapper.hpp index 296dd83..ca070fc 100644 --- a/client/web_socket_wrapper.hpp +++ b/client/web_socket_wrapper.hpp @@ -44,6 +44,7 @@ class Web_socket_wrapper : public QObject void send_event(Event event, size_t id, QString val); void send_event(Event event, size_t id, uint32_t sid, uint8_t dlc, std::array payload); void close(); + void inhibit_events(bool inhibit); Q_SIGNALS: void on_connected(); @@ -59,6 +60,7 @@ class Web_socket_wrapper : public QObject private: bool m_connected = false; + bool m_inhibit_events = false; QWebSocket *m_web_socket; QTimer *m_ping_timer; QTimer *m_pong_timer;