fix(Network): format-alt

This commit is contained in:
Alexis 2019-01-13 22:36:37 +01:00
parent f8116132a7
commit eace8c549f
3 changed files with 17 additions and 12 deletions

View File

@ -23,12 +23,12 @@ protected:
std::string format_; std::string format_;
std::mutex mutex_; std::mutex mutex_;
const std::chrono::seconds interval_; const std::chrono::seconds interval_;
bool alt_ = false;
std::string default_format_;
private: private:
bool handleToggle(GdkEventButton *const &ev); bool handleToggle(GdkEventButton *const &ev);
bool handleScroll(GdkEventScroll *); bool handleScroll(GdkEventScroll *);
bool alt = false;
const std::string default_format_;
}; };
} // namespace waybar } // namespace waybar

View File

@ -43,8 +43,8 @@ bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
} else if (config_["on-click-right"].isString() && e->button == 3) { } else if (config_["on-click-right"].isString() && e->button == 3) {
waybar::util::command::forkExec(config_["on-click-right"].asString()); waybar::util::command::forkExec(config_["on-click-right"].asString());
} else { } else {
alt = !alt; alt_ = !alt_;
if (alt) { if (alt_) {
format_ = config_["format-alt"].asString(); format_ = config_["format-alt"].asString();
} else { } else {
format_ = default_format_; format_ = default_format_;

View File

@ -135,26 +135,31 @@ void waybar::modules::Network::worker()
auto waybar::modules::Network::update() -> void auto waybar::modules::Network::update() -> void
{ {
auto format = format_;
std::string connectiontype; std::string connectiontype;
if (ifid_ <= 0 || ipaddr_.empty()) { if (ifid_ <= 0 || ipaddr_.empty()) {
format = config_["format-disconnected"].isString() if (config_["format-disconnected"].isString()) {
? config_["format-disconnected"].asString() : format; default_format_ = config_["format-disconnected"].asString();
}
label_.get_style_context()->add_class("disconnected"); label_.get_style_context()->add_class("disconnected");
connectiontype = "disconnected"; connectiontype = "disconnected";
} else { } else {
if (essid_.empty()) { if (essid_.empty()) {
format = config_["format-ethernet"].isString() if (config_["format-ethernet"].isString()) {
? config_["format-ethernet"].asString() : format; default_format_ = config_["format-ethernet"].asString();
}
connectiontype = "ethernet"; connectiontype = "ethernet";
} else { } else {
format = config_["format-wifi"].isString() if (config_["format-wifi"].isString()) {
? config_["format-wifi"].asString() : format; default_format_ = config_["format-wifi"].asString();
}
connectiontype = "wifi"; connectiontype = "wifi";
} }
label_.get_style_context()->remove_class("disconnected"); 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("essid", essid_),
fmt::arg("signaldBm", signal_strength_dbm_), fmt::arg("signaldBm", signal_strength_dbm_),
fmt::arg("signalStrength", signal_strength_), fmt::arg("signalStrength", signal_strength_),