Add custom tooltip format for network module

This commit is contained in:
Jonas 2019-03-03 21:35:35 +01:00
parent 7e4fed8218
commit a9f680b06e
1 changed files with 36 additions and 5 deletions

View File

@ -135,10 +135,17 @@ void waybar::modules::Network::worker()
auto waybar::modules::Network::update() -> void auto waybar::modules::Network::update() -> void
{ {
std::string connectiontype; std::string connectiontype;
std::string tooltip_format = "";
if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString();
}
if (ifid_ <= 0 || ipaddr_.empty()) { if (ifid_ <= 0 || ipaddr_.empty()) {
if (config_["format-disconnected"].isString()) { if (config_["format-disconnected"].isString()) {
default_format_ = config_["format-disconnected"].asString(); default_format_ = config_["format-disconnected"].asString();
} }
if (config_["tooltip-format-disconnected"].isString()) {
tooltip_format = config_["tooltip-format-disconnected"].asString();
}
label_.get_style_context()->add_class("disconnected"); label_.get_style_context()->add_class("disconnected");
connectiontype = "disconnected"; connectiontype = "disconnected";
} else { } else {
@ -146,11 +153,17 @@ auto waybar::modules::Network::update() -> void
if (config_["format-ethernet"].isString()) { if (config_["format-ethernet"].isString()) {
default_format_ = config_["format-ethernet"].asString(); default_format_ = config_["format-ethernet"].asString();
} }
if (config_["tooltip-format-ethernet"].isString()) {
tooltip_format = config_["tooltip-format-ethernet"].asString();
}
connectiontype = "ethernet"; connectiontype = "ethernet";
} else { } else {
if (config_["format-wifi"].isString()) { if (config_["format-wifi"].isString()) {
default_format_ = config_["format-wifi"].asString(); default_format_ = config_["format-wifi"].asString();
} }
if (config_["tooltip-format-wifi"].isString()) {
tooltip_format = config_["tooltip-format-wifi"].asString();
}
connectiontype = "wifi"; connectiontype = "wifi";
} }
label_.get_style_context()->remove_class("disconnected"); label_.get_style_context()->remove_class("disconnected");
@ -158,7 +171,7 @@ auto waybar::modules::Network::update() -> void
if (!alt_) { if (!alt_) {
format_ = default_format_; format_ = default_format_;
} }
label_.set_markup(fmt::format(format_, auto text = 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_),
@ -167,7 +180,25 @@ auto waybar::modules::Network::update() -> void
fmt::arg("ipaddr", ipaddr_), fmt::arg("ipaddr", ipaddr_),
fmt::arg("cidr", cidr_), fmt::arg("cidr", cidr_),
fmt::arg("icon", getIcon(signal_strength_, connectiontype)) fmt::arg("icon", getIcon(signal_strength_, connectiontype))
)); );
label_.set_markup(text);
if (tooltipEnabled()) {
if (!tooltip_format.empty()) {
auto tooltip_text = fmt::format(tooltip_format,
fmt::arg("essid", essid_),
fmt::arg("signaldBm", signal_strength_dbm_),
fmt::arg("signalStrength", signal_strength_),
fmt::arg("ifname", ifname_),
fmt::arg("netmask", netmask_),
fmt::arg("ipaddr", ipaddr_),
fmt::arg("cidr", cidr_),
fmt::arg("icon", getIcon(signal_strength_, connectiontype))
);
label_.set_tooltip_text(tooltip_text);
} else {
label_.set_tooltip_text(text);
}
}
} }
void waybar::modules::Network::disconnected() void waybar::modules::Network::disconnected()