[plasma/plasma-workspace] libtaskmanager: libtaskmanager: Split up servicesFromPid function

Nicolas Fella <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 1c70ce94055f21479b2982fa6c1ab89f1199d6f9 by Nicolas Fella.
Committed on 10/08/2026 at 14:48.
Pushed by nicolasfella into branch 'master'.

libtaskmanager: Split up servicesFromPid function

Extract the part that searches the environment

M  +9    -1    libtaskmanager/tasktools.cpp
M  +6    -0    libtaskmanager/tasktools.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/1c70ce94055f21479b2982fa6c1ab89f1199d6f9

diff --git a/libtaskmanager/tasktools.cpp b/libtaskmanager/tasktools.cpp
index 57ca8c4fe4..f5b85211a1 100644
--- a/libtaskmanager/tasktools.cpp
+++ b/libtaskmanager/tasktools.cpp
@@ -278,6 +278,10 @@ QUrl windowUrlFromMetadata(const QString &appId, quint32 pid, const QString &xWi
             }
         }
 
+        if (services.isEmpty()) {
+            services = servicesFromEnvironment(pid);
+        }
+
         // Ok, absolute *last* chance, try matching via pid (but only if we have not already tried this!) ...
         if (services.isEmpty() && !triedPid) {
             services = servicesFromPid(pid);
@@ -345,7 +349,7 @@ QUrl windowUrlFromMetadata(const QString &appId, quint32 pid, const QString &xWi
     return url;
 }
 
-KService::List servicesFromPid(quint32 pid)
+KService::List servicesFromEnvironment(quint32 pid)
 {
     if (pid == 0) {
         return {};
@@ -385,7 +389,11 @@ KService::List servicesFromPid(quint32 pid)
             }
         }
     }
+    return {};
+}
 
+KService::List servicesFromPid(quint32 pid)
+{
     auto proc = KProcessList::processInfo(pid);
     if (!proc.isValid()) {
         return {};
diff --git a/libtaskmanager/tasktools.h b/libtaskmanager/tasktools.h
index dde29613af..eec7ed3d93 100644
--- a/libtaskmanager/tasktools.h
+++ b/libtaskmanager/tasktools.h
@@ -90,6 +90,12 @@ TASKMANAGER_EXPORT QUrl windowUrlFromMetadata(const QString &appId, quint32 pid
  */
 TASKMANAGER_EXPORT KService::List servicesFromPid(quint32 pid);
 
+/**
+ * Tries to map a given application to a desktop file
+ * by looking into its process environment.
+ */
+KService::List servicesFromEnvironment(quint32 pid);
+
 /**
  * Returns a list of (usually application) KService instances for the
  * given process command line and process name, by mangling the command
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.