Mercurial > minori
annotate dep/animone/src/animone.cc @ 268:382b50754fe4
dep/animone: make osx code a bit less hacky
it would be nice if macos actually provided a real API for getting
window titles (outside of the accessibility api). the accessibility
API is a real mess to work with; the user has to give permission to
access it under newer versions.
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Fri, 12 Apr 2024 05:21:45 -0400 |
| parents | 1a6a5d3a94cd |
| children | b1f625b0227c |
| rev | line source |
|---|---|
| 258 | 1 #include "animone.h" |
| 2 #include "animone/fd.h" | |
| 3 #include "animone/strategies.h" | |
| 4 #include "animone/types.h" | |
| 5 #include "animone/util.h" | |
| 6 #include "animone/win.h" | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
|
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
12 #include <iostream> |
|
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
13 |
| 258 | 14 namespace animone { |
| 15 | |
| 16 namespace internal { | |
| 17 | |
|
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
18 static bool IsExecutableInList(const Player& player, const Process& proc) { |
| 258 | 19 for (const auto& pattern : player.executables) |
|
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
20 if (util::CheckPattern(pattern, proc.name)) |
| 258 | 21 return true; |
| 22 | |
| 23 return false; | |
| 24 } | |
| 25 | |
| 26 static bool IsWindowInList(const Player& player, const Window& window) { | |
| 27 for (const auto& pattern : player.windows) | |
| 28 if (util::CheckPattern(pattern, window.class_name)) | |
| 29 return true; | |
| 30 | |
| 31 return false; | |
| 32 } | |
| 33 | |
| 34 static bool PlayerHasStrategy(const Player& player, const Strategy& strategy) { | |
| 35 for (const auto& pstrategy : player.strategies) | |
| 36 if (pstrategy == strategy) | |
| 37 return true; | |
| 38 | |
| 39 return false; | |
| 40 } | |
| 41 | |
| 42 } // namespace internal | |
| 43 | |
| 44 bool GetResults(const std::vector<Player>& players, std::vector<Result>& results) { | |
| 45 auto window_proc = [&](const Process& process, const Window& window) -> bool { | |
|
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
46 for (const auto& player : players) |
|
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
47 if (internal::IsWindowInList(player, window) && internal::IsExecutableInList(player, process)) |
| 258 | 48 results.push_back({player, process, window, {}}); |
| 49 | |
| 50 return true; | |
| 51 }; | |
| 52 | |
|
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
53 if (internal::EnumerateWindows(window_proc) && internal::ApplyStrategies(results)) |
|
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
54 return true; |
| 258 | 55 |
| 56 /* fallback, enumerate over open processes instead */ | |
| 57 auto process_proc = [&](const Process& process) -> bool { | |
| 58 for (const auto& player : players) | |
|
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
59 if (internal::IsExecutableInList(player, process)) |
| 258 | 60 results.push_back({player, process, {}, {}}); |
| 61 | |
| 62 return true; | |
| 63 }; | |
| 64 | |
|
266
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
65 if (internal::EnumerateOpenProcesses(process_proc) && internal::ApplyStrategies(results)) |
|
1a6a5d3a94cd
dep/animone: make bsd.cc and x11.cc actually work
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
66 return true; |
| 258 | 67 |
| 68 return false; | |
| 69 } | |
| 70 | |
| 71 } // namespace animone |
