Merge pull request #146 from Alexays/network_alt

fix(Network): format-alt
This commit is contained in:
Alex 2019-01-14 09:05:52 +01:00 committed by GitHub
commit aedf133b16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 12 deletions

View File

@ -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

View File

@ -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_;

View File

@ -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_),