Skip to content

Commit 4ae3e79

Browse files
committed
feat: detect session type and extend gpu verification details
1 parent f43481f commit 4ae3e79

2 files changed

Lines changed: 72 additions & 39 deletions

File tree

src/backend/nvidia/detector.cpp

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "detector.h"
2+
23
#include "system/commandrunner.h"
34

45
#include <QFile>
6+
#include <QtGlobal>
57
#include <QRegularExpression>
68
#include <QTextStream>
79

@@ -16,6 +18,7 @@ NvidiaDetector::GpuInfo NvidiaDetector::detect() const {
1618
info.driverLoaded = isModuleLoaded(QStringLiteral("nvidia"));
1719
info.nouveauActive = isModuleLoaded(QStringLiteral("nouveau"));
1820
info.secureBootEnabled = detectSecureBoot();
21+
info.sessionType = detectSessionType();
1922

2023
return info;
2124
}
@@ -30,43 +33,60 @@ QString NvidiaDetector::installedDriverVersion() const {
3033
return detectDriverVersion();
3134
}
3235

36+
QString NvidiaDetector::activeDriver() const {
37+
if (m_info.driverLoaded)
38+
return QStringLiteral("Kapali Kaynak (NVIDIA)");
39+
if (m_info.nouveauActive)
40+
return QStringLiteral("Acik Kaynak (Nouveau)");
41+
return QStringLiteral("Yuklu Degil/Bilinmiyor");
42+
}
43+
3344
QString NvidiaDetector::verificationReport() const {
3445
const QString gpuText = m_info.found ? m_info.name : QStringLiteral("Yok");
35-
const QString driverText =
36-
m_info.driverVersion.isEmpty() ? QStringLiteral("Yok") : m_info.driverVersion;
37-
const QString secureBootText = m_info.secureBootEnabled ? QStringLiteral("Acik")
38-
: QStringLiteral("Kapali/Bilinmiyor");
39-
40-
return QStringLiteral("GPU: %1\nSurucu Versiyonu: %2\nSecure Boot: %3\nNVIDIA Modulu: %4\nNouveau: %5")
41-
.arg(gpuText, driverText, secureBootText,
42-
m_info.driverLoaded ? QStringLiteral("Yuklu") : QStringLiteral("Yuklu degil"),
43-
m_info.nouveauActive ? QStringLiteral("Aktif") : QStringLiteral("Aktif degil"));
46+
const QString versionText = m_info.driverVersion.isEmpty()
47+
? QStringLiteral("Yok")
48+
: m_info.driverVersion;
49+
50+
return QStringLiteral(
51+
"GPU: %1\nSurucu Versiyonu: %2\nSecure Boot: %3\nOturum: %4\n"
52+
"NVIDIA Modulu: %5\nNouveau: %6")
53+
.arg(gpuText, versionText,
54+
m_info.secureBootEnabled ? QStringLiteral("Acik")
55+
: QStringLiteral("Kapali/Bilinmiyor"),
56+
m_info.sessionType.isEmpty() ? QStringLiteral("Bilinmiyor")
57+
: m_info.sessionType,
58+
m_info.driverLoaded ? QStringLiteral("Yuklu")
59+
: QStringLiteral("Yuklu degil"),
60+
m_info.nouveauActive ? QStringLiteral("Aktif")
61+
: QStringLiteral("Aktif degil"));
62+
}
63+
64+
void NvidiaDetector::refresh() {
65+
m_info = detect();
66+
emit infoChanged();
4467
}
4568

