From 2a5ae1a9f3ddc14056d64d3f69a2d40e4acd4364 Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 5 Dec 2024 17:55:42 +0300 Subject: [PATCH 1/3] WindowTracker: Search desktop file by process name --- src/WindowTracker.vala | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/WindowTracker.vala b/src/WindowTracker.vala index 74f2f8455..8fcc69caa 100644 --- a/src/WindowTracker.vala +++ b/src/WindowTracker.vala @@ -63,7 +63,46 @@ public class Gala.WindowTracker : GLib.Object { } } - return null; + // try to guess app_info name by process name + var file = File.new_for_path ("/proc/%d/comm".printf ((int) pid)); + + try { + var dis = new DataInputStream (file.read ()); + var name = dis.read_line (null); + + if (name != null && name != "") { + name = name.concat (".desktop"); + unowned var app = AppSystem.get_default ().lookup_app (name); + if (app != null) { + return app; + } + } + + // this particular process's doesn't have corresponding desktop file + // but maybe parent process has it + + var stat_file = File.new_for_path ("/proc/%d/stat".printf ((int) pid)); + var stat_dis = new DataInputStream (stat_file.read ()); + var stats = stat_dis.read_line (null).split (" "); + + if (stats.length < 3) { + warning ("WindowTracker.get_app_from_pid: stat file has wrong format"); + } + + int parent_pid; + if (!int.try_parse (stats[3], out parent_pid, null, 10)) { + warning ("WindowTracker.get_app_from_pid: stat file doesn't have parent pid"); + } + + if (parent_pid == pid || pid < 1) { + return null; + } + + return get_app_from_pid (parent_pid); + } catch (Error e) { + critical (e.message); + return null; + } } private unowned Gala.App? get_app_from_window_pid (Meta.Window window) { From e13680018a9a82cb83e0c8df220dbeb4cda2ed4d Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 5 Dec 2024 17:57:16 +0300 Subject: [PATCH 2/3] Fix typo --- src/WindowTracker.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WindowTracker.vala b/src/WindowTracker.vala index 8fcc69caa..b63006a8e 100644 --- a/src/WindowTracker.vala +++ b/src/WindowTracker.vala @@ -78,7 +78,7 @@ public class Gala.WindowTracker : GLib.Object { } } - // this particular process's doesn't have corresponding desktop file + // this particular process doesn't have corresponding desktop file // but maybe parent process has it var stat_file = File.new_for_path ("/proc/%d/stat".printf ((int) pid)); From d4594a29cd34a57ac60e7b25ab5e15d24bf15f39 Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 5 Dec 2024 19:43:27 +0300 Subject: [PATCH 3/3] Add missing returns --- src/WindowTracker.vala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/WindowTracker.vala b/src/WindowTracker.vala index b63006a8e..36a1a8e33 100644 --- a/src/WindowTracker.vala +++ b/src/WindowTracker.vala @@ -85,13 +85,15 @@ public class Gala.WindowTracker : GLib.Object { var stat_dis = new DataInputStream (stat_file.read ()); var stats = stat_dis.read_line (null).split (" "); - if (stats.length < 3) { + if (stats.length < 4) { warning ("WindowTracker.get_app_from_pid: stat file has wrong format"); + return null; } int parent_pid; if (!int.try_parse (stats[3], out parent_pid, null, 10)) { warning ("WindowTracker.get_app_from_pid: stat file doesn't have parent pid"); + return null; } if (parent_pid == pid || pid < 1) {