From 73de008a6a67a4e3c41001130d47756fcdece151 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Wed, 15 Sep 2021 23:08:46 +0200 Subject: [PATCH] The sway/hide module is now limited to the bar passed by the constructor. --- include/bar.hpp | 6 +++--- src/bar.cpp | 8 ++++---- src/modules/sway/hide.cpp | 34 +++++++++++++++------------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 823a3eb6d..d40910195 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -59,9 +59,9 @@ class Bar { ~Bar() = default; void setVisible(bool visible); - void setHiddenClass(bool value); - void moveToTopLayer(); - void moveToBottomLayer(); + void setHiddenClass(bool value) const; + void moveToTopLayer() const; + void moveToConfiguredLayer() const; void toggle(); void setExclusive(bool value); void handleSignal(int); diff --git a/src/bar.cpp b/src/bar.cpp index ebaf0373c..8794177bf 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -605,7 +605,7 @@ void waybar::Bar::setVisible(bool value) { surface_impl_->commit(); } -void waybar::Bar::setHiddenClass(bool value) { +void waybar::Bar::setHiddenClass(bool value) const { if (value) { window.get_style_context()->add_class("hidden"); } else { @@ -613,13 +613,13 @@ void waybar::Bar::setHiddenClass(bool value) { } } -void waybar::Bar::moveToTopLayer() { +void waybar::Bar::moveToTopLayer() const { surface_impl_->setLayer(bar_layer::TOP); surface_impl_->commit(); } -void waybar::Bar::moveToBottomLayer() { - surface_impl_->setLayer(bar_layer::BOTTOM); +void waybar::Bar::moveToConfiguredLayer() const { + surface_impl_->setLayer(layer_); surface_impl_->commit(); } diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index ac616f473..83008d23f 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -15,37 +15,33 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) void Hide::onEvent(const struct Ipc::ipc_response& res) { auto payload = parser_.parse(res.payload); - std::lock_guard lock(mutex_); + mutex_.lock(); + auto &bar = const_cast(bar_); if (payload.isMember("mode")) { auto mode = payload["mode"].asString(); if (mode == "hide") { // Hide the bars when configuring the "hide" bar spdlog::debug("sway/hide: hiding bar(s)"); - for (auto& bar : waybar::Client::inst()->bars) { - bar->setVisible(false); - bar->setExclusive(false); - } + bar.setVisible(false); + bar.setExclusive(false); } else if (mode == "dock") { - spdlog::info("sway/hide: showing bar(s)"); - for (auto& bar : waybar::Client::inst()->bars) { - bar->setVisible(true); - bar->setExclusive(true); - } + spdlog::debug("sway/hide: showing bar(s)"); + bar.setVisible(true); + bar.setExclusive(true); } } else if (payload.isMember("visible_by_modifier")) { visible_by_modifier_ = payload["visible_by_modifier"].asBool(); spdlog::debug("sway/hide: visible by modifier: {}", visible_by_modifier_); - for (auto& bar : waybar::Client::inst()->bars) { - if (visible_by_modifier_) { - bar->setHiddenClass(false); - bar->moveToTopLayer(); - } else { - bar->setHiddenClass(true); - bar->moveToBottomLayer(); - bar->setExclusive(false); - } + if (visible_by_modifier_) { + bar.setHiddenClass(false); + bar.moveToTopLayer(); + } else { + bar.setHiddenClass(true); + bar.moveToConfiguredLayer(); + bar.setExclusive(false); } } + mutex_.unlock(); } void Hide::worker() {