4669
QString NvidiaDetector::detectGpuName() const {
4770
CommandRunner runner;
4871

49-
// lspci ile PCI cihazlarını listele, NVIDIA olanı filtrele
5072
const auto result =
5173
runner.run(QStringLiteral("lspci"), {QStringLiteral("-mm")});
5274

5375
if (!result.success())
5476
return {};
5577

56-
// lspci -mm çıktısında NVIDIA GPU satırını ara
5778
const QStringList lines = result.stdout.split(QLatin1Char('\n'));
5879
for (const QString &line : lines) {
5980
if (line.contains(QStringLiteral("NVIDIA"), Qt::CaseInsensitive) &&
6081
line.contains(QStringLiteral("VGA"), Qt::CaseInsensitive)) {
61-
// Tırnak işaretleri arasındaki model adını çıkar
6282
static const QRegularExpression re(QStringLiteral("\"([^\"]+)\""));
6383
auto it = re.globalMatch(line);
6484
QStringList parts;
6585
while (it.hasNext())
6686
parts << it.next().captured(1);
6787

6888
if (parts.size() >= 3)
69-
return parts[2]; // Model adı 3. tırnak grubunda
89+
return parts[2];
7090
}
7191
}
7292

@@ -76,15 +96,13 @@ QString NvidiaDetector::detectGpuName() const {
7696
QString NvidiaDetector::detectDriverVersion() const {
7797
CommandRunner runner;
7898

79-
// nvidia-smi varsa sürücü versiyonunu döner
8099
const auto result = runner.run(QStringLiteral("nvidia-smi"),
81100
{QStringLiteral("--query-gpu=driver_version"),
82101
QStringLiteral("--format=csv,noheader")});
83102

84103
if (result.success())
85104
return result.stdout.trimmed();
86105

87-
// nvidia-smi yoksa modinfo'dan dene
88106
const auto modinfo =
89107
runner.run(QStringLiteral("modinfo"), {QStringLiteral("nvidia")});
90108

@@ -100,7 +118,6 @@ QString NvidiaDetector::detectDriverVersion() const {
100118
}
101119

102120
bool NvidiaDetector::isModuleLoaded(const QString &moduleName) const {
103-
// /proc/modules dosyasını oku — yüklü kernel modüllerini listeler
104121
QFile modules(QStringLiteral("/proc/modules"));
105122
if (!modules.open(QIODevice::ReadOnly | QIODevice::Text))
106123
return false;
@@ -121,13 +138,29 @@ bool NvidiaDetector::detectSecureBoot() const {
121138
runner.run(QStringLiteral("mokutil"), {QStringLiteral("--sb-state")});
122139

123140
if (result.success() || result.exitCode == 1) {
124-
return result.stdout.contains(QStringLiteral("enabled"), Qt::CaseInsensitive);
141+
return result.stdout.contains(QStringLiteral("enabled"),
142+
Qt::CaseInsensitive);
125143
}
126144

127145
return false;
128146
}
129147

130-
void NvidiaDetector::refresh() {
131-
m_info = detect();
132-
emit infoChanged();
148+
QString NvidiaDetector::detectSessionType() const {
149+
const QString envType = qEnvironmentVariable("XDG_SESSION_TYPE").trimmed().toLower();
150+
if (!envType.isEmpty())
151+
return envType;
152+
153+
CommandRunner runner;
154+
const auto loginctl = runner.run(
155+
QStringLiteral("loginctl"),
156+
{QStringLiteral("show-session"), qEnvironmentVariable("XDG_SESSION_ID"),
157+
QStringLiteral("-p"), QStringLiteral("Type"), QStringLiteral("--value")});
158+
159+
if (loginctl.success()) {
160+
const QString type = loginctl.stdout.trimmed().toLower();
161+
if (!type.isEmpty())
162+
return type;
163+
}
164+
165+
return QStringLiteral("unknown");
133166
}

src/backend/nvidia/detector.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include <QObject>
44
#include <QString>
55

6-
// NvidiaDetector: Sistemdeki NVIDIA GPU ve sürücü durumunu tespit eder.
7-
// Hiçbir kurulum yapmaz — sadece okur ve raporlar.
6+
// NvidiaDetector: Sistemdeki NVIDIA GPU ve surucu durumunu tespit eder.
87
class NvidiaDetector : public QObject {
98
Q_OBJECT
109

@@ -14,17 +13,21 @@ class NvidiaDetector : public QObject {
1413
Q_PROPERTY(bool driverLoaded READ driverLoaded NOTIFY infoChanged)
1514
Q_PROPERTY(bool nouveauActive READ nouveauActive NOTIFY infoChanged)
1615
Q_PROPERTY(bool secureBootEnabled READ secureBootEnabled NOTIFY infoChanged)
16+
Q_PROPERTY(QString sessionType READ sessionType NOTIFY infoChanged)
17+
Q_PROPERTY(bool waylandSession READ waylandSession NOTIFY infoChanged)
18+
Q_PROPERTY(QString activeDriver READ activeDriver NOTIFY infoChanged)
1719
Q_PROPERTY(QString verificationReport READ verificationReport NOTIFY infoChanged)
1820

1921
public:
2022
struct GpuInfo {
21-
bool found = false; // NVIDIA GPU var mı?
22-
QString name; // GPU adı (ör: "NVIDIA GeForce RTX 3060")
23-
QString driverVersion; // Kurulu sürücü versiyonu (ör: "535.154.05")
24-
QString vbiosVersion; // VBIOS versiyonu
25-
bool driverLoaded = false; // nvidia.ko kernel modülü yüklü mü?
26-
bool nouveauActive = false; // Nouveau (açık kaynak) sürücü aktif mi?
27-
bool secureBootEnabled = false; // UEFI Secure Boot açık mı?
23+
bool found = false;
24+
QString name;
25+
QString driverVersion;
26+
QString vbiosVersion;
27+
bool driverLoaded = false;
28+
bool nouveauActive = false;
29+
bool secureBootEnabled = false;
30+
QString sessionType;
2831
};
2932

3033
explicit NvidiaDetector(QObject *parent = nullptr);
@@ -35,14 +38,17 @@ class NvidiaDetector : public QObject {
3538
bool driverLoaded() const { return m_info.driverLoaded; }
3639
bool nouveauActive() const { return m_info.nouveauActive; }
3740
bool secureBootEnabled() const { return m_info.secureBootEnabled; }
41+
QString sessionType() const { return m_info.sessionType; }
42+
bool waylandSession() const {
43+
return m_info.sessionType.compare(QStringLiteral("wayland"),
44+
Qt::CaseInsensitive) == 0;
45+
}
46+
QString activeDriver() const;
3847
QString verificationReport() const;
3948

4049
Q_INVOKABLE void refresh();
4150

42-
// Tüm GPU bilgisini toplar ve döner
4351
GpuInfo detect() const;
44-
45-
// Hızlı kontroller
4652
bool hasNvidiaGpu() const;
4753
bool isDriverInstalled() const;
4854
QString installedDriverVersion() const;
@@ -51,17 +57,11 @@ class NvidiaDetector : public QObject {
5157
void infoChanged();
5258

5359
private:
54-
// lspci çıktısından GPU adını çıkar
5560
QString detectGpuName() const;
56-
57-
// nvidia-smi'den sürücü versiyonunu çıkar
5861
QString detectDriverVersion() const;
59-
60-
// /proc/modules'dan modül durumunu kontrol et
6162
bool isModuleLoaded(const QString &moduleName) const;
62-
63-
// mokutil ile Secure Boot durumunu kontrol et
6463
bool detectSecureBoot() const;
64+
QString detectSessionType() const;
6565

6666
GpuInfo m_info;
6767
};

0 commit comments

Comments
 (0)