From eace8c549fd5b0506435bf2bcadad0fd303d2e57 Mon Sep 17 00:00:00 2001 From: Alexis Date: Sun, 13 Jan 2019 22:36:37 +0100 Subject: [PATCH] fix(Network): format-alt --- include/ALabel.hpp | 4 ++-- src/ALabel.cpp | 4 ++-- src/modules/network.cpp | 21 +++++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index 17b3ebdc..b4d79bec 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -23,12 +23,12 @@ protected: std::string format_; std::mutex mutex_; const std::chrono::seconds interval_; + bool alt_ = false; + std::string default_format_; private: bool handleToggle(GdkEventButton *const &ev); bool handleScroll(GdkEventScroll *); - bool alt = false; - const std::string default_format_; }; } // namespace waybar diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 668d143b..8b7cdc19 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -43,8 +43,8 @@ bool waybar::ALabel::handleToggle(GdkEventButton* const& e) { } else if (config_["on-click-right"].isString() && e->button == 3) { waybar::util::command::forkExec(config_["on-click-right"].asString()); } else { - alt = !alt; - if (alt) { + alt_ = !alt_; + if (alt_) { format_ = config_["format-alt"].asString(); } else { format_ = default_format_; diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 2f5da617..ea3a16c6 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -135,26 +135,31 @@ void waybar::modules::Network::worker() auto waybar::modules::Network::update() -> void { - auto format = format_; std::string connectiontype; if (ifid_ <= 0 || ipaddr_.empty()) { - format = config_["format-disconnected"].isString() - ? config_["format-disconnected"].asString() : format; + if (config_["format-disconnected"].isString()) { + default_format_ = config_["format-disconnected"].asString(); + } label_.get_style_context()->add_class("disconnected"); connectiontype = "disconnected"; } else { if (essid_.empty()) { - format = config_["format-ethernet"].isString() - ? config_["format-ethernet"].asString() : format; + if (config_["format-ethernet"].isString()) { + default_format_ = config_["format-ethernet"].asString(); + } connectiontype = "ethernet"; } else { - format = config_["format-wifi"].isString() - ? config_["format-wifi"].asString() : format; + if (config_["format-wifi"].isString()) { + default_format_ = config_["format-wifi"].asString(); + } connectiontype = "wifi"; } label_.get_style_context()->remove_class("disconnected"); } - label_.set_markup(fmt::format(format, + if (!alt_) { + format_ = default_format_; + } + label_.set_markup(fmt::format(format_, fmt::arg("essid", essid_), fmt::arg("signaldBm", signal_strength_dbm_), fmt::arg("signalStrength", signal_strength_),