Publish Framework tray enhancements and idle fingerprint retry
This commit is contained in:
1 parent
61ef199667
commit
ddb912d4ba
25 files changed
+654
-61
No files matched your search
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "chart.h"
|
||||
#include "graphdata.h"
|
||||
#include "readingformat.h"
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
#include <QToolTip>
|
||||
@@ -230,7 +231,8 @@ QString Chart::readingAt(qint64 time) const
|
||||
if (next != points.cbegin()) interval = std::max(interval, intervalAt((next - 1)->x()));
|
||||
const bool valid = !sleeping && closest && std::abs(closest->x() - time) <= interval * 1.5
|
||||
&& std::isfinite(closest->y()) && !crossesSleep(std::min(closest->x(), double(time)), std::max(closest->x(), double(time)));
|
||||
lines.append(it->name + ": " + (valid ? number(closest->y()) + " " + it->unit : "—"));
|
||||
const bool adaptive = it->unit == "W" || it->unit == "MHz" || it->unit == "°C";
|
||||
lines.append(it->name + ": " + (valid ? (adaptive ? formatReading(closest->y()) : number(closest->y())) + " " + it->unit : "—"));
|
||||
}
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
@@ -72,7 +72,26 @@ QVector<Sensor> temperatureSensors(const QString &sys)
|
||||
QVector<Sensor> frequencySensors(const QString &sys)
|
||||
{
|
||||
QVector<Sensor> sensors;
|
||||
sensors.append({"cpu", "CPU average (reported)", sys + "/devices/system/cpu/cpufreq", "MHz", .001});
|
||||
const QString root = sys + "/devices/system/cpu/cpufreq";
|
||||
const auto groups = cpuPolicyGroups(sys);
|
||||
for (const auto &group : {QString("p"), QString("e")}) {
|
||||
if (!groups.contains(group)) continue;
|
||||
Sensor sensor{"cpu/" + group, group.toUpper() + "-cores average (reported)", root, "MHz", .001, true};
|
||||
for (const auto &policy : groups[group])
|
||||
sensor.frequencyPaths.append(root + "/" + policy + "/scaling_cur_freq");
|
||||
sensors.append(sensor);
|
||||
}
|
||||
// Keep the original ID for saved tray selections and combined-average history.
|
||||
sensors.append({"cpu", "CPU average (reported)", root, "MHz", .001, groups.isEmpty()});
|
||||
const int groupCount = sensors.size() - 1;
|
||||
for (int i = 0; i < groupCount; ++i) {
|
||||
auto sensor = sensors[i];
|
||||
sensor.id += "/max";
|
||||
sensor.name = sensor.id.section('/', 1, 1).toUpper() + "-cores maximum (reported)";
|
||||
sensor.primary = false;
|
||||
sensor.maximum = true;
|
||||
sensors.append(sensor);
|
||||
}
|
||||
const QDir drm(sys + "/class/drm");
|
||||
for (const auto &card : drm.entryList({"card*"}, QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||
QDirIterator files(drm.filePath(card + "/device"), {"act_freq"}, QDir::Files,
|
||||
@@ -80,22 +99,27 @@ QVector<Sensor> frequencySensors(const QString &sys)
|
||||
while (files.hasNext()) {
|
||||
const QString path = files.next();
|
||||
const QString relative = path.mid(drm.filePath(card + "/device/").size());
|
||||
sensors.append({card + "/" + relative, "GPU " + card + " " + relative.section('/', 1, 1), path, "MHz", 1});
|
||||
sensors.append({card + "/" + relative, "GPU " + card + " " + relative.section('/', 1, 1), path, "MHz", 1, true});
|
||||
}
|
||||
}
|
||||
return sensors;
|
||||
}
|
||||
std::optional<double> sensorValue(const Sensor &sensor)
|
||||
{
|
||||
if (sensor.id == "cpu") {
|
||||
const QDir dir(sensor.path);
|
||||
double total = 0;
|
||||
int count = 0;
|
||||
for (const auto &policy : dir.entryList({"policy*"}, QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||
const auto n = readNumber(dir.filePath(policy + "/scaling_cur_freq"));
|
||||
if (n) { total += *n; ++count; }
|
||||
if (sensor.id == "cpu" || !sensor.frequencyPaths.isEmpty()) {
|
||||
QStringList paths = sensor.frequencyPaths;
|
||||
if (sensor.id == "cpu") {
|
||||
const QDir dir(sensor.path);
|
||||
for (const auto &policy : dir.entryList({"policy*"}, QDir::Dirs | QDir::NoDotAndDotDot))
|
||||
paths.append(dir.filePath(policy + "/scaling_cur_freq"));
|
||||
}
|
||||
return count ? std::optional<double>(total / count * sensor.scale) : std::nullopt;
|
||||
double total = 0, maximum = 0;
|
||||
int count = 0;
|
||||
for (const auto &path : paths) {
|
||||
const auto n = readNumber(path);
|
||||
if (n) { total += *n; maximum = std::max(maximum, *n); ++count; }
|
||||
}
|
||||
return count ? std::optional<double>((sensor.maximum ? maximum : total / count) * sensor.scale) : std::nullopt;
|
||||
}
|
||||
if (sensor.unit == "°C") {
|
||||
const QString fault = sensor.path.chopped(6) + "_fault";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVariantMap>
|
||||
#include <QVector>
|
||||
#include <optional>
|
||||
@@ -9,6 +10,8 @@ struct Sensor {
|
||||
QString id, name, path, unit;
|
||||
double scale = 1;
|
||||
bool primary = false;
|
||||
QStringList frequencyPaths;
|
||||
bool maximum = false;
|
||||
};
|
||||
QString readText(const QString &path);
|
||||
std::optional<double> readNumber(const QString &path);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
#include <QString>
|
||||
#include <cmath>
|
||||
|
||||
inline QString formatReading(double value)
|
||||
{
|
||||
if (!std::isfinite(value)) return QStringLiteral("—");
|
||||
const bool fractional = std::abs(value) < 10;
|
||||
const auto text = QString::number(fractional ? value : std::round(value), 'f', fractional ? 1 : 0);
|
||||
return text == "-0.0" ? QStringLiteral("0.0") : text;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "tooltip.h"
|
||||
#include "readingformat.h"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -15,9 +16,9 @@ QVector<TooltipSensor> tooltipSensors(const QVector<Sensor> &sensors)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool tooltipEnabled(const QVariantMap &settings, const QString &key)
|
||||
bool tooltipEnabled(const QVariantMap &settings, const QString &key, bool fallback)
|
||||
{
|
||||
return settings.value("tray/hover/" + key, true).toBool();
|
||||
return settings.value("tray/hover/" + key, fallback).toBool();
|
||||
}
|
||||
int tooltipAppCount(const QVariantMap &settings)
|
||||
{
|
||||
@@ -36,7 +37,7 @@ QString batteryTooltip(const QVariantMap &battery, int limit, const QVariantMap
|
||||
};
|
||||
text += " · " + energy("remainingMWh") + " mWh / " + energy("fullMWh") + " mWh";
|
||||
const auto watts = batteryRate(battery);
|
||||
text += "\n\u2003" + (watts ? (*watts > 0 ? "+" : "") + QString::number(*watts, 'f', 1) + " W" : "— W");
|
||||
text += "\n\u2003" + (watts ? (*watts > 0 ? "+" : "") + formatReading(*watts) + " W" : "— W");
|
||||
const bool charging = battery["state"] == "Charging", discharging = battery["state"] == "Discharging";
|
||||
double seconds = 0;
|
||||
bool approximate = false;
|
||||
@@ -60,7 +61,8 @@ QString batteryTooltip(const QVariantMap &battery, int limit, const QVariantMap
|
||||
return text;
|
||||
}
|
||||
QString trayTooltip(const QVariantMap &settings, const QMap<QString, double> &values,
|
||||
const QVector<TooltipSensor> &temperatures, const QString &battery, const QStringList &topApps)
|
||||
const QVector<TooltipSensor> &temperatures, const QString &battery, const QStringList &topApps,
|
||||
const QVector<Sensor> &powerSensors)
|
||||
{
|
||||
const auto reading = [&](const QString &id, int decimals) {
|
||||
const auto it = values.constFind(id);
|
||||
@@ -75,10 +77,16 @@ QString trayTooltip(const QVariantMap &settings, const QMap<QString, double> &va
|
||||
}
|
||||
if (tooltipEnabled(settings, "battery")) lines << battery;
|
||||
if (tooltipEnabled(settings, "fan")) lines << "Fan speed: " + reading("fan", 0) + " RPM (" + reading("fan-duty", 0) + " %)";
|
||||
QStringList power;
|
||||
for (const auto &sensor : powerSensors)
|
||||
if (tooltipEnabled(settings, sensor.id, false))
|
||||
power << sensor.name + ": " + formatReading(values.value(sensor.id, NAN)) + " W";
|
||||
if (power.size() > 1) lines << "Power consumption:";
|
||||
for (const auto &line : power) lines << (power.size() > 1 ? "\u2003" : "") + line;
|
||||
QStringList temps;
|
||||
for (const auto &sensor : temperatures)
|
||||
if (!sensor.id.isEmpty() && tooltipEnabled(settings, "temperature/" + sensor.key))
|
||||
temps << sensor.name + " " + reading(sensor.id, 0) + "°C";
|
||||
temps << sensor.name + " " + formatReading(values.value(sensor.id, NAN)) + "°C";
|
||||
if (temps.size() > 1) lines << "Temperatures:";
|
||||
for (const auto &temp : temps) lines << (temps.size() > 1 ? "\u2003" : "") + temp;
|
||||
return lines.join('\n');
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
|
||||
struct TooltipSensor { QString key, name, id; };
|
||||
QVector<TooltipSensor> tooltipSensors(const QVector<Sensor> &sensors);
|
||||
bool tooltipEnabled(const QVariantMap &settings, const QString &key);
|
||||
bool tooltipEnabled(const QVariantMap &settings, const QString &key, bool fallback = true);
|
||||
int tooltipAppCount(const QVariantMap &settings);
|
||||
QString batteryTooltip(const QVariantMap &battery, int limit, const QVariantMap &upower);
|
||||
QString trayTooltip(const QVariantMap &settings, const QMap<QString, double> &values,
|
||||
const QVector<TooltipSensor> &temperatures, const QString &battery, const QStringList &topApps);
|
||||
const QVector<TooltipSensor> &temperatures, const QString &battery, const QStringList &topApps,
|
||||
const QVector<Sensor> &powerSensors = {});
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "tray.h"
|
||||
#include "graphdata.h"
|
||||
#include "readingformat.h"
|
||||
#include <QPainter>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
@@ -30,7 +31,8 @@ QRectF trayPlotRect(bool border)
|
||||
// Two-pixel border; reserve space for the graph's vertical padding inside it.
|
||||
return border ? QRectF(3, 3, 58, 58) : QRectF(1, 1, 62, 62);
|
||||
}
|
||||
QIcon telemetryIcon(bool graph, const QVector<QPointF> &values, const QString &unit, const TrayStyle &style, qint64 now)
|
||||
QIcon telemetryIcon(bool graph, const QVector<QPointF> &values, const QString &unit, const TrayStyle &style, qint64 now,
|
||||
std::optional<TrayReading> second)
|
||||
{
|
||||
QPixmap pixmap(64, 64); pixmap.fill(style.backgroundColor);
|
||||
QPainter p(&pixmap); p.setRenderHint(QPainter::Antialiasing);
|
||||
@@ -67,11 +69,28 @@ QIcon telemetryIcon(bool graph, const QVector<QPointF> &values, const QString &u
|
||||
}
|
||||
p.restore();
|
||||
} else {
|
||||
const QString value = !std::isfinite(latest) ? "—" : unit == "MHz"
|
||||
? QString::number(latest / 1000, 'f', 1) : QString::number(std::round(latest), 'f', 0);
|
||||
QFont font; font.setBold(true); font.setPixelSize(42);
|
||||
while (QFontMetrics(font).horizontalAdvance(value) > area.width() && font.pixelSize() > 12) font.setPixelSize(font.pixelSize() - 1);
|
||||
p.setFont(font); p.drawText(area, Qt::AlignCenter, value);
|
||||
const bool stacked = !graph && second.has_value();
|
||||
const auto drawNumber = [&](const TrayReading &reading, const QRectF &rect) {
|
||||
const bool adaptive = reading.unit == "MHz" || reading.unit == "W" || reading.unit == "°C";
|
||||
const QString value = !std::isfinite(reading.value) ? "—" : adaptive
|
||||
? formatReading(reading.unit == "MHz" ? reading.value / 1000 : reading.value)
|
||||
: QString::number(std::round(reading.value), 'f', 0);
|
||||
QFont font; font.setBold(true); font.setPixelSize(42);
|
||||
while (font.pixelSize() > 12 && (QFontMetrics(font).horizontalAdvance(value) > rect.width()
|
||||
|| (stacked && QFontMetrics(font).tightBoundingRect(value).height() > rect.height() - 2)))
|
||||
font.setPixelSize(font.pixelSize() - 1);
|
||||
p.setFont(font);
|
||||
if (stacked) {
|
||||
// Centre the visible glyphs, not the font's extra line spacing.
|
||||
const auto bounds = QFontMetricsF(font).tightBoundingRect(value);
|
||||
p.drawText(rect.center() - bounds.center(), value);
|
||||
} else p.drawText(rect, Qt::AlignCenter, value);
|
||||
};
|
||||
if (stacked) {
|
||||
const double height = area.height() / 2;
|
||||
drawNumber({latest, unit}, QRectF(area.left(), area.top(), area.width(), height));
|
||||
drawNumber(*second, QRectF(area.left(), area.top() + height, area.width(), height));
|
||||
} else drawNumber({latest, unit}, area);
|
||||
}
|
||||
return QIcon(pixmap);
|
||||
}
|
||||
@@ -23,5 +23,9 @@ struct TrayStyle {
|
||||
qint64 historyMs = 60000;
|
||||
};
|
||||
QRectF trayPlotRect(bool border);
|
||||
struct TrayReading {
|
||||
double value;
|
||||
QString unit;
|
||||
};
|
||||
QIcon telemetryIcon(bool graph, const QVector<QPointF> &values, const QString &unit, const TrayStyle &style,
|
||||
qint64 now = QDateTime::currentMSecsSinceEpoch());
|
||||
qint64 now = QDateTime::currentMSecsSinceEpoch(), std::optional<TrayReading> second = {});
|
||||
@@ -53,6 +53,11 @@ TrayPage::TrayPage(const QVariantMap &values, const QVector<Sensor> &sensors, QW
|
||||
auto *graphForm = new QFormLayout(graphOptions); graphForm->setContentsMargins(24, 0, 0, 0);
|
||||
graphForm->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
|
||||
form->addRow(graphOptions); form->addRow("Reading:", m_metric);
|
||||
m_secondMetric = new QComboBox; m_secondMetric->setObjectName("traySecondMetric");
|
||||
m_secondMetric->addItem("None", "");
|
||||
for (const auto &sensor : sensors) m_secondMetric->addItem(sensor.name + " (" + sensor.unit + ")", sensor.id);
|
||||
m_secondMetric->setCurrentIndex(std::max(0, m_secondMetric->findData(m_values.value("tray/secondMetric", ""))));
|
||||
form->addRow("Second reading:", m_secondMetric);
|
||||
auto *appearance = new QWidget; auto *colors = new QFormLayout(appearance); colors->setContentsMargins(0, 0, 0, 0);
|
||||
colors->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
|
||||
auto colorRow = [&](QFormLayout *target, const QString &label, const QString &key, const QColor &fallback, bool alpha = false) {
|
||||
@@ -132,10 +137,11 @@ TrayPage::TrayPage(const QVariantMap &values, const QVector<Sensor> &sensors, QW
|
||||
m_values.insert("tray/outside", m_outside->currentData()); syncOutside(); if (!m_loading) Q_EMIT settingsChanged();
|
||||
});
|
||||
syncOutside(); layout->addWidget(m_graphSettings);
|
||||
auto syncMode = [this, appearance, graphOptions] {
|
||||
auto syncMode = [this, form, appearance, graphOptions] {
|
||||
const bool telemetry = mode() != "icon";
|
||||
m_metric->setEnabled(telemetry); appearance->setVisible(telemetry); m_graphSettings->setVisible(mode() == "graph");
|
||||
graphOptions->setVisible(mode() == "graph");
|
||||
form->setRowVisible(m_secondMetric, mode() == "number");
|
||||
};
|
||||
connect(m_mode, &QComboBox::currentIndexChanged, this, [this, syncMode] {
|
||||
m_values.insert("tray/mode", m_mode->currentData()); syncMode(); if (!m_loading) Q_EMIT settingsChanged();
|
||||
@@ -143,6 +149,9 @@ TrayPage::TrayPage(const QVariantMap &values, const QVector<Sensor> &sensors, QW
|
||||
connect(m_metric, &QComboBox::currentIndexChanged, this, [this] {
|
||||
m_values.insert("tray/metric", m_metric->currentData()); loadScale(); if (!m_loading) Q_EMIT settingsChanged();
|
||||
});
|
||||
connect(m_secondMetric, &QComboBox::currentIndexChanged, this, [this] {
|
||||
m_values.insert("tray/secondMetric", m_secondMetric->currentData()); if (!m_loading) Q_EMIT settingsChanged();
|
||||
});
|
||||
connect(m_minimum, &QDoubleSpinBox::valueChanged, this, [this](double value) {
|
||||
m_maximum->setMinimum(value + 1); m_values.insert(scaleKey("minimum"), value); if (!m_loading) Q_EMIT settingsChanged();
|
||||
});
|
||||
@@ -152,10 +161,12 @@ TrayPage::TrayPage(const QVariantMap &values, const QVector<Sensor> &sensors, QW
|
||||
loadScale(); syncMode();
|
||||
m_values.insert("tray/mode", m_mode->currentData());
|
||||
m_values.insert("tray/metric", m_metric->currentData());
|
||||
m_values.insert("tray/secondMetric", m_secondMetric->currentData());
|
||||
m_values.insert("tray/outside", m_outside->currentData());
|
||||
m_reload.append([this, syncMode, syncOutside] {
|
||||
m_mode->setCurrentIndex(std::max(0, m_mode->findData(m_values.value("tray/mode", "icon"))));
|
||||
m_metric->setCurrentIndex(std::max(0, m_metric->findData(m_values.value("tray/metric", "cpu-usage"))));
|
||||
m_secondMetric->setCurrentIndex(std::max(0, m_secondMetric->findData(m_values.value("tray/secondMetric", ""))));
|
||||
m_outside->setCurrentIndex(std::max(0, m_outside->findData(m_values.value("tray/outside", "clamp"))));
|
||||
syncMode(); syncOutside();
|
||||
});
|
||||
@@ -178,6 +189,15 @@ TrayPage::TrayPage(const QVariantMap &values, const QVector<Sensor> &sensors, QW
|
||||
appOptions->setEnabled(cpu->isChecked()); connect(cpu, &QCheckBox::toggled, appOptions, &QWidget::setEnabled);
|
||||
check(hoverForm, "Battery", "hover/battery", true);
|
||||
check(hoverForm, "Fan", "hover/fan", true);
|
||||
auto *powerOptions = new QWidget;
|
||||
auto *powerForm = new QFormLayout(powerOptions); powerForm->setContentsMargins(24, 0, 0, 0);
|
||||
for (const auto &sensor : sensors)
|
||||
if (sensor.unit == "W" && sensor.id.startsWith("power/"))
|
||||
check(powerForm, sensor.name, "hover/" + sensor.id, false);
|
||||
if (powerForm->rowCount()) {
|
||||
hoverForm->addRow(new QLabel("Power consumption:"));
|
||||
hoverForm->addRow(powerOptions);
|
||||
} else delete powerOptions;
|
||||
hoverForm->addRow(new QLabel("Temperature:"));
|
||||
auto *temperatures = new QWidget; auto *tempForm = new QFormLayout(temperatures); tempForm->setContentsMargins(24, 0, 0, 0);
|
||||
for (const auto &sensor : tooltipSensors(sensors)) {
|
||||
@@ -205,7 +225,8 @@ void TrayPage::loadScale()
|
||||
const bool frequency = unit == "MHz", temperature = unit == "°C", rate = unit == "W";
|
||||
m_scaleLayout->setRowVisible(m_minimum, temperature || rate); m_scaleLayout->setRowVisible(m_maximum, temperature || frequency || rate);
|
||||
for (auto *spin : {m_minimum, m_maximum}) { spin->setDecimals(0); spin->setRange(rate ? -300 : temperature ? -50 : 0, frequency ? 20000 : 300); spin->setSuffix(" " + unit); }
|
||||
double maximum = frequency ? (metric().id == "cpu" ? cpuLimits().value("high", 5000).toDouble() : 3000) : rate ? 75 : 100;
|
||||
const bool cpuFrequency = metric().id == "cpu" || metric().id.startsWith("cpu/");
|
||||
double maximum = frequency ? (cpuFrequency ? cpuLimits("/sys", metric().id.section('/', 1, 1)).value("high", 5000).toDouble() : 3000) : rate ? 75 : 100;
|
||||
const double low = m_values.value(scaleKey("minimum"), rate && !metric().id.startsWith("power/") ? -75 : 0).toDouble();
|
||||
maximum = m_values.value(scaleKey("maximum"), maximum).toDouble();
|
||||
m_minimum->setValue(low); m_maximum->setMinimum(m_minimum->value() + 1); m_maximum->setValue(maximum);
|
||||
@@ -345,7 +366,7 @@ QVector<TrayConfiguration> TrayIconsPage::configurations() const
|
||||
QVector<TrayConfiguration> result;
|
||||
for (int i = 0; i < m_count->value(); ++i) {
|
||||
const auto *page = m_pages[i];
|
||||
result.append({page->mode(), page->metric(), page->iconStyle(), page->draft()});
|
||||
result.append({page->mode(), page->metric(), page->iconStyle(), page->draft(), page->secondMetric()});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ struct TrayConfiguration {
|
||||
Sensor metric;
|
||||
TrayStyle style;
|
||||
QVariantMap values;
|
||||
std::optional<Sensor> secondMetric;
|
||||
};
|
||||
|
||||
class TrayPage : public QWidget {
|
||||
@@ -28,6 +29,10 @@ public:
|
||||
TrayPage(const QVariantMap &values, const QVector<Sensor> &sensors, QWidget *parent = nullptr);
|
||||
QString mode() const { return m_mode->currentData().toString(); }
|
||||
Sensor metric() const { return m_sensors[m_metric->currentIndex()]; }
|
||||
std::optional<Sensor> secondMetric() const {
|
||||
return m_secondMetric->currentIndex() > 0
|
||||
? std::optional<Sensor>(m_sensors[m_secondMetric->currentIndex() - 1]) : std::nullopt;
|
||||
}
|
||||
TrayStyle iconStyle() const;
|
||||
QVariantMap draft() const { return m_values; }
|
||||
void load(const QVariantMap &values);
|
||||
@@ -40,7 +45,7 @@ private:
|
||||
QList<std::function<void()>> m_reload;
|
||||
bool m_loading = false;
|
||||
QVector<Sensor> m_sensors;
|
||||
QComboBox *m_mode, *m_metric, *m_outside, *m_history;
|
||||
QComboBox *m_mode, *m_metric, *m_secondMetric, *m_outside, *m_history;
|
||||
QDoubleSpinBox *m_minimum, *m_maximum;
|
||||
QFormLayout *m_scaleLayout;
|
||||
QWidget *m_graphSettings;
|
||||
|
||||
@@ -119,7 +119,8 @@ QGroupBox *Window::sensorGroup(const QString &title, Chart *chart, const QVector
|
||||
QVector<Sensor> main, extra;
|
||||
for (const auto &sensor : sensors) {
|
||||
chart->addSeries(sensor.id, sensor.name, sensor.unit);
|
||||
chart->setSelected(sensor.id, m_settings.value("series/" + sensor.id, !temperatures || sensor.primary).toBool());
|
||||
const bool selectedByDefault = (temperatures || sensor.unit == "MHz") ? sensor.primary : true;
|
||||
chart->setSelected(sensor.id, m_settings.value("series/" + sensor.id, selectedByDefault).toBool());
|
||||
(temperatures && !sensor.primary ? extra : main).append(sensor);
|
||||
}
|
||||
auto makeLegend = [&](const QVector<Sensor> &entries) {
|
||||
@@ -310,15 +311,24 @@ void Window::updateTray()
|
||||
if (config.mode == "icon") tray.icon->setIcon(windowIcon());
|
||||
else {
|
||||
const double since = now - (config.mode == "graph" ? config.style.historyMs : 0);
|
||||
QVector<QPointF> history;
|
||||
if (metric.id == "cpu-usage")
|
||||
for (auto it = historyStart(m_usageHistory, since); it != m_usageHistory.cend(); ++it) history.append(*it);
|
||||
else if (metric.id == "battery" || metric.id == "battery-rate") history = m_batteryChart->history(metric.id, since);
|
||||
else if (metric.id.startsWith("power/")) history = m_powerChart->history(metric.id, since);
|
||||
else history = (metric.unit == "MHz" ? m_frequencyChart : m_temperatureChart)->history(metric.id, since);
|
||||
tray.icon->setIcon(telemetryIcon(config.mode == "graph", history, metric.unit, config.style, now));
|
||||
const auto historyFor = [&](const Sensor &sensor) {
|
||||
if (sensor.id == "cpu-usage") {
|
||||
QVector<QPointF> history;
|
||||
for (auto it = historyStart(m_usageHistory, since); it != m_usageHistory.cend(); ++it) history.append(*it);
|
||||
return history;
|
||||
}
|
||||
if (sensor.id == "battery" || sensor.id == "battery-rate") return m_batteryChart->history(sensor.id, since);
|
||||
if (sensor.id.startsWith("power/")) return m_powerChart->history(sensor.id, since);
|
||||
return (sensor.unit == "MHz" ? m_frequencyChart : m_temperatureChart)->history(sensor.id, since);
|
||||
};
|
||||
std::optional<TrayReading> second;
|
||||
if (config.mode == "number" && config.secondMetric) {
|
||||
const auto history = historyFor(*config.secondMetric);
|
||||
second = TrayReading{history.isEmpty() ? NAN : history.last().y(), config.secondMetric->unit};
|
||||
}
|
||||
tray.icon->setIcon(telemetryIcon(config.mode == "graph", historyFor(metric), metric.unit, config.style, now, second));
|
||||
}
|
||||
tray.icon->setToolTip(trayTooltip(config.values, m_values, temperatures, m_batteryText, m_topAppText));
|
||||
tray.icon->setToolTip(trayTooltip(config.values, m_values, temperatures, m_batteryText, m_topAppText, m_powerMonitor.sensors()));
|
||||
}
|
||||
}
|
||||
QVariantMap Window::controlValue(const QString &key) const
|
||||
@@ -531,7 +541,8 @@ void Window::sample()
|
||||
sampleSensors(m_frequencies, m_frequencyChart); sampleSensors(m_temperatures, m_temperatureChart);
|
||||
const auto power = m_powerMonitor.sample(m_fastTimer.interval());
|
||||
m_powerChart->sample(power, m_fastTimer.interval());
|
||||
m_values.insert(power);
|
||||
for (const auto &sensor : m_powerMonitor.sensors())
|
||||
m_values[sensor.id] = power.value(sensor.id, NAN);
|
||||
const QString ec = ecHwmon();
|
||||
const auto rpm = readNumber(ec + "/fan1_input");
|
||||
const auto mode = readNumber(ec + "/pwm1_enable");
|
||||
|
||||
Reference in new issue
Block a user