Skip to content

Commit

Permalink
feat(swaybar-ipc): handle mode update
Browse files Browse the repository at this point in the history
  • Loading branch information
alebastr committed Sep 15, 2021
1 parent 858c107 commit 8edaf91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/modules/sway/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
17 changes: 16 additions & 1 deletion src/modules/sway/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8edaf91

Please sign in to comment.