Skip to content

Commit

Permalink
The sway/hide module is now limited to the bar passed by the construc…
Browse files Browse the repository at this point in the history
…tor.
  • Loading branch information
emirror-de committed Sep 15, 2021
1 parent c11aecd commit 73de008
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
6 changes: 3 additions & 3 deletions include/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,21 +605,21 @@ 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 {
window.get_style_context()->remove_class("hidden");
}
}

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();
}

Expand Down
34 changes: 15 additions & 19 deletions src/modules/sway/hide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mutex_);
mutex_.lock();
auto &bar = const_cast<Bar &>(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() {
Expand Down

0 comments on commit 73de008

Please sign in to comment.