From ebdeb8670310e1e4308a457be04829ba11d2b156 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 19 Oct 2020 19:35:55 -0700 Subject: [PATCH] feat(swaybar-ipc): handle visibility_by_modifier update --- include/modules/sway/bar.hpp | 2 ++ src/modules/sway/bar.cpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/modules/sway/bar.hpp b/include/modules/sway/bar.hpp index e32dee4a..d3a697c3 100644 --- a/include/modules/sway/bar.hpp +++ b/include/modules/sway/bar.hpp @@ -33,12 +33,14 @@ class BarIpcClient { void onIpcEvent(const struct Ipc::ipc_response&); void onConfigUpdate(const swaybar_config& config); void onVisibilityUpdate(bool visible_by_modifier); + void update(); Bar& bar_; util::JsonParser parser_; Ipc ipc_; swaybar_config bar_config_; + bool visible_by_modifier_ = false; SafeSignal signal_visible_; SafeSignal signal_config_; diff --git a/src/modules/sway/bar.cpp b/src/modules/sway/bar.cpp index 3179221c..7cae4baf 100644 --- a/src/modules/sway/bar.cpp +++ b/src/modules/sway/bar.cpp @@ -82,12 +82,23 @@ 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); bar_config_ = config; - bar_.setMode(bar_config_.mode); + update(); } void BarIpcClient::onVisibilityUpdate(bool visible_by_modifier) { spdlog::trace("visiblity update: {}", visible_by_modifier); - // TODO: pass visibility to bars + visible_by_modifier_ = visible_by_modifier; + update(); +} + +void BarIpcClient::update() { + bool visible = visible_by_modifier_; + if (bar_config_.mode == "invisible") { + visible = false; + } else if (bar_config_.mode != "hide" || bar_config_.hidden_state != "hide") { + visible = true; + } + bar_.setMode(visible ? bar_config_.mode : Bar::MODE_INVISIBLE); } } // namespace waybar::modules::sway