From 8edaf917923829a502a2eef793ca8e111ab87554 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Wed, 15 Sep 2021 22:39:51 +0700 Subject: [PATCH] feat(swaybar-ipc): handle mode update --- include/modules/sway/bar.hpp | 2 +- src/modules/sway/bar.cpp | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/modules/sway/bar.hpp b/include/modules/sway/bar.hpp index 1008ec8cb1..6a3ca2a87d 100644 --- a/include/modules/sway/bar.hpp +++ b/include/modules/sway/bar.hpp @@ -33,7 +33,7 @@ class BarIpcClient { void onConfigUpdate(const swaybar_config& config); void onVisibilityUpdate(bool visible_by_modifier); - const Client& client_; + Client& client_; const std::string bar_id_; util::JsonParser parser_; Ipc ipc_; diff --git a/src/modules/sway/bar.cpp b/src/modules/sway/bar.cpp index cc6613265c..f98e458322 100644 --- a/src/modules/sway/bar.cpp +++ b/src/modules/sway/bar.cpp @@ -48,6 +48,16 @@ struct swaybar_config parseConfig(const Json::Value& payload) { return conf; } +void updateConfig(Json::Value& dst, const swaybar_config& src) { + if (dst.isArray()) { + for (auto& obj : dst) { + obj["mode"] = src.mode; + } + } else { + dst["mode"] = src.mode; + } +} + void BarIpcClient::onInitialConfig(const struct Ipc::ipc_response& res) { try { auto payload = parser_.parse(res.payload); @@ -81,7 +91,12 @@ void BarIpcClient::onIpcEvent(const struct Ipc::ipc_response& res) { void BarIpcClient::onConfigUpdate(const swaybar_config& config) { spdlog::info("config update: {} {} {}", config.id, config.mode, config.position); - // TODO: pass config to bars + // update config for future bar instances + updateConfig(client_.config.getConfig(), config); + // update existing bar instances + for (auto& bar : client_.bars) { + bar->setMode(config.mode); + } } void BarIpcClient::onVisibilityUpdate(bool visible_by_modifier) {