Merge pull request #5015 from yui-915/compact-bandwidth
feat: add compact versions of bandwidthBytes to network module
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user