summaryrefslogtreecommitdiff
path: root/src/helpers/MiscFunctions.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-10-01 19:19:15 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-10-01 19:19:15 +0100
commita97621b1cb203b0e3a7dd07d88c5422b798cbfd8 (patch)
treee5ee5f450dd823d4cdf007ce6d73d9b3b3f80ff3 /src/helpers/MiscFunctions.cpp
parent355366714eb725d72286a7b6744d20a993ad57e5 (diff)
Added window swallowing
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
-rw-r--r--src/helpers/MiscFunctions.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index 22afd4a0..e933d496 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -354,3 +354,38 @@ void matrixProjection(float mat[9], int w, int h, wl_output_transform tr) {
// Identity
mat[8] = 1.0f;
}
+
+int64_t getPPIDof(int64_t pid) {
+ std::string dir = "/proc/" + std::to_string(pid) + "/status";
+ FILE* infile;
+
+ infile = fopen(dir.c_str(), "r");
+ if (!infile)
+ return 0;
+
+ char* line = nullptr;
+ size_t len = 0;
+ ssize_t len2 = 0;
+
+ std::string pidstr;
+
+ while ((len2 = getline(&line, &len, infile)) != -1) {
+ if (strstr(line, "PPid:")) {
+ pidstr = std::string(line, len2);
+ const auto tabpos = pidstr.find_last_of('\t');
+ if (tabpos != std::string::npos)
+ pidstr = pidstr.substr(tabpos);
+ break;
+ }
+ }
+
+ fclose(infile);
+ if (line)
+ free(line);
+
+ try {
+ return std::stoll(pidstr);
+ } catch (std::exception& e) {
+ return 0;
+ }
+} \ No newline at end of file