fix(Steam Deck): CPU/Battery Temp & Percentage

Signed-off-by: Collecting <collecting@noreply.localhost>
This commit is contained in:
Collecting
2026-01-04 22:01:19 +00:00
parent 884922a1cb
commit 8535fa202f

View File

@@ -251,30 +251,67 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
battery_temperature = 0.0f;
#if defined(Q_OS_LINUX)
QDir thermal_dir(QString::fromUtf8("/sys/class/thermal/"));
QStringList filters{QString::fromUtf8("thermal_zone*")};
QStringList thermal_zones = thermal_dir.entryList(filters, QDir::Dirs);
// 1. Read Battery Percentage and Temperature (Steam Deck / Linux Laptops)
QStringList bat_nodes = {QStringLiteral("BAT1"), QStringLiteral("BAT0")};
for (const QString& node : bat_nodes) {
QString base_path = QStringLiteral("/sys/class/power_supply/%1/").arg(node);
QFile cap_file(base_path + QStringLiteral("capacity"));
if (cap_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
battery_percentage = cap_file.readAll().trimmed().toInt();
cap_file.close();
for (const QString& zone_name : thermal_zones) {
QFile type_file(thermal_dir.filePath(zone_name + QString::fromUtf8("/type")));
if (!type_file.open(QIODevice::ReadOnly | QIODevice::Text)) continue;
QString type = QString::fromUtf8(type_file.readAll()).trimmed();
type_file.close();
QFile temp_file(thermal_dir.filePath(zone_name + QString::fromUtf8("/temp")));
if (!temp_file.open(QIODevice::ReadOnly | QIODevice::Text)) continue;
float temp = temp_file.readAll().trimmed().toFloat() / 1000.0f;
temp_file.close();
if (type.contains(QString::fromUtf8("x86_pkg_temp")) || type.contains(QString::fromUtf8("cpu"))) {
if (temp > cpu_temperature) {
cpu_temperature = temp;
cpu_sensor_type = QString::fromUtf8("CPU");
QFile btemp_file(base_path + QStringLiteral("temp"));
if (btemp_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
battery_temperature = btemp_file.readAll().trimmed().toFloat() / 10.0f;
btemp_file.close();
}
} else if (type.contains(QString::fromUtf8("radeon")) || type.contains(QString::fromUtf8("amdgpu")) || type.contains(QString::fromUtf8("nvidia")) || type.contains(QString::fromUtf8("nouveau"))) {
if (temp > gpu_temperature) {
gpu_temperature = temp;
gpu_sensor_type = QString::fromUtf8("GPU");
break;
}
}
// 2. Read CPU/GPU Temperature via hwmon (Steam Deck APU)
QDir hwmon_dir(QStringLiteral("/sys/class/hwmon/"));
QStringList hwmons = hwmon_dir.entryList({QStringLiteral("hwmon*")}, QDir::Dirs);
for (const QString& h_node : hwmons) {
QFile name_file(hwmon_dir.filePath(h_node + QStringLiteral("/name")));
if (!name_file.open(QIODevice::ReadOnly | QIODevice::Text)) continue;
QString hw_name = QString::fromUtf8(name_file.readAll().trimmed());
name_file.close();
if (hw_name == QStringLiteral("amdgpu") || hw_name == QStringLiteral("k10temp")) {
QFile temp_file(hwmon_dir.filePath(h_node + QStringLiteral("/temp1_input")));
if (temp_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
float temp = temp_file.readAll().trimmed().toFloat() / 1000.0f;
temp_file.close();
if (temp > cpu_temperature) {
cpu_temperature = temp;
gpu_temperature = temp;
cpu_sensor_type = QStringLiteral("APU");
gpu_sensor_type = QStringLiteral("GPU");
}
}
}
}
// 3. Fallback to generic thermal_zones
if (cpu_temperature <= 0.0f) {
QDir thermal_dir(QStringLiteral("/sys/class/thermal/"));
QStringList thermal_zones = thermal_dir.entryList({QStringLiteral("thermal_zone*")}, QDir::Dirs);
for (const QString& zone_name : thermal_zones) {
QFile type_file(thermal_dir.filePath(zone_name + QStringLiteral("/type")));
if (!type_file.open(QIODevice::ReadOnly | QIODevice::Text)) continue;
QString type = QString::fromUtf8(type_file.readAll().trimmed());
type_file.close();
if (type.contains(QStringLiteral("x86_pkg_temp")) || type.contains(QStringLiteral("cpu"))) {
QFile temp_file(thermal_dir.filePath(zone_name + QStringLiteral("/temp")));
if (temp_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
cpu_temperature = temp_file.readAll().trimmed().toFloat() / 1000.0f;
cpu_sensor_type = QStringLiteral("CPU");
temp_file.close();
}
}
}
}
@@ -282,7 +319,7 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
#if defined(Q_OS_ANDROID)
QJniObject battery_status = QJniObject::callStaticObjectMethod(
"android/content/CONTEXT", "registerReceiver",
"android/content/Context", "registerReceiver",
"(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;",
nullptr, new QJniObject("android.content.IntentFilter", "(Ljava/lang/String;)V", "android.intent.action.BATTERY_CHANGED"));
@@ -323,7 +360,7 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
pclsObj->Get(L"CurrentTemperature", 0, &vtProp, 0, 0);
float temp_kelvin = vtProp.uintVal / 10.0f;
cpu_temperature = temp_kelvin - 273.15f;
cpu_sensor_type = QString::fromUtf8("CPU");
cpu_sensor_type = QStringLiteral("CPU");
VariantClear(&vtProp);
pclsObj->Release();
}