diff --git a/include/adapters/net.hpp b/include/adapters/net.hpp index ac966bba..4529ef3b 100644 --- a/include/adapters/net.hpp +++ b/include/adapters/net.hpp @@ -13,6 +13,7 @@ #include "common.hpp" #include "config.hpp" #include "errors.hpp" +#include "utils/math.hpp" POLYBAR_NS @@ -30,9 +31,10 @@ namespace net { int max{0}; int percentage() const { - if (max < 0) - return 2 * (val + 100); - return static_cast(val) / max * 100.0f + 0.5f; + if (val < 0) { + return std::max(std::min(std::abs(math_util::percentage(val, max, -20)), 100), 0); + } + return std::max(std::min(math_util::percentage(val, 0, max), 100), 0); } }; diff --git a/src/adapters/net.cpp b/src/adapters/net.cpp index 087fc644..33ed22d4 100644 --- a/src/adapters/net.cpp +++ b/src/adapters/net.cpp @@ -392,7 +392,7 @@ namespace net { // Check if the values are defined in dBm if (stats.qual.level > range.max_qual.level) { m_signalstrength.val -= 0x100; - m_signalstrength.max -= 0x100; + m_signalstrength.max = (stats.qual.level - range.max_qual.level) - 0x100; } } }