From a97621b1cb203b0e3a7dd07d88c5422b798cbfd8 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 1 Oct 2022 19:19:15 +0100 Subject: Added window swallowing --- src/helpers/MiscFunctions.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/helpers/MiscFunctions.cpp') 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 -- cgit v1.2.3