13#include <config-kwin.h>
18#include <QLoggingCategory>
21#include <KApplicationTrader>
26const static QString s_waylandInterfaceName = QStringLiteral(
"X-KDE-Wayland-Interfaces");
27const static QString s_dbusRestrictedInterfaceName = QStringLiteral(
"X-KDE-DBUS-Restricted-Interfaces");
29static QStringList fetchProcessServiceField(
const QString &executablePath,
const QString &fieldName)
32 static QLoggingCategory KWIN_UTILS(
"KWIN_UTILS", QtWarningMsg);
33 const auto servicesFound = KApplicationTrader::query([&executablePath](
const KService::Ptr &service) {
34 const auto splitCommandList = QProcess::splitCommand(service->exec());
35 if (splitCommandList.isEmpty()) {
38 return QFileInfo(splitCommandList.first()).canonicalFilePath() == executablePath;
41 if (servicesFound.isEmpty()) {
42 qCDebug(KWIN_UTILS) <<
"Could not find the desktop file for" << executablePath;
46 const auto fieldValues = servicesFound.first()->property<QStringList>(fieldName);
47 if (KWIN_UTILS().isDebugEnabled()) {
48 qCDebug(KWIN_UTILS) <<
"Interfaces found for" << executablePath << fieldName <<
":" << fieldValues;
53static inline QStringList fetchRequestedInterfacesForDesktopId(
const QString &desktopId)
55 const auto service = KService::serviceByDesktopName(desktopId);
59 return service->property<QStringList>(s_waylandInterfaceName);
62static inline QStringList fetchRequestedInterfaces(
const QString &executablePath)
64 return fetchProcessServiceField(executablePath, s_waylandInterfaceName);
67static inline QStringList fetchRestrictedDBusInterfacesFromPid(
const uint pid)
69 const auto executablePath = QFileInfo(QStringLiteral(
"/proc/%1/exe").arg(pid)).symLinkTarget();
70 return fetchProcessServiceField(executablePath, s_dbusRestrictedInterfaceName);