diff --git a/include/client.hpp b/include/client.hpp index c3df3f218..8598e3569 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -44,6 +44,7 @@ class Client { const char* interface, uint32_t version); static void handleGlobalRemove(void* data, struct wl_registry* registry, uint32_t name); static void handleOutputDone(void*, struct zxdg_output_v1*); + void createBarsBatch(); static void handleOutputName(void*, struct zxdg_output_v1*, const char*); static void handleOutputDescription(void*, struct zxdg_output_v1*, const char*); void handleMonitorAdded(Glib::RefPtr monitor); @@ -58,6 +59,8 @@ class Client { std::string m_cssFile; sigc::connection monitor_added_connection_; sigc::connection monitor_removed_connection_; + std::vector pending_outputs_; + bool bars_scheduled_ = false; }; } // namespace waybar diff --git a/src/client.cpp b/src/client.cpp index d14891867..ff354e180 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -91,16 +91,37 @@ void waybar::Client::handleOutputDone(void* data, struct zxdg_output_v1* /*xdg_o output.xdg_output.reset(); spdlog::debug("Output detection done: {} ({})", output.name, output.identifier); - auto configs = client->getOutputConfigs(output); + client->pending_outputs_.push_back(&output); + + if (!client->bars_scheduled_) { + client->bars_scheduled_ = true; + + Glib::signal_idle().connect_once([client]() { + client->createBarsBatch(); + }, Glib::PRIORITY_HIGH_IDLE); + } + } + } catch (const std::exception& e) { + spdlog::warn("caught exception in zxdg_output_v1_listener::done: {}", e.what()); + } +} + +void waybar::Client::createBarsBatch() { + for (auto* output : pending_outputs_) { + try { + auto configs = getOutputConfigs(*output); if (!configs.empty()) { for (const auto& config : configs) { - client->bars.emplace_back(std::make_unique(&output, config)); + bars.emplace_back(std::make_unique(output, config)); } } + } catch (const std::exception& e) { + spdlog::warn("Error creating bar: {}", e.what()); } - } catch (const std::exception& e) { - spdlog::warn("caught exception in zxdg_output_v1_listener::done: {}", e.what()); } + + pending_outputs_.clear(); + bars_scheduled_ = false; } void waybar::Client::handleOutputName(void* data, struct zxdg_output_v1* /*xdg_output*/,