Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WindowTracker: Search desktop file by process name #2141

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/WindowTracker.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 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");
lenemter marked this conversation as resolved.
Show resolved Hide resolved
}

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) {
Expand Down
Loading