diff --git a/include/modules/network.hpp b/include/modules/network.hpp index 35ee4e69..b8a16245 100644 --- a/include/modules/network.hpp +++ b/include/modules/network.hpp @@ -31,6 +31,7 @@ namespace waybar::modules { Json::Value _config; std::size_t _ifid; std::string _essid; + int _signalStrengthdBm; int _signalStrength; }; diff --git a/resources/config b/resources/config index fe53e63d..2bdc8738 100644 --- a/resources/config +++ b/resources/config @@ -12,7 +12,7 @@ }, "network": { "interface": "wlp2s0", - "format": "{essid} ({signalStrength}dBm) " + "format": "{essid} ({signalStrength}%) " }, "pulseaudio": { "format": "{}% ", diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 23f4d0bb..6be39975 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -18,6 +18,7 @@ auto waybar::modules::Network::update() -> void auto format = _config["format"] ? _config["format"].asString() : "{}"; _label.set_text(fmt::format(format, fmt::arg("essid", _essid), + fmt::arg("signaldBm", _signalStrengthdBm), fmt::arg("signalStrength", _signalStrength) )); } @@ -75,8 +76,14 @@ void waybar::modules::Network::_parseEssid(struct nlattr **bss) void waybar::modules::Network::_parseSignal(struct nlattr **bss) { if (bss[NL80211_BSS_SIGNAL_MBM] != nullptr) { // signalstrength in dBm - _signalStrength = + _signalStrengthdBm = static_cast(nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM])) / 100; + + // WiFi-hardware usually operates in the range -90 to -20dBm. + const int hardwareMax = -20; + const int hardwareMin = -90; + _signalStrength = ((double)(_signalStrengthdBm - hardwareMin) + / (double)(hardwareMax - hardwareMin)) * 100; } }