]> git.pld-linux.org Git - packages/polybar.git/commitdiff
upstream patch for increasing precision of network speed auto/th/polybar-3.5.7-1
authorJan Palus <atler@pld-linux.org>
Tue, 21 Sep 2021 16:37:09 +0000 (18:37 +0200)
committerJan Palus <atler@pld-linux.org>
Tue, 21 Sep 2021 16:37:34 +0000 (18:37 +0200)
from: https://github.com/polybar/polybar/pull/2054

polybar-net-speedrate-precison.patch [new file with mode: 0644]
polybar.spec

diff --git a/polybar-net-speedrate-precison.patch b/polybar-net-speedrate-precison.patch
new file mode 100644 (file)
index 0000000..0cf2172
--- /dev/null
@@ -0,0 +1,42 @@
+From 6208c9e2454e00f61a0980ca3fdae630e52a9548 Mon Sep 17 00:00:00 2001
+From: Jan Palus <atler@pld-linux.org>
+Date: Thu, 9 Apr 2020 01:39:27 +0200
+Subject: [PATCH] net: increase speedrate precision
+
+more granular units need lower precision, while less granular need
+higher precision. assume sane default of:
+
+unit | precision
+KB   | 0
+MB   | 1
+GB   | 2
+---
+ src/adapters/net.cpp | 10 ++++++----
+ 1 file changed, 6 insertions(+), 4 deletions(-)
+
+diff --git a/src/adapters/net.cpp b/src/adapters/net.cpp
+index 40c8b89fd7..4860309577 100644
+--- a/src/adapters/net.cpp
++++ b/src/adapters/net.cpp
+@@ -229,15 +229,17 @@ namespace net {
+     float time_diff = duration.count();
+     float speedrate = bytes_diff / time_diff;
+-    vector<string> suffixes{"GB", "MB"};
++    vector<pair<string,int>> units{make_pair("GB",2), make_pair("MB",1)};
+     string suffix{"KB"};
++    int precision = 0;
+     while ((speedrate /= 1000) > 999) {
+-      suffix = suffixes.back();
+-      suffixes.pop_back();
++      suffix = units.back().first;
++      precision = units.back().second;
++      units.pop_back();
+     }
+-    return sstream() << std::setw(minwidth) << std::setfill(' ') << std::setprecision(0) << std::fixed << speedrate
++    return sstream() << std::setw(minwidth) << std::setfill(' ') << std::setprecision(precision) << std::fixed << speedrate
+                      << " " << suffix << "/s";
+   }
index 8eba7a2d1510b086bcd213b2d57865dc5a37b940..6f4c163c6bd1b0015eea198e38452f83b8ae4635 100644 (file)
@@ -7,6 +7,7 @@ Group:          X11/Window Managers
 Source0:       https://github.com/polybar/polybar/releases/download/%{version}/%{name}-%{version}.tar.gz 
 # Source0-md5: 3a9b19709d49ac9e86d875ed2570ff91
 Patch0:                %{name}-mpd-overhead.patch
+Patch1:                %{name}-net-speedrate-precison.patch
 URL:           https://polybar.github.io/
 BuildRequires: alsa-lib-devel
 BuildRequires: cairo-devel
@@ -66,6 +67,7 @@ zsh-completion for polybar.
 %prep
 %setup -q
 %patch0 -p1
+%patch1 -p1
 
 %build
 install -d build
This page took 0.152668 seconds and 4 git commands to generate.