annotate dep/animone/src/animone.cc @ 271:f01b6e9c8fa2

dep/animone: make OS X code build
author Paper <paper@paper.us.eu.org>
date Sun, 14 Apr 2024 22:28:50 -0400
parents 1a6a5d3a94cd
children b1f625b0227c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
1 #include "animone.h"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
2 #include "animone/fd.h"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
3 #include "animone/strategies.h"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
4 #include "animone/types.h"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
5 #include "animone/util.h"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
6 #include "animone/win.h"
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
7
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
8 #include <set>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
9 #include <string>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
10 #include <vector>
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
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
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
14 namespace animone {
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
15
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
16 namespace internal {
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
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
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
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
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
21 return true;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
22
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
23 return false;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
24 }
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
25
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
26 static bool IsWindowInList(const Player& player, const Window& window) {
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
27 for (const auto& pattern : player.windows)
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
28 if (util::CheckPattern(pattern, window.class_name))
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
29 return true;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
30
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
31 return false;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
32 }
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
33
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
34 static bool PlayerHasStrategy(const Player& player, const Strategy& strategy) {
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
35 for (const auto& pstrategy : player.strategies)
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
36 if (pstrategy == strategy)
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
37 return true;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
38
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
39 return false;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
40 }
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
41
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
42 } // namespace internal
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
43
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
44 bool GetResults(const std::vector<Player>& players, std::vector<Result>& results) {
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
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
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
48 results.push_back({player, process, window, {}});
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
49
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
50 return true;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
51 };
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
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
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
55
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
56 /* fallback, enumerate over open processes instead */
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
57 auto process_proc = [&](const Process& process) -> bool {
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
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
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
60 results.push_back({player, process, {}, {}});
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
61
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
62 return true;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
63 };
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
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
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
67
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
68 return false;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
69 }
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
70
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents:
diff changeset
71 } // namespace animone