ApplicationContext.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. #pragma once
  2. #include <cstdint>
  3. #include <filesystem>
  4. #include <map>
  5. #include <optional>
  6. #include <string>
  7. #include <vector>
  8. #include <glm/vec2.hpp>
  9. #include <glm/vec4.hpp>
  10. #include "ApplicationState.h"
  11. #include "WallpaperEngine/Data/JSON.h"
  12. #include "../Render/TextureProvider.h"
  13. #include "WallpaperEngine/Render/WallpaperState.h"
  14. #include "WallpaperEngine/VideoPlayback/VideoSegment.h"
  15. #include "WallpaperEngine/Data/Model/Project.h"
  16. namespace WallpaperEngine::Application {
  17. using namespace WallpaperEngine::Data::Assets;
  18. class ApplicationContext {
  19. public:
  20. ApplicationContext (int argc, char* argv[]);
  21. void loadSettingsFromArgv ();
  22. [[nodiscard]] std::optional<bool> resolveObjectVisibility (int id, const std::string& name) const;
  23. [[nodiscard]] std::optional<bool> resolveEffectVisibility (int id, const std::string& name) const;
  24. [[nodiscard]] std::optional<float> resolveAudioSensitivity (int id, const std::string& name) const;
  25. [[nodiscard]] std::optional<float> resolveSoundVolume (int id, const std::string& name) const;
  26. enum WINDOW_MODE {
  27. NORMAL_WINDOW = 0,
  28. DESKTOP_BACKGROUND = 1,
  29. EXPLICIT_WINDOW = 2,
  30. };
  31. enum WAYLAND_LAYER {
  32. WAYLAND_LAYER_BACKGROUND = 0,
  33. WAYLAND_LAYER_BOTTOM = 1,
  34. WAYLAND_LAYER_TOP = 2,
  35. WAYLAND_LAYER_OVERLAY = 3,
  36. };
  37. enum HRTF_MODE {
  38. HRTF_AUTO = 0,
  39. HRTF_ON = 1,
  40. HRTF_OFF = 2,
  41. };
  42. [[nodiscard]] static std::optional<HRTF_MODE> parseHrtfMode (const std::string& value);
  43. struct PlaylistSettings {
  44. uint32_t delayMinutes = 60;
  45. std::string mode = "timer";
  46. std::string order = "sequential";
  47. bool updateOnPause = false;
  48. bool videoSequence = false;
  49. bool beginFirst = false;
  50. bool playIntro = false;
  51. [[nodiscard]] bool hasIntro () const { return this->mode == "timer" && this->beginFirst && this->playIntro; }
  52. };
  53. struct PlaylistDefinition {
  54. std::string name;
  55. std::vector<std::filesystem::path> items;
  56. PlaylistSettings settings;
  57. };
  58. struct SpanGroup {
  59. std::vector<std::string> screens;
  60. std::filesystem::path background;
  61. WallpaperEngine::Render::WallpaperState::TextureUVsScaling scaling
  62. = WallpaperEngine::Render::WallpaperState::TextureUVsScaling::DefaultUVs;
  63. TextureFlags clamp = TextureFlags_ClampUVsBorder;
  64. float zoom = 1.0f;
  65. glm::vec2 offset = { 0.0f, 0.0f };
  66. WallpaperEngine::Render::WallpaperState::Alignment alignment = {};
  67. glm::vec4 cornerColor = { 0.0f, 0.0f, 0.0f, 1.0f };
  68. WallpaperEngine::Data::Model::ImageAdjustments imageAdjustments = {};
  69. };
  70. struct SplitScreen {
  71. enum Layout {
  72. LAYOUT_ASPECT = 0,
  73. LAYOUT_EQUAL = 1,
  74. LAYOUT_CENTER = 2,
  75. };
  76. std::string screen;
  77. std::vector<std::string> slots;
  78. Layout layout = LAYOUT_ASPECT;
  79. };
  80. [[nodiscard]] const SplitScreen* findSplitScreen (const std::string& screenOrSlot) const;
  81. [[nodiscard]] bool isScreenRequested (const std::string& name) const;
  82. [[nodiscard]] std::vector<std::string> describeRequestedScreens () const;
  83. struct {
  84. struct {
  85. bool onlyListProperties = false;
  86. bool onlyListObjects = false;
  87. bool onlyListAudioObjects = false;
  88. bool onlyListEffects = false;
  89. bool onlyListFonts = false;
  90. bool dumpStructure = false;
  91. bool noShaderCache = false;
  92. bool disableParticles = false;
  93. bool expandCanvas = false;
  94. bool repairAssets = false;
  95. bool postProcessingDisabled = false;
  96. bool ultraPostProcessing = false;
  97. bool displayHDR = false;
  98. int volumetricsQuality = 2;
  99. int shadowQuality = 2;
  100. int msaaSamples = 0;
  101. int supersampling = 1;
  102. std::vector<std::string> disabledObjects;
  103. std::vector<std::string> enabledObjects;
  104. std::vector<std::string> disabledEffects;
  105. std::vector<std::string> enabledEffects;
  106. std::map<std::string, float> audioSensitivity;
  107. std::map<std::string, float> soundVolume;
  108. std::filesystem::path assets;
  109. std::filesystem::path defaultBackground;
  110. std::map<std::string, std::filesystem::path> screenBackgrounds;
  111. std::map<std::string, std::string> properties;
  112. std::map<std::string, WallpaperEngine::Render::WallpaperState::TextureUVsScaling> screenScalings;
  113. std::map<std::string, TextureFlags> screenClamps;
  114. std::map<std::string, float> screenZooms;
  115. std::map<std::string, float> screenRenderScales;
  116. std::map<std::string, glm::vec2> screenOffsets;
  117. std::map<std::string, WallpaperEngine::Render::WallpaperState::Alignment> screenAlignments;
  118. std::map<std::string, glm::vec4> screenCornerColors;
  119. std::map<std::string, WallpaperEngine::Data::Model::ImageAdjustments> screenImageAdjustments;
  120. std::map<std::string, WallpaperEngine::VideoPlayback::VideoSegments> screenVideoSegments;
  121. std::map<std::string, PlaylistDefinition> screenPlaylists;
  122. std::optional<PlaylistDefinition> defaultPlaylist;
  123. std::vector<SpanGroup> spanGroups;
  124. std::vector<SplitScreen> splitScreens;
  125. bool webHost = false;
  126. std::string webHostShm;
  127. std::string webHostFrames;
  128. int webHostSocket = -1;
  129. uint32_t webHostWidth = 0;
  130. uint32_t webHostHeight = 0;
  131. std::optional<std::filesystem::path> controlFile;
  132. } general;
  133. struct {
  134. WINDOW_MODE mode;
  135. int maximumFPS;
  136. float playbackSpeed;
  137. WallpaperEngine::VideoPlayback::VideoSegments videoSegments;
  138. std::string hwdec;
  139. std::string webFrames;
  140. std::string frameLimiter;
  141. std::string transition;
  142. int transitionMs;
  143. bool freezeAnimations;
  144. bool pauseOnFullscreen;
  145. // only fullscreen toplevels that are also activated count (scrollable tiling compositors)
  146. bool pauseOnFullscreenOnlyWhenActive;
  147. bool pauseOnFocus;
  148. /** wlroots: maximized toplevels pause their outputs too (KDE and GNOME always do, like WE) */
  149. bool pauseOnMaximized;
  150. std::vector<std::string> fullscreenPauseIgnoreAppIds;
  151. std::optional<int> batteryFPS;
  152. int idlePauseMinutes;
  153. bool pauseOnLock;
  154. bool hdr;
  155. struct {
  156. bool baseOnly;
  157. bool noSolidFinal;
  158. bool passLog;
  159. bool brightnessLog;
  160. bool noPuppetAnimation;
  161. std::optional<int> objectFilter;
  162. std::vector<int> skipObjects;
  163. std::vector<int> skipEffects;
  164. } debug;
  165. struct {
  166. glm::ivec4 geometry;
  167. TextureFlags clamp;
  168. WallpaperEngine::Render::WallpaperState::TextureUVsScaling scalingMode;
  169. float zoom;
  170. glm::vec2 offset;
  171. WallpaperEngine::Render::WallpaperState::Alignment alignment;
  172. glm::vec4 cornerColor;
  173. WallpaperEngine::Data::Model::ImageAdjustments imageAdjustments;
  174. bool asBackground;
  175. bool regular;
  176. } window;
  177. struct {
  178. WAYLAND_LAYER layer;
  179. bool layerAuto;
  180. } wayland;
  181. } render;
  182. struct {
  183. bool enabled;
  184. /** 0-128 */
  185. int volume;
  186. bool automute;
  187. bool audioprocessing;
  188. std::optional<std::string> audioScreen;
  189. std::optional<int> ambientVolume;
  190. HRTF_MODE hrtf;
  191. } audio;
  192. struct {
  193. bool enabled;
  194. std::string host;
  195. uint16_t port;
  196. bool boost;
  197. /** WE's brightnessfactor, 1 = as is */
  198. float brightness;
  199. bool reduceFps;
  200. } leds;
  201. struct {
  202. bool enabled;
  203. bool disableparallax;
  204. bool clampParallaxToImageSize;
  205. std::filesystem::path inputFile;
  206. } mouse;
  207. struct {
  208. bool take;
  209. /** In frames, not seconds */
  210. uint32_t delay;
  211. std::filesystem::path path;
  212. } screenshot;
  213. } settings = {
  214. .general = {
  215. .onlyListProperties = false,
  216. .onlyListObjects = false,
  217. .onlyListAudioObjects = false,
  218. .onlyListEffects = false,
  219. .onlyListFonts = false,
  220. .dumpStructure = false,
  221. .noShaderCache = false,
  222. .disabledObjects = {},
  223. .enabledObjects = {},
  224. .disabledEffects = {},
  225. .enabledEffects = {},
  226. .audioSensitivity = {},
  227. .soundVolume = {},
  228. .assets = "",
  229. .defaultBackground = "",
  230. .screenBackgrounds = {},
  231. .properties = {},
  232. .screenScalings = {},
  233. .screenClamps = {},
  234. .screenZooms = {},
  235. .screenRenderScales = {},
  236. .screenOffsets = {},
  237. .screenAlignments = {},
  238. .screenCornerColors = {},
  239. .screenImageAdjustments = {},
  240. .screenVideoSegments = {},
  241. .screenPlaylists = {},
  242. .defaultPlaylist = std::nullopt,
  243. .spanGroups = {},
  244. .splitScreens = {},
  245. .webHost = false,
  246. .webHostShm = "",
  247. .webHostFrames = "shm",
  248. .webHostSocket = -1,
  249. .webHostWidth = 0,
  250. .webHostHeight = 0,
  251. .controlFile = std::nullopt,
  252. },
  253. .render = {
  254. .mode = NORMAL_WINDOW,
  255. .maximumFPS = 60,
  256. .playbackSpeed = 1.0f,
  257. .videoSegments = {},
  258. .hwdec = "auto",
  259. .webFrames = "auto",
  260. .frameLimiter = "budget",
  261. .transition = "none",
  262. .transitionMs = 600,
  263. .freezeAnimations = false,
  264. .pauseOnFullscreen = true,
  265. .pauseOnFullscreenOnlyWhenActive = false,
  266. .pauseOnFocus = false,
  267. .pauseOnMaximized = false,
  268. .fullscreenPauseIgnoreAppIds = {},
  269. .batteryFPS = std::nullopt,
  270. .idlePauseMinutes = 0,
  271. .pauseOnLock = true,
  272. .hdr = false,
  273. .debug = {
  274. .baseOnly = false,
  275. .noSolidFinal = false,
  276. .passLog = false,
  277. .brightnessLog = false,
  278. .noPuppetAnimation = false,
  279. .objectFilter = std::nullopt,
  280. .skipObjects = {},
  281. .skipEffects = {},
  282. },
  283. .window = {
  284. .geometry = {},
  285. .clamp = TextureFlags_ClampUVsBorder,
  286. .scalingMode = WallpaperEngine::Render::WallpaperState::TextureUVsScaling::DefaultUVs,
  287. .zoom = 1.0f,
  288. .offset = { 0.0f, 0.0f },
  289. .alignment = {},
  290. .cornerColor = { 0.0f, 0.0f, 0.0f, 1.0f },
  291. .imageAdjustments = {},
  292. .asBackground = false,
  293. .regular = false,
  294. },
  295. .wayland = {
  296. .layer = WAYLAND_LAYER_BOTTOM,
  297. .layerAuto = true,
  298. },
  299. },
  300. .audio = {
  301. .enabled = true,
  302. .volume = 15,
  303. .automute = false,
  304. .audioprocessing = true,
  305. .audioScreen = std::nullopt,
  306. .ambientVolume = std::nullopt,
  307. .hrtf = HRTF_AUTO,
  308. },
  309. .leds = {
  310. .enabled = false,
  311. .host = "127.0.0.1",
  312. .port = 6742,
  313. .boost = true,
  314. .brightness = 1.0f,
  315. .reduceFps = false,
  316. },
  317. .mouse = {
  318. .enabled = true,
  319. .disableparallax = false,
  320. .clampParallaxToImageSize = true,
  321. },
  322. .screenshot = {
  323. .take = false,
  324. .delay = 5,
  325. .path = "",
  326. },
  327. };
  328. ApplicationState state;
  329. [[nodiscard]] int getArgc () const;
  330. [[nodiscard]] char** getArgv () const;
  331. private:
  332. int m_argc;
  333. char** m_argv;
  334. void validateAssets ();
  335. void validateScreenshot () const;
  336. static std::filesystem::path translateBackground (const std::string& bgIdOrPath);
  337. void loadPlaylistsFromConfig ();
  338. std::filesystem::path resolvePlaylistItemPath (const std::string& raw) const;
  339. std::filesystem::path configFilePath () const;
  340. std::optional<WallpaperEngine::Data::JSON::JSON> parseConfigJson (const std::filesystem::path& path) const;
  341. PlaylistSettings parsePlaylistSettings (const WallpaperEngine::Data::JSON::JSON& playlistJson) const;
  342. std::vector<std::filesystem::path>
  343. collectPlaylistItems (const WallpaperEngine::Data::JSON::JSON& playlistJson, const std::string& name) const;
  344. std::optional<PlaylistDefinition> buildPlaylistDefinition (
  345. const WallpaperEngine::Data::JSON::JSON& playlistJson, const std::string& fallbackName
  346. ) const;
  347. void registerPlaylist (PlaylistDefinition&& definition);
  348. [[nodiscard]] const PlaylistDefinition& getPlaylistFromConfig (const std::string& name);
  349. std::map<std::string, PlaylistDefinition> m_configPlaylists;
  350. bool m_loadedConfigPlaylists = false;
  351. };
  352. }