32 lines
1.0 KiB
C++
32 lines
1.0 KiB
C++
|
//
|
||
|
// Created by zpf on 2023/2/13.
|
||
|
//
|
||
|
#include "utils.h"
|
||
|
#include <QFile>
|
||
|
#include <QByteArray>
|
||
|
#include <KWindowSystem>
|
||
|
using namespace UkuiNotification;
|
||
|
QString Utils::desktopEntryFromPid(uint pid)
|
||
|
{
|
||
|
return QString();
|
||
|
}
|
||
|
QString Utils::displayFromPid(uint pid)
|
||
|
{
|
||
|
QFile environFile(QStringLiteral("/proc/%1/environ").arg(QString::number(pid)));
|
||
|
if (environFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||
|
const QByteArray DISPLAY = KWindowSystem::isPlatformWayland() ? QByteArrayLiteral("WAYLAND_DISPLAY") : QByteArrayLiteral("DISPLAY");
|
||
|
const auto lines = environFile.readAll().split('\0');
|
||
|
for (const QByteArray &line : lines) {
|
||
|
const int equalsIdx = line.indexOf('=');
|
||
|
if (equalsIdx <= 0) {
|
||
|
continue;
|
||
|
}
|
||
|
const QByteArray key = line.left(equalsIdx);
|
||
|
if (key == DISPLAY) {
|
||
|
const QByteArray value = line.mid(equalsIdx + 1);
|
||
|
return value;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return QString();
|
||
|
}
|