Skip to content

Commit

Permalink
feat(swaybar-ipc): handle visibility_by_modifier update
Browse files Browse the repository at this point in the history
  • Loading branch information
alebastr committed Nov 21, 2021
1 parent a5ee087 commit 6a0abba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/modules/sway/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> signal_visible_;
SafeSignal<swaybar_config> signal_config_;
Expand Down
15 changes: 13 additions & 2 deletions src/modules/sway/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6a0abba

Please sign in to comment.