Merge pull request #5015 from yui-915/compact-bandwidth

feat: add compact versions of bandwidthBytes to network module
This commit is contained in:
Alexis Rouillard
2026-07-03 22:42:22 +02:00
committed by GitHub
2 changed files with 13 additions and 3 deletions
+5 -3
View File
@@ -5,12 +5,13 @@
class pow_format { class pow_format {
public: public:
pow_format(long long val, std::string&& unit, bool binary = false) pow_format(long long val, std::string&& unit, bool binary = false, int min_pow_for_decimal = 0)
: val_(val), unit_(unit), binary_(binary) {}; : val_(val), unit_(unit), binary_(binary), min_pow_for_decimal_(min_pow_for_decimal) {};
long long val_; long long val_;
std::string unit_; std::string unit_;
bool binary_; bool binary_;
int min_pow_for_decimal_;
}; };
namespace fmt { namespace fmt {
@@ -74,7 +75,8 @@ struct formatter<pow_format> {
break; break;
case 0: case 0:
default: default:
format = "{coefficient:.1f}{prefix}{unit}"; format = pow < s.min_pow_for_decimal_ ? "{coefficient:.0f}{prefix}{unit}"
: "{coefficient:.1f}{prefix}{unit}";
break; break;
} }
return fmt::format_to( return fmt::format_to(
+8
View File
@@ -368,6 +368,10 @@ auto waybar::modules::Network::update() -> void {
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "o/s")), pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "o/s")),
fmt::arg("bandwidthDownBytes", pow_format(bandwidth_down / elapsed_seconds, "B/s")), fmt::arg("bandwidthDownBytes", pow_format(bandwidth_down / elapsed_seconds, "B/s")),
fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / elapsed_seconds, "B/s")), fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / elapsed_seconds, "B/s")),
fmt::arg("bandwidthDownBytesCompact",
pow_format(bandwidth_down / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthUpBytesCompact",
pow_format(bandwidth_up / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthTotalBytes", fmt::arg("bandwidthTotalBytes",
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "B/s"))); pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "B/s")));
if (text.compare(label_.get_label()) != 0) { if (text.compare(label_.get_label()) != 0) {
@@ -401,6 +405,10 @@ auto waybar::modules::Network::update() -> void {
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "o/s")), pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "o/s")),
fmt::arg("bandwidthDownBytes", pow_format(bandwidth_down / elapsed_seconds, "B/s")), fmt::arg("bandwidthDownBytes", pow_format(bandwidth_down / elapsed_seconds, "B/s")),
fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / elapsed_seconds, "B/s")), fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / elapsed_seconds, "B/s")),
fmt::arg("bandwidthDownBytesCompact",
pow_format(bandwidth_down / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthUpBytesCompact",
pow_format(bandwidth_up / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthTotalBytes", fmt::arg("bandwidthTotalBytes",
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "B/s"))); pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "B/s")));
if (label_.get_tooltip_text() != tooltip_text) { if (label_.get_tooltip_text() != tooltip_text) {