mirror of
https://github.com/polybar/polybar.git
synced 2024-11-25 13:55:47 -05:00
feat(net): %netspeed% token to show combined up+download speed (#2590)
Closes #1083 * Add netspeed parameter (#1083) * Update net.cpp * Update net.hpp * Update network.cpp * Update CHANGELOG.md
This commit is contained in:
parent
a33e8de922
commit
ab915fb724
4 changed files with 13 additions and 0 deletions
|
@ -154,6 +154,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- For module actions, you can now also specify the module name,
|
||||
action name, and optional data as separate arguments.
|
||||
- Added man page
|
||||
- `internal/network`: New token `%netspeed%` that provides the total speed of the internet (up + down speed) ([#2590](https://github.com/polybar/polybar/issues/2590))
|
||||
|
||||
### Changed
|
||||
- Polybar now also reads `config.ini` when searching for config files.
|
||||
|
|
|
@ -90,6 +90,7 @@ namespace net {
|
|||
string mac() const;
|
||||
string downspeed(int minwidth = 3, const string& unit = "B/s") const;
|
||||
string upspeed(int minwidth = 3, const string& unit = "B/s") const;
|
||||
string netspeed(int minwidth = 3, const string& unit = "B/s") const;
|
||||
void set_unknown_up(bool unknown = true);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -274,6 +274,15 @@ namespace net {
|
|||
float bytes_diff = m_status.current.transmitted - m_status.previous.transmitted;
|
||||
return format_speedrate(bytes_diff, minwidth, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total net speed rate
|
||||
*/
|
||||
string network::netspeed(int minwidth, const string& unit) const {
|
||||
float bytes_diff = m_status.current.received - m_status.previous.received
|
||||
+ m_status.current.transmitted - m_status.previous.transmitted;
|
||||
return format_speedrate(bytes_diff, minwidth, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if unknown counts as up
|
||||
|
|
|
@ -148,6 +148,7 @@ namespace modules {
|
|||
|
||||
auto upspeed = network->upspeed(m_udspeed_minwidth, m_udspeed_unit);
|
||||
auto downspeed = network->downspeed(m_udspeed_minwidth, m_udspeed_unit);
|
||||
auto netspeed = network->netspeed(m_udspeed_minwidth, m_udspeed_unit);
|
||||
|
||||
// Update label contents
|
||||
const auto replace_tokens = [&](label_t& label) {
|
||||
|
@ -158,6 +159,7 @@ namespace modules {
|
|||
label->replace_token("%local_ip6%", network->ip6());
|
||||
label->replace_token("%upspeed%", upspeed);
|
||||
label->replace_token("%downspeed%", downspeed);
|
||||
label->replace_token("%netspeed%", netspeed);
|
||||
|
||||
if (m_wired) {
|
||||
label->replace_token("%linkspeed%", m_wired->linkspeed());
|
||||
|
|
Loading…
Reference in a new issue