Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/dep/animone/src/strategist.cc Wed Jun 19 14:02:11 2024 -0400 +++ b/dep/animone/src/strategist.cc Wed Jun 19 23:13:55 2024 -0400 @@ -2,11 +2,14 @@ #include <unordered_map> #include "animone.h" +#include "animone/a11y.h" #include "animone/fd.h" #include "animone/strategies.h" #include "animone/util.h" -/* this was STUPIDLY slow in Anisthesia, oops! */ +/* This file was changed lots from anisthesia. Most notably we don't use classes here + * anymore, and we just pass the result vector to different function that append + * to the result (which is better imo) */ namespace animone::internal { @@ -45,13 +48,17 @@ if (media_information.value.empty()) return false; - Media media; - media.information.push_back(media_information); + Media media = { + .information = {media_information} + }; result.media.push_back(std::move(media)); return true; } +/* ------------------------------------------------------------------------- */ +/* strategies */ + static bool ApplyWindowTitleStrategy(std::vector<Result>& results) { bool success = false; @@ -94,15 +101,43 @@ return success; } +static bool ApplyAccessibilityStrategy(std::vector<Result>& results) { + bool success = false; + + for (Result& result : results) { + auto web_browser_proc = [&result](const WebBrowserInformation& info) { + auto value = info.value; + + switch (info.type) { + case WebBrowserInformationType::Address: + AddMedia(result, {MediaInfoType::Url, value}); + break; + case WebBrowserInformationType::Title: + ApplyWindowTitleFormat(result.player.window_title_format, value); + AddMedia(result, {MediaInfoType::Title, value}); + break; + case WebBrowserInformationType::Tab: + AddMedia(result, {MediaInfoType::Tab, value}); + break; + } + }; + + success |= GetWebBrowserInformation(result.window, web_browser_proc); + } + + return success; +} + +/* ------------------------------------------------------------------------- */ + bool ApplyStrategies(std::vector<Result>& results) { bool success = false; success |= ApplyWindowTitleStrategy(results); success |= ApplyOpenFilesStrategy(results); + success |= ApplyAccessibilityStrategy(results); return success; } -//////////////////////////////////////////////////////////////////////////////// - } // namespace animone::internal