diff --git a/graphicsdriverapplet.cpp b/graphicsdriverapplet.cpp index 76fcfd8..02a5237 100644 --- a/graphicsdriverapplet.cpp +++ b/graphicsdriverapplet.cpp @@ -395,6 +395,52 @@ void GraphicsDriverApplet::readGpuStats() } } } + + // --- 以下为 Intel 核显等无 hwmon/vram sysfs 接口时的回退逻辑 --- + + // 温度回退:扫描 thermal_zone,匹配 Intel GPU 的 ACPI 标识 (B0D4) + // B0D4 是 Intel GPU 在 ACPI 规范中的标准热区标识 + if (gpu.temperature < 0) { + QDir thermalDir("/sys/class/thermal"); + QStringList zones = thermalDir.entryList(QStringList() << "thermal_zone*", QDir::Dirs | QDir::NoDotAndDotDot); + for (const QString &zone : zones) { + QFile typeFile(thermalDir.absoluteFilePath(zone + "/type")); + if (typeFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QString type = QTextStream(&typeFile).readAll().trimmed(); + if (type == "B0D4") { + QFile tempFile(thermalDir.absoluteFilePath(zone + "/temp")); + if (tempFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + int tempMilli = QTextStream(&tempFile).readAll().trimmed().toInt(); + gpu.temperature = tempMilli / 1000; + } + break; + } + } + } + } + + // 显存回退:Intel 核显使用共享系统内存,读取 /proc/meminfo 作为参考 + // 注意:这是系统内存使用量,非核显独占,仅作参考 + if (gpu.memTotal < 0) { + QFile meminfo("/proc/meminfo"); + if (meminfo.open(QIODevice::ReadOnly | QIODevice::Text)) { + QString content = QTextStream(&meminfo).readAll(); + QRegularExpression totalRe("MemTotal:\\s*(\\d+)\\s*kB"); + QRegularExpression availRe("MemAvailable:\\s*(\\d+)\\s*kB"); + auto totalMatch = totalRe.match(content); + auto availMatch = availRe.match(content); + if (totalMatch.hasMatch()) { + gpu.memTotal = totalMatch.captured(1).toLongLong() / 1024; // kB -> MB + } + if (availMatch.hasMatch() && gpu.memTotal > 0) { + qint64 availMB = availMatch.captured(1).toLongLong() / 1024; + gpu.memUsed = gpu.memTotal - availMB; + if (gpu.memUsed >= 0) { + gpu.memUsage = gpu.memUsed * 100 / gpu.memTotal; + } + } + } + } } // 生成统计数据 (格式: temp|gpuUsage|memUsage|memUsed|memTotal)