fix: 修复驱动检测与版本号显示

- 修复 driver 名称获取:使用 QFileInfo::symLinkTarget() 替代 QDir::dirName(),
  解决驱动名恒为 'driver' 的问题
- 添加开源内核驱动版本号支持:amdgpu/radeon/nouveau/i915 等显示内核版本
- 添加卡片 tooltip 三行信息(显卡/驱动/版本号)的翻译条目
This commit is contained in:
2026-07-13 22:10:38 +08:00
parent fcc395053a
commit bc371fbac5
4 changed files with 75 additions and 4 deletions
+17 -4
View File
@@ -83,11 +83,13 @@ void GraphicsDriverApplet::detectGpus()
gpu.name = parseGpuName(line);
// 检测驱动
// 检测驱动:通过 symlink 目标获取真实驱动名
QString sysPath = "/sys/bus/pci/devices/0000:" + gpu.pciId + "/driver";
QDir driverDir(sysPath);
if (driverDir.exists()) {
gpu.driver = driverDir.dirName();
QFileInfo driverLink(sysPath);
if (driverLink.exists() && driverLink.isSymLink()) {
QString target = driverLink.symLinkTarget();
// symLinkTarget 返回如 ".../drivers/nvidia",提取最后一段
gpu.driver = target.section('/', -1);
// 读取驱动版本
gpu.driverVersion = readDriverVersion(gpu.driver);
@@ -197,6 +199,17 @@ QString GraphicsDriverApplet::readDriverVersion(const QString &driverName)
}
}
// 开源内核驱动(如 amdgpu, radeon, nouveau, i915)无独立版本号,版本跟随内核
static const QStringList kernelDrivers = {
"amdgpu", "radeon", "nouveau", "i915", "i965", "mgag200", "ast", "vmwgfx"
};
if (kernelDrivers.contains(driverName)) {
QFile osrelease("/proc/sys/kernel/osrelease");
if (osrelease.open(QIODevice::ReadOnly | QIODevice::Text)) {
return "Linux " + QTextStream(&osrelease).readAll().trimmed();
}
}
return QString();
}
+28
View File
@@ -186,6 +186,7 @@ AppletItem {
model: root.ready ? root.deviceInfo.split("\n").filter(function(line) { return line.trim().length > 0 }) : []
delegate: Rectangle {
id: gpuCard
width: gpuColumn.width
height: 72
color: root.cardBackground
@@ -193,6 +194,16 @@ AppletItem {
border.width: 1
border.color: root.cardBorder
ToolTip.text: qsTr("GPU: ") + parseGpuName(modelData) + "\n"
+ qsTr("Driver: ") + parseDriverName(modelData) + "\n"
+ qsTr("Version: ") + (parseDriverVersion(modelData) || qsTr("Unknown"))
ToolTip.visible: cardHover.hovered
ToolTip.delay: 300
HoverHandler {
id: cardHover
}
RowLayout {
anchors.fill: parent
anchors.margins: 12
@@ -327,6 +338,23 @@ AppletItem {
return info
}
// 解析驱动名称
function parseDriverName(info) {
var driver = parseDriverInfo(info)
var parts = driver.split(" ")
return parts[0] || qsTr("Unknown")
}
// 解析驱动版本号
function parseDriverVersion(info) {
var driver = parseDriverInfo(info)
var parts = driver.split(" ")
if (parts.length > 1) {
return parts[1]
}
return ""
}
// 识别 GPU 厂商简称
function parseGpuVendorShort(info) {
var name = info.toLowerCase()
@@ -28,5 +28,20 @@
<source>Refresh</source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>GPU: </source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Driver: </source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Version: </source>
<translation></translation>
</message>
</context>
</TS>
@@ -28,5 +28,20 @@
<source>Refresh</source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>GPU: </source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Driver: </source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Version: </source>
<translation></translation>
</message>
</context>
</TS>