comparison dep/animone/src/strategist.cc @ 340:74e2365326c6

dep/animone: add experimental accessibility strategy I also moved most of the functions out of util/win32.cc, because that file is meant for things that are shared between the different functions, and currently that is only wide string conversion helpers.
author Paper <paper@paper.us.eu.org>
date Wed, 19 Jun 2024 23:13:55 -0400
parents b1f625b0227c
children 886f66775f31
comparison
equal deleted inserted replaced
339:eac06513db86 340:74e2365326c6
1 #include <regex> 1 #include <regex>
2 #include <unordered_map> 2 #include <unordered_map>
3 3
4 #include "animone.h" 4 #include "animone.h"
5 #include "animone/a11y.h"
5 #include "animone/fd.h" 6 #include "animone/fd.h"
6 #include "animone/strategies.h" 7 #include "animone/strategies.h"
7 #include "animone/util.h" 8 #include "animone/util.h"
8 9
9 /* this was STUPIDLY slow in Anisthesia, oops! */ 10 /* This file was changed lots from anisthesia. Most notably we don't use classes here
11 * anymore, and we just pass the result vector to different function that append
12 * to the result (which is better imo) */
10 13
11 namespace animone::internal { 14 namespace animone::internal {
12 15
13 static bool ApplyWindowTitleFormat(const std::string& format, std::string& title) { 16 static bool ApplyWindowTitleFormat(const std::string& format, std::string& title) {
14 if (format.empty()) 17 if (format.empty())
43 46
44 static bool AddMedia(Result& result, const MediaInfo media_information) { 47 static bool AddMedia(Result& result, const MediaInfo media_information) {
45 if (media_information.value.empty()) 48 if (media_information.value.empty())
46 return false; 49 return false;
47 50
48 Media media; 51 Media media = {
49 media.information.push_back(media_information); 52 .information = {media_information}
53 };
50 result.media.push_back(std::move(media)); 54 result.media.push_back(std::move(media));
51 55
52 return true; 56 return true;
53 } 57 }
58
59 /* ------------------------------------------------------------------------- */
60 /* strategies */
54 61
55 static bool ApplyWindowTitleStrategy(std::vector<Result>& results) { 62 static bool ApplyWindowTitleStrategy(std::vector<Result>& results) {
56 bool success = false; 63 bool success = false;
57 64
58 for (auto& result : results) { 65 for (auto& result : results) {
92 EnumerateOpenFiles(pids, open_file_proc); 99 EnumerateOpenFiles(pids, open_file_proc);
93 100
94 return success; 101 return success;
95 } 102 }
96 103
104 static bool ApplyAccessibilityStrategy(std::vector<Result>& results) {
105 bool success = false;
106
107 for (Result& result : results) {
108 auto web_browser_proc = [&result](const WebBrowserInformation& info) {
109 auto value = info.value;
110
111 switch (info.type) {
112 case WebBrowserInformationType::Address:
113 AddMedia(result, {MediaInfoType::Url, value});
114 break;
115 case WebBrowserInformationType::Title:
116 ApplyWindowTitleFormat(result.player.window_title_format, value);
117 AddMedia(result, {MediaInfoType::Title, value});
118 break;
119 case WebBrowserInformationType::Tab:
120 AddMedia(result, {MediaInfoType::Tab, value});
121 break;
122 }
123 };
124
125 success |= GetWebBrowserInformation(result.window, web_browser_proc);
126 }
127
128 return success;
129 }
130
131 /* ------------------------------------------------------------------------- */
132
97 bool ApplyStrategies(std::vector<Result>& results) { 133 bool ApplyStrategies(std::vector<Result>& results) {
98 bool success = false; 134 bool success = false;
99 135
100 success |= ApplyWindowTitleStrategy(results); 136 success |= ApplyWindowTitleStrategy(results);
101 success |= ApplyOpenFilesStrategy(results); 137 success |= ApplyOpenFilesStrategy(results);
138 success |= ApplyAccessibilityStrategy(results);
102 139
103 return success; 140 return success;
104 } 141 }
105 142
106 ////////////////////////////////////////////////////////////////////////////////
107
108 } // namespace animone::internal 143 } // namespace animone::internal