Mercurial > minori
comparison dep/animone/src/animone.cc @ 266:1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
apparently I broke these, and even now the x11 code *still* doesn't want
to work correctly (at least on FreeBSD). half of the PID response codes
are just 0 or the PID for the X server itself... wtf?
maybe dwm just doesn't support the XRes extension, or I'm just stupid.
i don't know.
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Thu, 11 Apr 2024 22:05:41 -0400 |
| parents | 862d0d8619f6 |
| children | b1f625b0227c |
comparison
equal
deleted
inserted
replaced
| 265:ff0b2052b234 | 266:1a6a5d3a94cd |
|---|---|
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include <iostream> | |
| 13 | |
| 12 namespace animone { | 14 namespace animone { |
| 13 | 15 |
| 14 namespace internal { | 16 namespace internal { |
| 15 | 17 |
| 16 static bool IsExecutableInList(const Player& player, const std::string& name) { | 18 static bool IsExecutableInList(const Player& player, const Process& proc) { |
| 17 std::string stem; | |
| 18 #ifdef WIN32 | |
| 19 if (!util::Stem(name, stem)) | |
| 20 #endif | |
| 21 stem = name; | |
| 22 | |
| 23 for (const auto& pattern : player.executables) | 19 for (const auto& pattern : player.executables) |
| 24 if (util::CheckPattern(pattern, stem)) | 20 if (util::CheckPattern(pattern, proc.name)) |
| 25 return true; | 21 return true; |
| 26 | 22 |
| 27 return false; | 23 return false; |
| 28 } | 24 } |
| 29 | 25 |
| 45 | 41 |
| 46 } // namespace internal | 42 } // namespace internal |
| 47 | 43 |
| 48 bool GetResults(const std::vector<Player>& players, std::vector<Result>& results) { | 44 bool GetResults(const std::vector<Player>& players, std::vector<Result>& results) { |
| 49 auto window_proc = [&](const Process& process, const Window& window) -> bool { | 45 auto window_proc = [&](const Process& process, const Window& window) -> bool { |
| 50 for (const auto& player : players) { | 46 for (const auto& player : players) |
| 51 if (internal::IsWindowInList(player, window)) | 47 if (internal::IsWindowInList(player, window) && internal::IsExecutableInList(player, process)) |
| 52 results.push_back({player, process, window, {}}); | 48 results.push_back({player, process, window, {}}); |
| 53 } | |
| 54 | 49 |
| 55 return true; | 50 return true; |
| 56 }; | 51 }; |
| 57 | 52 |
| 58 if (internal::EnumerateWindows(window_proc)) | 53 if (internal::EnumerateWindows(window_proc) && internal::ApplyStrategies(results)) |
| 59 return internal::ApplyStrategies(results); | 54 return true; |
| 60 | 55 |
| 61 /* fallback, enumerate over open processes instead */ | 56 /* fallback, enumerate over open processes instead */ |
| 62 auto process_proc = [&](const Process& process) -> bool { | 57 auto process_proc = [&](const Process& process) -> bool { |
| 63 for (const auto& player : players) | 58 for (const auto& player : players) |
| 64 if (internal::IsExecutableInList(player, process.name)) | 59 if (internal::IsExecutableInList(player, process)) |
| 65 results.push_back({player, process, {}, {}}); | 60 results.push_back({player, process, {}, {}}); |
| 66 | 61 |
| 67 return true; | 62 return true; |
| 68 }; | 63 }; |
| 69 | 64 |
| 70 if (internal::EnumerateOpenProcesses(process_proc)) | 65 if (internal::EnumerateOpenProcesses(process_proc) && internal::ApplyStrategies(results)) |
| 71 return internal::ApplyStrategies(results); | 66 return true; |
| 72 | 67 |
| 73 return false; | 68 return false; |
| 74 } | 69 } |
| 75 | 70 |
| 76 } // namespace animone | 71 } // namespace animone |
