Skip to content

Commit b38b2f2

Browse files
committed
Unsmooth systray text traffic rates
1 parent 5315b33 commit b38b2f2

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
## Text statistics tray icons
1212

1313
Enable **Display Text Statistics** for an interface to add an icon showing upload
14-
above download, in bytes per second. Short units use powers of 1024: `K`, `M`,
14+
above download, in bytes per second. Rates use only the counter difference from
15+
the previous sample divided by the actual elapsed time, without smoothing; the
16+
tray tooltip uses the same rates. Until two valid samples are available, the
17+
icon shows dashes. Short units use powers of 1024: `K`, `M`,
1518
`G`, `T`, and `P`. Each monitored text icon has a unique digit from 0 to 9;
1619
used digits cannot be selected for another monitored text icon. This limits text
1720
icons to ten interfaces, without limiting ordinary interface monitoring.

‎src/configure.cpp‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ void Configure::setupTextStatisticsControls() {
240240
previews->addWidget(mTextPreview22);
241241
previews->addStretch();
242242
form->addRow(tr("Preview:"), previews);
243-
auto *hint = new QLabel(tr("Upload above download, in bytes/s. The chosen font family and style "
244-
"are fitted automatically. Digits already used by monitored text icons are unavailable."), mTextStatisticsGroup);
245-
hint->setWordWrap(true);
246-
form->addRow(hint);
247243
gridLayout_3->addWidget(mTextStatisticsGroup, 0, 2, 2, 1);
248244
connect(mTextStatisticsGroup, &QGroupBox::toggled, this, &Configure::updateTextStatisticsControls);
249245
connect(mMonitoringInterface, &QCheckBox::toggled, this, &Configure::updateTextStatisticsControls);

‎src/qnetstatsview.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ void QNetStatsView::updateStats() {
204204
mDeltaBufferRx[mDeltaBufferPtr] = brx - mBRx;
205205
mDeltaBufferPTx[mDeltaBufferPtr] = ptx - mPTx;
206206
mDeltaBufferPRx[mDeltaBufferPtr] = prx - mPRx;
207+
mRatesAvailable = true;
207208
mSpeedHistoryRx[mSpeedHistoryPtr] = calcSpeed(mDeltaBufferRx);
208209
mSpeedHistoryTx[mSpeedHistoryPtr] = calcSpeed(mDeltaBufferTx);
209210
calcMaxSpeed();
@@ -241,7 +242,6 @@ void QNetStatsView::updateStats() {
241242
mBTx = btx;
242243
mPRx = prx;
243244
mPTx = ptx;
244-
mRatesAvailable = true;
245245
updateTextTrayIcon();
246246
}
247247

@@ -347,8 +347,10 @@ void QNetStatsView::iconActivated(QSystemTrayIcon::ActivationReason reason) {
347347
void QNetStatsView::updateTextTrayIcon(bool force) {
348348
if (!mOptions.mDisplayTextStatistics)
349349
return;
350-
const double upload = calcSpeed(mDeltaBufferTx);
351-
const double download = calcSpeed(mDeltaBufferRx);
350+
// Text statistics use only the latest counter interval, without smoothing.
351+
const double seconds = mSampleSeconds[mDeltaBufferPtr];
352+
const double upload = seconds > 0.0 ? mDeltaBufferTx[mDeltaBufferPtr] / seconds : 0.0;
353+
const double download = seconds > 0.0 ? mDeltaBufferRx[mDeltaBufferPtr] / seconds : 0.0;
352354
const QString upl = mRatesAvailable ? formatShortRate(upload) : QString("-");
353355
const QString dld = mRatesAvailable ? formatShortRate(download) : QString("-");
354356
if (force || upl != mLastUpload || dld != mLastDownload) {

0 commit comments

Comments
 (0)