| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455 |
- #include "ApplicationContext.h"
- #include "Steam/FileSystem/FileSystem.h"
- #include "WallpaperEngine/Data/JSON.h"
- #include "WallpaperEngine/Logging/Log.h"
- #include "WallpaperEngine/Render/CFBO.h"
- #include "WallpaperEngine/Render/Wallpapers/CVideo.h"
- #include <algorithm>
- #include <charconv>
- #include <cstdlib>
- #include <cstring>
- #include <fstream>
- #include <functional>
- #include <iostream>
- #include <optional>
- #include <sstream>
- #include <stdexcept>
- #include <string_view>
- #include <argparse/argparse.hpp>
- #define WORKSHOP_APP_ID 431960
- #define APP_DIRECTORY "wallpaper_engine"
- using namespace WallpaperEngine::Application;
- using WallpaperEngine::Data::Model::ImageAdjustments;
- namespace {
- // CEF and --web-host children re-run the whole argument parsing, the parent already reported all of it
- bool isHelperProcess (int argc, char** argv, bool webHost) {
- if (webHost) {
- return true;
- }
- for (int i = 1; i < argc; i++) {
- if (std::string_view (argv[i]).starts_with ("--type=")) {
- return true;
- }
- }
- return false;
- }
- } // namespace
- using WallpaperEngine::Data::JSON::JSON;
- std::filesystem::path ApplicationContext::resolvePlaylistItemPath (const std::string& raw) const {
- if (raw.empty ()) {
- return {};
- }
- std::string cleaned = raw;
- constexpr std::string_view windowsPrefix = "\\\\?\\";
- if (cleaned.rfind (windowsPrefix, 0) == 0) {
- cleaned = cleaned.substr (windowsPrefix.length ());
- }
- std::replace (cleaned.begin (), cleaned.end (), '\\', '/');
- if (cleaned.size () > 1 && cleaned[1] == ':') {
- cleaned = cleaned.substr (2);
- }
- if (!cleaned.empty () && cleaned.front () != '/') {
- cleaned.insert (cleaned.begin (), '/');
- }
- std::filesystem::path path = std::filesystem::path (cleaned).lexically_normal ();
- if (std::filesystem::is_regular_file (path)) {
- path = path.parent_path ();
- }
- return path;
- }
- std::filesystem::path ApplicationContext::configFilePath () const {
- try {
- return Steam::FileSystem::appDirectory (APP_DIRECTORY, "") / "config.json";
- } catch (std::runtime_error&) {
- sLog.exception ("Cannot locate wallpaper engine installation to read config.json");
- return {};
- }
- }
- std::optional<JSON> ApplicationContext::parseConfigJson (const std::filesystem::path& path) const {
- if (path.empty ()) {
- return std::nullopt;
- }
- std::ifstream configFile (path);
- if (!configFile.is_open ()) {
- sLog.exception ("Cannot open wallpaper engine config file at ", path);
- return std::nullopt;
- }
- try {
- return JSON::parse (configFile);
- } catch (const std::exception& e) {
- sLog.error ("Failed parsing wallpaper engine config.json: ", e.what ());
- return std::nullopt;
- }
- }
- std::optional<ApplicationContext::PlaylistDefinition>
- ApplicationContext::buildPlaylistDefinition (const JSON& playlistJson, const std::string& fallbackName) const {
- PlaylistDefinition definition;
- definition.name = playlistJson.optional<std::string> ("name", fallbackName);
- definition.settings = this->parsePlaylistSettings (playlistJson);
- definition.items
- = this->collectPlaylistItems (playlistJson, definition.name.empty () ? fallbackName : definition.name);
- if (definition.items.empty ()) {
- return std::nullopt;
- }
- if (definition.name.empty ()) {
- if (fallbackName.empty ()) {
- sLog.error ("Skipping playlist with no name");
- return std::nullopt;
- }
- definition.name = fallbackName;
- }
- return definition;
- }
- ApplicationContext::PlaylistSettings ApplicationContext::parsePlaylistSettings (const JSON& playlistJson) const {
- PlaylistSettings settings;
- const auto settingsJson = playlistJson.optional ("settings");
- settings.delayMinutes = settingsJson ? settingsJson->optional<uint32_t> ("delay", 60) : 60;
- settings.mode = settingsJson ? settingsJson->optional<std::string> ("mode", "timer") : "timer";
- settings.order = settingsJson ? settingsJson->optional<std::string> ("order", "sequential") : "sequential";
- settings.updateOnPause = settingsJson ? settingsJson->optional<bool> ("updateonpause", false) : false;
- settings.videoSequence = settingsJson ? settingsJson->optional<bool> ("videosequence", false) : false;
- return settings;
- }
- std::vector<std::filesystem::path>
- ApplicationContext::collectPlaylistItems (const JSON& playlistJson, const std::string& name) const {
- std::vector<std::filesystem::path> items;
- const auto jsonItems = playlistJson.optional ("items");
- if (!jsonItems.has_value () || !jsonItems->is_array ()) {
- sLog.error ("Skipping playlist ", name, ": missing items");
- return items;
- }
- for (const auto& rawItem : *jsonItems) {
- if (!rawItem.is_string ()) {
- continue;
- }
- auto resolvedPath = this->resolvePlaylistItemPath (rawItem.get<std::string> ());
- if (resolvedPath.empty ()) {
- continue;
- }
- if (!std::filesystem::exists (resolvedPath)) {
- sLog.error ("Skipping playlist item not found: ", resolvedPath.string ());
- continue;
- }
- items.push_back (resolvedPath);
- }
- if (items.empty ()) {
- sLog.error ("Skipping playlist ", name, ": no usable items found");
- }
- return items;
- }
- void ApplicationContext::registerPlaylist (PlaylistDefinition&& definition) {
- this->m_configPlaylists.insert_or_assign (definition.name, std::move (definition));
- }
- void ApplicationContext::loadPlaylistsFromConfig () {
- if (this->m_loadedConfigPlaylists) {
- return;
- }
- this->m_loadedConfigPlaylists = true;
- const auto configPath = this->configFilePath ();
- const auto root = this->parseConfigJson (configPath);
- if (!root.has_value ()) {
- return;
- }
- const auto steamUser = root->optional ("steamuser");
- if (!steamUser.has_value ()) {
- sLog.exception ("Cannot find steamuser section in config.json");
- }
- auto addPlaylist = [this] (const JSON& playlistJson, const std::string& fallbackName) {
- auto definition = this->buildPlaylistDefinition (playlistJson, fallbackName);
- if (!definition) {
- return;
- }
- this->registerPlaylist (std::move (*definition));
- };
- if (const auto general = steamUser->optional ("general")) {
- if (const auto playlists = general->optional ("playlists")) {
- for (const auto& playlist : *playlists) {
- try {
- addPlaylist (playlist, playlist.optional<std::string> ("name", ""));
- } catch (const std::exception& e) {
- sLog.error ("Failed parsing playlist: ", e.what ());
- }
- }
- }
- }
- if (const auto wallpaperConfig = steamUser->optional ("wallpaperconfig")) {
- if (const auto selected = wallpaperConfig->optional ("selectedwallpapers")) {
- for (const auto& entry : selected->items ()) {
- const auto playlist = entry.value ().optional ("playlist");
- if (!playlist.has_value ()) {
- continue;
- }
- try {
- addPlaylist (*playlist, entry.key ());
- } catch (const std::exception& e) {
- sLog.error ("Failed parsing playlist for ", entry.key (), ": ", e.what ());
- }
- }
- }
- }
- }
- const ApplicationContext::PlaylistDefinition& ApplicationContext::getPlaylistFromConfig (const std::string& name) {
- if (!this->m_loadedConfigPlaylists) {
- this->loadPlaylistsFromConfig ();
- }
- const auto cur = this->m_configPlaylists.find (name);
- if (cur == this->m_configPlaylists.end ()) {
- std::string available;
- for (auto it = this->m_configPlaylists.begin (); it != this->m_configPlaylists.end (); ++it) {
- available += it->first;
- if (std::next (it) != this->m_configPlaylists.end ()) {
- available += ", ";
- }
- }
- const std::string availableText = available.empty () ? "" : std::string (". Available: ") + available;
- sLog.exception ("Playlist not found in config.json: ", name, availableText);
- throw std::runtime_error ("Playlist not found: " + name);
- }
- return cur->second;
- }
- ApplicationContext::ApplicationContext (int argc, char* argv[]) : m_argc (argc), m_argv (argv) { }
- namespace {
- bool matchesObjectToken (const std::string& token, int id, const std::string& name) {
- if (token == name) {
- return true;
- }
- int parsed = 0;
- const auto* end = token.data () + token.size ();
- const auto result = std::from_chars (token.data (), end, parsed);
- return result.ec == std::errc () && result.ptr == end && parsed == id;
- }
- } // namespace
- std::optional<bool> ApplicationContext::resolveObjectVisibility (int id, const std::string& name) const {
- for (const auto& token : this->settings.general.disabledObjects) {
- if (matchesObjectToken (token, id, name)) {
- return false;
- }
- }
- for (const auto& token : this->settings.general.enabledObjects) {
- if (matchesObjectToken (token, id, name)) {
- return true;
- }
- }
- return std::nullopt;
- }
- std::optional<bool> ApplicationContext::resolveEffectVisibility (int id, const std::string& name) const {
- for (const auto& token : this->settings.general.disabledEffects) {
- if (matchesObjectToken (token, id, name)) {
- return false;
- }
- }
- for (const auto& token : this->settings.general.enabledEffects) {
- if (matchesObjectToken (token, id, name)) {
- return true;
- }
- }
- return std::nullopt;
- }
- std::optional<float> ApplicationContext::resolveAudioSensitivity (int id, const std::string& name) const {
- // "*" is a wildcard default, checked last so a specific id/name match always wins
- // regardless of the map's (alphabetically ordered) iteration order.
- std::optional<float> wildcard;
- for (const auto& [token, multiplier] : this->settings.general.audioSensitivity) {
- if (token == "*") {
- wildcard = multiplier;
- continue;
- }
- if (matchesObjectToken (token, id, name)) {
- return multiplier;
- }
- }
- return wildcard;
- }
- std::optional<float> ApplicationContext::resolveSoundVolume (int id, const std::string& name) const {
- // "*" is a wildcard default, checked last so a specific id/name match always wins (same rule as
- // resolveAudioSensitivity).
- std::optional<float> wildcard;
- for (const auto& [token, volume] : this->settings.general.soundVolume) {
- if (token == "*") {
- wildcard = volume;
- continue;
- }
- if (matchesObjectToken (token, id, name)) {
- return volume;
- }
- }
- return wildcard;
- }
- void ApplicationContext::loadSettingsFromArgv () {
- std::string lastScreen;
- argparse::ArgumentParser program ("linux-wallpaperengine", "0.0", argparse::default_arguments::help);
- auto& backgroundGroup = program.add_group ("Background options");
- auto& backgroundMode = backgroundGroup.add_mutually_exclusive_group (false);
- backgroundGroup.add_argument ("background id")
- .help ("The background to use as default for screens with no background specified")
- .default_value ("")
- .action ([this] (const std::string& value) -> void {
- if (!value.empty ()) {
- this->settings.general.defaultBackground = translateBackground (value);
- }
- });
- // Internal, hidden: appended to CEF subprocess re-execs so they see the current (possibly
- // hotswapped) background instead of the launch-time "background id" positional. Registered
- // last so it takes precedence.
- backgroundGroup.add_argument ("--current-background")
- .default_value ("")
- .hidden ()
- .action ([this] (const std::string& value) -> void {
- if (!value.empty ()) {
- this->settings.general.defaultBackground = translateBackground (value);
- }
- });
- // Internal, hidden: marks a self-re-exec as a disposable CEF host for one Web wallpaper.
- backgroundGroup.add_argument ("--web-host").flag ().hidden ().store_into (this->settings.general.webHost);
- backgroundGroup.add_argument ("--web-host-shm")
- .default_value ("")
- .hidden ()
- .store_into (this->settings.general.webHostShm);
- backgroundGroup.add_argument ("--web-host-width")
- .default_value (0)
- .hidden ()
- .action ([this] (const std::string& value) -> void {
- try {
- this->settings.general.webHostWidth = static_cast<uint32_t> (std::stoul (value));
- } catch (const std::exception&) {
- sLog.exception ("Invalid --web-host-width value: ", value);
- }
- });
- backgroundGroup.add_argument ("--web-host-height")
- .default_value (0)
- .hidden ()
- .action ([this] (const std::string& value) -> void {
- try {
- this->settings.general.webHostHeight = static_cast<uint32_t> (std::stoul (value));
- } catch (const std::exception&) {
- sLog.exception ("Invalid --web-host-height value: ", value);
- }
- });
- backgroundMode.add_argument ("-w", "--window")
- .help ("Window geometry to use for the given screen")
- .action ([this] (const std::string& value) -> void {
- if (this->settings.render.mode == DESKTOP_BACKGROUND) {
- sLog.exception ("Cannot run in both background and window mode");
- }
- if (this->settings.render.mode == EXPLICIT_WINDOW) {
- sLog.exception ("Only one window at a time can be specified in explicit window mode");
- }
- this->settings.render.mode = EXPLICIT_WINDOW;
- if (value.empty ()) {
- sLog.exception ("Window geometry cannot be empty");
- }
- const char* str = value.c_str ();
- const char* delim1 = strchr (str, 'x');
- const char* delim2 = delim1 ? strchr (delim1 + 1, 'x') : nullptr;
- const char* delim3 = delim2 ? strchr (delim2 + 1, 'x') : nullptr;
- if (delim1 == nullptr || delim2 == nullptr || delim3 == nullptr) {
- sLog.exception ("Window geometry must be in the format: XxYxWxH");
- }
- this->settings.render.window.geometry.x = strtol (str, nullptr, 10);
- this->settings.render.window.geometry.y = strtol (delim1 + 1, nullptr, 10);
- this->settings.render.window.geometry.z = strtol (delim2 + 1, nullptr, 10);
- this->settings.render.window.geometry.w = strtol (delim3 + 1, nullptr, 10);
- })
- .append ();
- backgroundMode.add_argument ("-r", "--screen-root")
- .help ("The screen the following settings will have an effect on")
- .action ([this, &lastScreen] (const std::string& value) -> void {
- if (this->settings.general.screenBackgrounds.find (value)
- != this->settings.general.screenBackgrounds.end ()) {
- sLog.exception ("Cannot specify the same screen more than once: ", value);
- }
- for (const auto& group : this->settings.general.spanGroups) {
- if (std::find (group.screens.begin (), group.screens.end (), value) != group.screens.end ()) {
- sLog.exception ("--screen-root: screen '", value, "' already belongs to a span group");
- }
- }
- if (this->settings.render.mode == EXPLICIT_WINDOW) {
- sLog.exception ("Cannot run in both background and window mode");
- }
- this->settings.render.mode = DESKTOP_BACKGROUND;
- lastScreen = value;
- this->settings.general.screenBackgrounds[lastScreen] = "";
- this->settings.general.screenScalings[lastScreen] = this->settings.render.window.scalingMode;
- this->settings.general.screenClamps[lastScreen] = this->settings.render.window.clamp;
- })
- .append ();
- backgroundGroup.add_argument ("--screen-span")
- .help ("Comma-separated list of screens to span a single wallpaper across")
- .action ([this, &lastScreen] (const std::string& value) -> void {
- if (this->settings.render.mode == EXPLICIT_WINDOW) {
- sLog.exception ("Cannot run in both background and window mode");
- }
- this->settings.render.mode = DESKTOP_BACKGROUND;
- SpanGroup group;
- std::string screen;
- std::istringstream ss (value);
- while (std::getline (ss, screen, ',')) {
- if (screen.empty ()) {
- continue;
- }
- if (this->settings.general.screenBackgrounds.find (screen)
- != this->settings.general.screenBackgrounds.end ()) {
- sLog.exception ("--screen-span: screen '", screen, "' is already configured individually");
- }
- if (std::find (group.screens.begin (), group.screens.end (), screen) != group.screens.end ()) {
- sLog.exception ("--screen-span: duplicate screen name '", screen, "'");
- }
- for (const auto& existing : this->settings.general.spanGroups) {
- if (std::find (existing.screens.begin (), existing.screens.end (), screen)
- != existing.screens.end ()) {
- sLog.exception ("--screen-span: screen '", screen, "' already belongs to another span group");
- }
- }
- group.screens.push_back (screen);
- }
- if (group.screens.size () < 2) {
- sLog.exception ("--screen-span requires at least two comma-separated screen names");
- }
- group.scaling = this->settings.render.window.scalingMode;
- group.clamp = this->settings.render.window.clamp;
- group.alignment = this->settings.render.window.alignment;
- this->settings.general.spanGroups.push_back (std::move (group));
- // synthetic "span:" name lets --bg/--scaling/--clamp target this group
- lastScreen = "span:" + value;
- this->settings.general.screenBackgrounds[lastScreen] = "";
- })
- .append ();
- backgroundGroup.add_argument ("-b", "--bg")
- .help ("After --screen-root or --screen-span, specifies the background to use")
- .action ([this, &lastScreen] (const std::string& value) -> void {
- this->settings.general.screenBackgrounds[lastScreen] = translateBackground (value);
- this->settings.general.defaultBackground = translateBackground (value);
- if (lastScreen.rfind ("span:", 0) == 0 && !this->settings.general.spanGroups.empty ()) {
- this->settings.general.spanGroups.back ().background = translateBackground (value);
- }
- })
- .append ();
- backgroundGroup.add_argument ("--playlist")
- .help (
- "Uses a playlist from wallpaper engine's config.json. If used after --screen-root it is applied to that "
- "screen, otherwise it is used in window mode."
- )
- .action ([this, &lastScreen] (const std::string& value) -> void {
- const auto& playlist = this->getPlaylistFromConfig (value);
- if (lastScreen.empty ()) {
- this->settings.general.defaultPlaylist = playlist;
- if (this->settings.general.defaultBackground.empty () && !playlist.items.empty ()) {
- this->settings.general.defaultBackground = playlist.items.front ();
- }
- } else {
- this->settings.general.screenPlaylists[lastScreen] = playlist;
- if (!playlist.items.empty ()) {
- this->settings.general.screenBackgrounds[lastScreen] = playlist.items.front ();
- }
- if (this->settings.general.defaultBackground.empty () && !playlist.items.empty ()) {
- this->settings.general.defaultBackground = playlist.items.front ();
- }
- }
- })
- .append ();
- backgroundGroup.add_argument ("--scaling")
- .help (
- "Scaling mode to use when rendering the background, this applies to the previous --window, --screen-root, "
- "or --screen-span output, or the default background if no other background is specified"
- )
- .choices ("stretch", "fit", "fill", "center", "free", "default")
- .action ([this, &lastScreen] (const std::string& value) -> void {
- const auto parsed = WallpaperEngine::Render::WallpaperState::parseScalingMode (value);
- if (!parsed.has_value ()) {
- sLog.exception ("Invalid scaling mode: ", value);
- }
- const auto mode = *parsed;
- if (this->settings.render.mode == DESKTOP_BACKGROUND) {
- this->settings.general.screenScalings[lastScreen] = mode;
- if (lastScreen.rfind ("span:", 0) == 0 && !this->settings.general.spanGroups.empty ()) {
- this->settings.general.spanGroups.back ().scaling = mode;
- }
- } else {
- this->settings.render.window.scalingMode = mode;
- }
- })
- .append ();
- backgroundGroup.add_argument ("--clamp")
- .help (
- "Clamp mode to use when rendering the background, this applies to the previous --window, --screen-root, "
- "or --screen-span output, or the default background if no other background is specified"
- )
- .choices ("clamp", "border", "repeat")
- .action ([this, &lastScreen] (const std::string& value) -> void {
- TextureFlags flags;
- if (value == "clamp") {
- flags = TextureFlags_ClampUVs;
- } else if (value == "border") {
- flags = TextureFlags_ClampUVsBorder;
- } else if (value == "repeat") {
- flags = TextureFlags_NoFlags;
- } else {
- sLog.exception ("Invalid clamp mode: ", value);
- }
- if (this->settings.render.mode == DESKTOP_BACKGROUND) {
- this->settings.general.screenClamps[lastScreen] = flags;
- if (lastScreen.rfind ("span:", 0) == 0 && !this->settings.general.spanGroups.empty ()) {
- this->settings.general.spanGroups.back ().clamp = flags;
- }
- } else {
- this->settings.render.window.clamp = flags;
- }
- })
- .append ();
- backgroundGroup.add_argument ("--zoom")
- .help (
- "Manual zoom factor layered on top of --scaling (e.g. 1.5 zooms in 50%, 0.5 zooms out to half size), "
- "this applies to the previous --window, --screen-root, or --screen-span output, or the default "
- "background if no other background is specified"
- )
- .action ([this, &lastScreen] (const std::string& value) -> void {
- float zoom;
- try {
- zoom = std::stof (value);
- } catch (const std::exception&) {
- sLog.exception ("Invalid zoom value: ", value);
- }
- if (this->settings.render.mode == DESKTOP_BACKGROUND) {
- this->settings.general.screenZooms[lastScreen] = zoom;
- if (lastScreen.rfind ("span:", 0) == 0 && !this->settings.general.spanGroups.empty ()) {
- this->settings.general.spanGroups.back ().zoom = zoom;
- }
- } else {
- this->settings.render.window.zoom = zoom;
- }
- })
- .append ();
- backgroundGroup.add_argument ("--offset")
- .help (
- "Re-centers the visible crop window a cropping scaling mode (e.g. --scaling fill) or --zoom produces, "
- "as \"X,Y\" with each axis in [-1, 1] (0,0 is centered/default, e.g. -1,0 shows as much of the left "
- "edge as the crop allows, 0,1 shows as much of the top edge as the crop allows). Has no visible "
- "effect where nothing is being cropped. This applies to the previous --window, --screen-root, or "
- "--screen-span output, or the default background if no other background is specified"
- )
- // "-1,0" would otherwise look like another option to argparse
- .allow_optional_like_value ()
- .action ([this, &lastScreen] (const std::string& value) -> void {
- const auto comma = value.find (',');
- if (comma == std::string::npos) {
- sLog.exception ("Offset must be in the format: X,Y");
- }
- glm::vec2 offset;
- try {
- offset.x = std::stof (value.substr (0, comma));
- offset.y = std::stof (value.substr (comma + 1));
- } catch (const std::exception&) {
- sLog.exception ("Invalid offset value: ", value);
- }
- if (this->settings.render.mode == DESKTOP_BACKGROUND) {
- this->settings.general.screenOffsets[lastScreen] = offset;
- if (lastScreen.rfind ("span:", 0) == 0 && !this->settings.general.spanGroups.empty ()) {
- this->settings.general.spanGroups.back ().offset = offset;
- }
- } else {
- this->settings.render.window.offset = offset;
- }
- })
- .append ();
- // WE's alignment settings in its own units (sub_140181F30 divides them by 100)
- const auto addAlignmentArgument = [this, &backgroundGroup, &lastScreen] (
- const char* name, const char* help, const float maximum,
- float WallpaperEngine::Render::WallpaperState::Alignment::* field
- ) {
- backgroundGroup.add_argument (name)
- .help (help)
- .action ([this, &lastScreen, name, maximum, field] (const std::string& value) -> void {
- float parsed;
- try {
- parsed = std::stof (value);
- } catch (const std::exception&) {
- sLog.exception ("Invalid ", name, " value: ", value);
- }
- if (parsed < 0.0f || parsed > maximum) {
- sLog.exception (name, " must be between 0 and ", maximum, ": ", value);
- }
- parsed /= 100.0f;
- if (this->settings.render.mode == DESKTOP_BACKGROUND) {
- auto& alignment = this->settings.general.screenAlignments
- .try_emplace (lastScreen, this->settings.render.window.alignment)
- .first->second;
- alignment.*field = parsed;
- if (lastScreen.rfind ("span:", 0) == 0 && !this->settings.general.spanGroups.empty ()) {
- this->settings.general.spanGroups.back ().alignment.*field = parsed;
- }
- } else {
- this->settings.render.window.alignment.*field = parsed;
- }
- })
- .append ();
- };
- addAlignmentArgument (
- "--alignment-position",
- "Wallpaper Engine's alignment position, 0-100 (default 50): where --scaling fill/default crops (0 keeps the "
- "right or top edge) and --scaling fit places the letterboxed wallpaper (0 = left or top). This applies to the "
- "previous --window, --screen-root, or --screen-span output, or the default background",
- 100.0f, &WallpaperEngine::Render::WallpaperState::Alignment::position
- );
- addAlignmentArgument (
- "--alignment-x",
- "Wallpaper Engine's horizontal alignment for --scaling center and free, 0-100 (default 50, 0 = left). This "
- "applies to the previous --window, --screen-root, or --screen-span output, or the default background",
- 100.0f, &WallpaperEngine::Render::WallpaperState::Alignment::x
- );
- addAlignmentArgument (
- "--alignment-y",
- "Wallpaper Engine's vertical alignment for --scaling center and free, 0-100 (default 50, 0 = top). This "
- "applies to the previous --window, --screen-root, or --screen-span output, or the default background",
- 100.0f, &WallpaperEngine::Render::WallpaperState::Alignment::y
- );
- addAlignmentArgument (
- "--alignment-zoom",
- "Wallpaper Engine's zoom for --scaling free, 0-200 (default 100 = native size, higher zooms in). This applies "
- "to the previous --window, --screen-root, or --screen-span output, or the default background",
- 200.0f, &WallpaperEngine::Render::WallpaperState::Alignment::zoom
- );
- backgroundGroup.add_argument ("--corner-color")
- .help (
- "Color to show outside the wallpaper's bounds (Center/Fit letterboxing, zoomed-out scaling) when "
- "--clamp is border, as a hex RGB or RGBA value (e.g. \"000000\" or \"#1a1a1aff\"). Default: opaque "
- "black. This applies to the previous --window, --screen-root, or --screen-span output, or the "
- "default background if no other background is specified"
- )
- .action ([this, &lastScreen] (const std::string& value) -> void {
- const auto color = WallpaperEngine::Render::CFBO::parseColor (value);
- if (!color.has_value ()) {
- sLog.exception ("Invalid corner color: ", value);
- }
- if (this->settings.render.mode == DESKTOP_BACKGROUND) {
- this->settings.general.screenCornerColors[lastScreen] = *color;
- if (lastScreen.rfind ("span:", 0) == 0 && !this->settings.general.spanGroups.empty ()) {
- this->settings.general.spanGroups.back ().cornerColor = *color;
- }
- } else {
- this->settings.render.window.cornerColor = *color;
- }
- })
- .append ();
- // Wallpaper Engine's own image settings (its properties panel), every one of them applies to the previous
- // --window, --screen-root or --screen-span output like --zoom does
- const auto updateImageAdjustments = [this, &lastScreen] (const std::function<void (ImageAdjustments&)>& update) {
- if (this->settings.render.mode == DESKTOP_BACKGROUND) {
- update (this->settings.general.screenImageAdjustments[lastScreen]);
- if (lastScreen.rfind ("span:", 0) == 0 && !this->settings.general.spanGroups.empty ()) {
- update (this->settings.general.spanGroups.back ().imageAdjustments);
- }
- } else {
- update (this->settings.render.window.imageAdjustments);
- }
- };
- const auto parseSlider = [] (const std::string& name, const std::string& value) -> float {
- float result;
- try {
- result = std::stof (value);
- } catch (const std::exception&) {
- sLog.exception ("Invalid ", name, " value: ", value);
- }
- if (result < 0.0f || result > 100.0f) {
- sLog.exception (name, " must be between 0 and 100: ", value);
- }
- return result;
- };
- backgroundGroup.add_argument ("--image-filter")
- .help (
- "Applies one of Wallpaper Engine's image filters (a color lookup table from the assets' materials/lut "
- "folder, e.g. \"lutx32_amber\" or \"k23_b\"), \"none\" removes it. Scene and video wallpapers only. "
- "This applies to the previous --window, --screen-root, or --screen-span output, or the default "
- "background if no other background is specified"
- )
- .action ([updateImageAdjustments] (const std::string& value) -> void {
- updateImageAdjustments ([&value] (ImageAdjustments& adjustments) {
- adjustments.filter = value == "none" ? "" : value;
- });
- })
- .append ();
- backgroundGroup.add_argument ("--image-filter-strength")
- .help ("How strongly --image-filter applies, 0-100. Default: 100")
- .action ([updateImageAdjustments, parseSlider] (const std::string& value) -> void {
- const float strength = parseSlider ("image filter strength", value);
- updateImageAdjustments ([strength] (ImageAdjustments& adjustments) {
- adjustments.filterStrength = strength;
- });
- })
- .append ();
- for (const auto& [option, name] : std::initializer_list<std::pair<const char*, const char*>> {
- { "--brightness", "brightness" },
- { "--contrast", "contrast" },
- { "--saturation", "saturation" },
- { "--hue", "hue" },
- }) {
- backgroundGroup.add_argument (option)
- .help (
- std::string ("Wallpaper Engine's ") + name
- + " color option, 0-100 with 50 leaving the image unchanged. Scene and video wallpapers only"
- )
- .action ([updateImageAdjustments, parseSlider, name] (const std::string& value) -> void {
- const float amount = parseSlider (name, value);
- const std::string_view which = name;
- updateImageAdjustments ([amount, which] (ImageAdjustments& adjustments) {
- adjustments.colorEnabled = true;
- if (which == "brightness") {
- adjustments.brightness = amount;
- } else if (which == "contrast") {
- adjustments.contrast = amount;
- } else if (which == "saturation") {
- adjustments.saturation = amount;
- } else {
- adjustments.hue = amount;
- }
- });
- })
- .append ();
- }
- backgroundGroup.add_argument ("--color-options")
- .help (
- "Turns Wallpaper Engine's color options (--brightness and friends, or the ones a preset carries) on or "
- "off. Giving any of them turns them on"
- )
- .choices ("on", "off")
- .action ([updateImageAdjustments] (const std::string& value) -> void {
- updateImageAdjustments ([&value] (ImageAdjustments& adjustments) {
- adjustments.colorEnabled = value == "on";
- });
- })
- .append ();
- backgroundGroup.add_argument ("--flip")
- .help (
- "Mirrors the wallpaper horizontally (Wallpaper Engine's \"Flip\" option), \"on\" or \"off\". Scene and "
- "video wallpapers only"
- )
- .choices ("on", "off")
- .action ([updateImageAdjustments] (const std::string& value) -> void {
- updateImageAdjustments ([&value] (ImageAdjustments& adjustments) {
- adjustments.flipHorizontal = value == "on";
- });
- })
- .append ();
- backgroundGroup.add_argument ("--hdr")
- .help (
- "Wayland-only: sends HDR (PQ, BT.2020) to monitors running in HDR mode and plays HDR videos in HDR, "
- "like Wallpaper Engine's \"HDR display\" setting. Needs a compositor with the color management "
- "protocol (wp_color_manager_v1, recent KDE Plasma); other monitors keep getting the usual SDR image"
- )
- .flag ()
- .store_into (this->settings.render.hdr);
- backgroundGroup.add_argument ("--layer")
- .help (
- "Wayland-only: which wlr-layer-shell layer to anchor the wallpaper to "
- "(background, bottom, top, overlay). Default: background on KDE, bottom elsewhere. "
- "KDE defaults to 'background' because KWin's 'show desktop' (Super+D) hides 'bottom' surfaces. "
- "Use 'background' on niri to pair with the `place-within-backdrop` layer-rule, "
- "otherwise the wallpaper will be cloned to every workspace in the overview."
- )
- .choices ("background", "bottom", "top", "overlay")
- .default_value (std::string ("bottom"))
- .action ([this] (const std::string& value) -> void {
- if (value == "background") {
- this->settings.render.wayland.layer = WAYLAND_LAYER_BACKGROUND;
- } else if (value == "bottom") {
- this->settings.render.wayland.layer = WAYLAND_LAYER_BOTTOM;
- } else if (value == "top") {
- this->settings.render.wayland.layer = WAYLAND_LAYER_TOP;
- } else if (value == "overlay") {
- this->settings.render.wayland.layer = WAYLAND_LAYER_OVERLAY;
- } else {
- sLog.exception ("Invalid wlr-layer-shell layer: ", value);
- }
- });
- auto& performanceGroup = program.add_group ("Performance options");
- performanceGroup.add_argument ("-f", "--fps")
- .help ("Limits the FPS to the given number, useful to keep battery consumption low")
- .default_value (60)
- .store_into (this->settings.render.maximumFPS);
- performanceGroup.add_argument ("--speed")
- .help (
- "Global playback speed multiplier for animations, particles and effects (e.g. 0.5 for half speed, "
- "2.0 for double speed). Useful to calm down backgrounds with overly fast particle effects"
- )
- .action ([this] (const std::string& value) -> void {
- float speed;
- try {
- speed = std::stof (value);
- } catch (const std::exception&) {
- sLog.exception ("Invalid speed value: ", value);
- }
- if (speed <= 0.0f) {
- sLog.exception ("--speed must be a positive number");
- }
- this->settings.render.playbackSpeed = speed;
- });
- performanceGroup.add_argument ("--no-fullscreen-pause")
- .help ("Prevents the background pausing when an app is fullscreen")
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.render.pauseOnFullscreen = false; });
- performanceGroup.add_argument ("--fullscreen-pause-only-active")
- .help ("Wayland only: pause only when a fullscreen window is active (activated)")
- .flag ()
- .action ([this] (const std::string& value) -> void {
- this->settings.render.pauseOnFullscreenOnlyWhenActive = true;
- });
- performanceGroup.add_argument ("--fullscreen-pause-ignore-appid")
- .help ("Wayland only: ignore fullscreen windows whose app_id contains this value (repeatable)")
- .action ([this] (const std::string& value) -> void {
- if (!value.empty ()) {
- this->settings.render.fullscreenPauseIgnoreAppIds.push_back (value);
- }
- })
- .append ();
- auto& audioGroup = program.add_group ("Sound settings");
- auto& audioSettingsGroup = audioGroup.add_mutually_exclusive_group (false);
- audioSettingsGroup.add_argument ("-v", "--volume")
- .help ("Volume for all the sounds in the background")
- .default_value (15)
- .store_into (this->settings.audio.volume);
- audioSettingsGroup.add_argument ("-s", "--silent")
- .help ("Mutes all the sound the wallpaper might produce")
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.audio.enabled = false; });
- audioGroup.add_argument ("--automute")
- .help ("Mutes the wallpaper's audio when another app is playing sound")
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.audio.automute = true; });
- audioGroup.add_argument ("--noautomute")
- .help ("Disables the automute when an app is playing sound (default)")
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.audio.automute = false; });
- audioGroup.add_argument ("--no-audio-processing")
- .help ("Disables audio processing for backgrounds")
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.audio.audioprocessing = false; });
- audioGroup.add_argument ("--audio-screen")
- .help (
- "Only the background on this screen (matches --screen-root names) produces audio; every other screen "
- "is muted regardless of its own sound. Default: no restriction, every screen can produce sound."
- )
- .action ([this] (const std::string& value) -> void {
- if (!value.empty ()) {
- this->settings.audio.audioScreen = value;
- }
- });
- audioGroup.add_argument ("--ambient-volume")
- .help (
- "Separate volume (0-128) for non-video backgrounds (scene sound objects and web wallpapers), instead "
- "of --volume; video wallpapers always keep using --volume. Web wallpapers only support mute (0) vs "
- "unmuted (any other value), since CEF exposes no analog volume control. Default: same as --volume."
- )
- .action ([this] (const std::string& value) -> void {
- try {
- this->settings.audio.ambientVolume = std::stoi (value);
- } catch (const std::exception&) {
- sLog.exception ("Invalid --ambient-volume value: ", value);
- }
- });
- auto& screenshotGroup = program.add_group ("Screenshot options");
- screenshotGroup.add_argument ("--screenshot")
- .help ("Takes a screenshot of the background for it's use with tools like PyWAL")
- .default_value ("")
- .action ([this] (const std::string& value) -> void {
- this->settings.screenshot.take = true;
- this->settings.screenshot.path = value;
- });
- screenshotGroup.add_argument ("--screenshot-delay")
- .help ("Frames to wait before taking the screenshot")
- .default_value<uint32_t> (5)
- .store_into (this->settings.screenshot.delay);
- auto& contentGroup = program.add_group ("Content options");
- contentGroup.add_argument ("--assets-dir")
- .help ("Folder where the assets are stored")
- .default_value ("")
- .action ([this] (const std::string& value) -> void { this->settings.general.assets = value; });
- auto& configurationGroup = program.add_group ("Wallpaper configuration options");
- const auto parseVideoTime = [] (const char* name, const std::string& value) -> double {
- const auto seconds = WallpaperEngine::Render::Wallpapers::CVideo::parseTime (value);
- if (!seconds.has_value ()) {
- sLog.exception ("Invalid ", name, " value (seconds, m:ss or h:mm:ss): ", value);
- }
- return *seconds;
- };
- configurationGroup.add_argument ("--video-start")
- .help (
- "Video wallpapers only: where the part of the video that loops starts, in seconds, m:ss or h:mm:ss (e.g. "
- "\"3:00\"). Without --video-end it loops from here to the end of the video"
- )
- .action ([this, parseVideoTime] (const std::string& value) -> void {
- this->settings.render.videoStart = parseVideoTime ("--video-start", value);
- });
- configurationGroup.add_argument ("--video-end")
- .help (
- "Video wallpapers only: where the part of the video that loops ends, in seconds, m:ss or h:mm:ss (e.g. "
- "\"4:00\"). Without --video-start it loops from the beginning up to here"
- )
- .action ([this, parseVideoTime] (const std::string& value) -> void {
- this->settings.render.videoEnd = parseVideoTime ("--video-end", value);
- });
- configurationGroup.add_argument ("--control-file")
- .help (
- "File the SIGUSR1 hotswap request is read from. Give every engine its own when several run at once, "
- "otherwise they all read the same one. Default: $XDG_RUNTIME_DIR/lwe-control"
- )
- .action ([this] (const std::string& value) -> void {
- if (!value.empty ()) {
- this->settings.general.controlFile = value;
- }
- });
- configurationGroup.add_argument ("--disable-particles")
- .help ("Disables particles for the backgrounds")
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.general.disableParticles = true; });
- configurationGroup.add_argument ("--expand-canvas")
- .help (
- "Grows a scene's render canvas so image layers that extend past the camera's projection (a tall or wide "
- "picture the author only meant to be revealed by parallax) are shown in full instead of cropped. Layout "
- "stays centered on the original canvas, so it only ever adds room around it. Combine with "
- "--disable-parallax and --scaling fit to see the whole picture"
- )
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.general.expandCanvas = true; });
- configurationGroup.add_argument ("--post-processing")
- .help (
- "Wallpaper Engine's post processing quality: \"enabled\" (default), \"ultra\" or \"displayhdr\". With "
- "ultra, scenes that turn on both bloom and hdr render in HDR with Wallpaper Engine's HDR bloom; displayhdr "
- "also lets their highlights go up to an HDR output's peak brightness (with --hdr)"
- )
- .choices ("enabled", "ultra", "displayhdr")
- .action ([this] (const std::string& value) -> void {
- this->settings.general.ultraPostProcessing = value == "ultra" || value == "displayhdr";
- this->settings.general.displayHDR = value == "displayhdr";
- });
- // same names and numbers as Wallpaper Engine's quality settings (sub_14010DAD0)
- const auto qualityLevel = [] (const std::string& value) {
- return value == "disabled" ? 0 : value == "low" ? 1 : value == "high" ? 3 : value == "ultra" ? 4 : 2;
- };
- configurationGroup.add_argument ("--volumetrics")
- .help ("Wallpaper Engine's volumetric lighting quality: disabled, low, medium (default), high or ultra")
- .choices ("disabled", "low", "medium", "high", "ultra")
- .action ([this, qualityLevel] (const std::string& value) -> void {
- this->settings.general.volumetricsQuality = qualityLevel (value);
- });
- configurationGroup.add_argument ("--shadows")
- .help ("Wallpaper Engine's shadow quality: disabled, low, medium (default), high or ultra")
- .choices ("disabled", "low", "medium", "high", "ultra")
- .action ([this, qualityLevel] (const std::string& value) -> void {
- this->settings.general.shadowQuality = qualityLevel (value);
- });
- configurationGroup.add_argument ("--msaa")
- .help (
- "Wallpaper Engine's anti-aliasing setting: none (default), x2, x4 or x8. Like Wallpaper Engine it only "
- "applies "
- "to scenes with a 3D model object, which then draw their objects multisampled"
- )
- .choices ("none", "x2", "x4", "x8")
- .action ([this] (const std::string& value) -> void {
- this->settings.general.msaaSamples = value == "x2" ? 2 : value == "x4" ? 4 : value == "x8" ? 8 : 0;
- });
- configurationGroup.add_argument ("--disable-animations")
- .help ("Freezes all scene animation (scripts, particles, effects and puppet meshes) at its current frame")
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.render.freezeAnimations = true; });
- configurationGroup.add_argument ("--disable-mouse")
- .help ("Disables mouse interaction with the backgrounds")
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.mouse.enabled = false; });
- configurationGroup.add_argument ("--disable-parallax")
- .help ("Disables parallax effect for the backgrounds")
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.mouse.disableparallax = true; });
- configurationGroup.add_argument ("--allow-parallax-overflow")
- .help (
- "Lets parallax push an image past its own edges, exposing black corners on layers too small for the "
- "movement. Disabled by default, which clamps parallax displacement to each image's own size; images "
- "whose texture tiles/repeats are always exempt from the clamp, since going past their edges is seamless"
- )
- .flag ()
- .action ([this] (const std::string& value) -> void { this->settings.mouse.clampParallaxToImageSize = false; });
- configurationGroup.add_argument ("-l", "--list-properties")
- .help ("List all the available properties and their configuration")
- .flag ()
- .store_into (this->settings.general.onlyListProperties);
- configurationGroup.add_argument ("--set-property", "--property")
- .help ("Overrides the default value of the given property")
- .action ([this] (const std::string& value) -> void {
- const std::string::size_type equals = value.find ('=');
- // properties without a value are treated as booleans for now
- if (equals == std::string::npos) {
- this->settings.general.properties[value] = "1";
- } else {
- this->settings.general.properties[value.substr (0, equals)] = value.substr (equals + 1);
- }
- })
- .append ();
- configurationGroup.add_argument ("--list-objects")
- .help ("List all the objects/layers a background has, with their id, name and type")
- .flag ()
- .store_into (this->settings.general.onlyListObjects);
- configurationGroup.add_argument ("--disable-object")
- .help ("Hides an object/layer (parallax layer, clock, particles, etc), matched by id or name. Can be repeated")
- .action ([this] (const std::string& value) -> void {
- this->settings.general.disabledObjects.push_back (value);
- })
- .append ();
- configurationGroup.add_argument ("--enable-object")
- .help (
- "Forces an object/layer to show even if the background hides it by default, matched by id or name. "
- "Can be repeated"
- )
- .action ([this] (const std::string& value) -> void { this->settings.general.enabledObjects.push_back (value); })
- .append ();
- configurationGroup.add_argument ("--list-effects")
- .help (
- "List all effects (bloom, blur, glow, etc) attached to a background's objects, with their id, editor "
- "name and category"
- )
- .flag ()
- .store_into (this->settings.general.onlyListEffects);
- configurationGroup.add_argument ("--disable-effect")
- .help (
- "Disables an object's visual effect (bloom, blur, glow, etc), matched by effect id or editor name. "
- "Can be repeated"
- )
- .action ([this] (const std::string& value) -> void {
- this->settings.general.disabledEffects.push_back (value);
- })
- .append ();
- configurationGroup.add_argument ("--enable-effect")
- .help (
- "Forces an effect to show even if the scene hides it by default, matched by effect id or editor name. "
- "Can be repeated"
- )
- .action ([this] (const std::string& value) -> void { this->settings.general.enabledEffects.push_back (value); })
- .append ();
- configurationGroup.add_argument ("--list-audio-objects")
- .help (
- "List objects/properties whose script reacts to music (via engine.registerAudioBuffers), with their "
- "current minvalue/maxvalue/frequency/smoothing"
- )
- .flag ()
- .store_into (this->settings.general.onlyListAudioObjects);
- configurationGroup.add_argument ("--audio-sensitivity")
- .help (
- "Scales how much an audio-reactive object's music-driven properties swing around their authored "
- "midpoint, matched by id or name: 0 locks it (no pulse), 1 is the wallpaper's original behavior, "
- ">1 exaggerates it. Use \"*\" as the id to set a default for every audio-reactive object with no "
- "more specific match. Format: <id-or-name-or-*>=<multiplier>. Can be repeated"
- )
- .action ([this] (const std::string& value) -> void {
- const std::string::size_type equals = value.find ('=');
- if (equals == std::string::npos) {
- sLog.exception ("--audio-sensitivity expects <id-or-name>=<multiplier>, got '" + value + "'");
- }
- const std::string target = value.substr (0, equals);
- const std::string multiplierStr = value.substr (equals + 1);
- try {
- this->settings.general.audioSensitivity[target] = std::stof (multiplierStr);
- } catch (const std::exception&) {
- sLog.exception ("--audio-sensitivity: '" + multiplierStr + "' is not a valid number");
- }
- })
- .append ();
- configurationGroup.add_argument ("--sound-volume")
- .help (
- "Sets a Sound object's own volume (0-1), independent of the global volume - lets a wallpaper with "
- "several alternate music tracks play only one, matched by id or name. Use \"*\" as the id to set a "
- "default for every Sound object with no more specific match. Format: <id-or-name-or-*>=<volume>. Can "
- "be repeated"
- )
- .action ([this] (const std::string& value) -> void {
- const std::string::size_type equals = value.find ('=');
- if (equals == std::string::npos) {
- sLog.exception ("--sound-volume expects <id-or-name>=<volume>, got '" + value + "'");
- }
- const std::string target = value.substr (0, equals);
- const std::string volumeStr = value.substr (equals + 1);
- try {
- this->settings.general.soundVolume[target] = std::stof (volumeStr);
- } catch (const std::exception&) {
- sLog.exception ("--sound-volume: '" + volumeStr + "' is not a valid number");
- }
- })
- .append ();
- auto& debuggingGroup = program.add_group ("Debugging options");
- debuggingGroup.add_argument ("-z", "--dump-structure")
- .help ("Dumps the structure of the backgrounds")
- .flag ()
- .store_into (this->settings.general.dumpStructure);
- debuggingGroup.add_argument ("--render-debug")
- .help (
- "Scene render debug mode: base-only, no-solid-final, pass-log, brightness-log, no-puppet-animation, "
- "object=<id>, "
- "skip-object=<id>, or skip-effect=<id>. Can be repeated."
- )
- .action ([this] (const std::string& value) -> void {
- const auto parseDebugId = [&value] (const std::string& prefix) -> std::optional<int> {
- try {
- return std::stoi (value.substr (prefix.length ()));
- } catch (const std::invalid_argument&) {
- sLog.exception ("Invalid numeric value for --render-debug ", value);
- } catch (const std::out_of_range&) {
- sLog.exception ("Out-of-range numeric value for --render-debug ", value);
- }
- return std::nullopt;
- };
- if (value == "base-only") {
- this->settings.render.debug.baseOnly = true;
- } else if (value == "no-solid-final") {
- this->settings.render.debug.noSolidFinal = true;
- } else if (value == "pass-log") {
- this->settings.render.debug.passLog = true;
- } else if (value == "brightness-log") {
- this->settings.render.debug.brightnessLog = true;
- } else if (value == "no-puppet-animation") {
- this->settings.render.debug.noPuppetAnimation = true;
- } else if (value.rfind ("object=", 0) == 0) {
- this->settings.render.debug.objectFilter = parseDebugId ("object=");
- } else if (value.rfind ("skip-object=", 0) == 0) {
- if (const auto id = parseDebugId ("skip-object="); id.has_value ()) {
- this->settings.render.debug.skipObjects.emplace_back (*id);
- }
- } else if (value.rfind ("skip-effect=", 0) == 0) {
- if (const auto id = parseDebugId ("skip-effect="); id.has_value ()) {
- this->settings.render.debug.skipEffects.emplace_back (*id);
- }
- } else {
- sLog.exception ("Invalid render debug mode: ", value);
- }
- })
- .append ();
- program.add_epilog (
- "Usage examples:\n"
- " linux-wallpaperengine --screen-root HDMI-1 --bg 2317494988 --scaling fill --clamp border\n"
- " Runs the background 2317494988 on screen HDMI-1, scaling it to fill the screen and clamping the UVs to "
- "the border\n\n"
- " linux-wallpaperengine 2317494988\n"
- " Previews the background 2317494988 on a window\n\n"
- " linux-wallpaperengine --screen-root HDMI-1 --bg 2317494988 --screen-root HDMI-2 --bg 1108150151\n"
- " Runs two backgrounds on two screens, one on HDMI-1 and the other on HDMI-2\n\n"
- " linux-wallpaperengine --screen-root HDMI-1 --screen-root HDMI-2 2317494988\n"
- " Runs the background 2317494988 on two screens, one on HDMI-1 and the other on HDMI-2\n\n"
- " linux-wallpaperengine --screen-span HDMI-1,HDMI-2 --bg 2317494988 --scaling fill\n"
- " Spans the background 2317494988 across HDMI-1 and HDMI-2 as a single stretched wallpaper\n\n"
- );
- try {
- program.parse_known_args (this->m_argc, this->m_argv);
- if (!program.is_used ("--layer")) {
- const auto* desktopSession = std::getenv ("DESKTOP_SESSION");
- const auto* xdgDesktop = std::getenv ("XDG_SESSION_DESKTOP");
- const auto* kdeSession = std::getenv ("KDE_FULL_SESSION");
- bool onKDE = false;
- if (desktopSession) {
- std::string_view s (desktopSession);
- onKDE = s.find ("kde") != std::string_view::npos || s.find ("plasma") != std::string_view::npos;
- }
- if (!onKDE && xdgDesktop && std::string_view (xdgDesktop) == "KDE") {
- onKDE = true;
- }
- if (!onKDE && kdeSession && std::string_view (kdeSession) == "true") {
- onKDE = true;
- }
- if (onKDE) {
- this->settings.render.wayland.layer = WAYLAND_LAYER_BACKGROUND;
- if (!isHelperProcess (this->m_argc, this->m_argv, this->settings.general.webHost)) {
- sLog.out (
- "KDE detected: using --layer background to prevent 'show desktop' from hiding the wallpaper "
- "(use --layer bottom to override)"
- );
- }
- }
- }
- if (this->settings.general.defaultBackground.empty ()) {
- throw std::runtime_error ("At least one background ID must be specified");
- }
- this->settings.audio.volume = std::max (0, std::min (this->settings.audio.volume, 128));
- if (this->settings.audio.ambientVolume.has_value ()) {
- this->settings.audio.ambientVolume = std::max (0, std::min (*this->settings.audio.ambientVolume, 128));
- }
- this->settings.screenshot.delay
- = std::max<uint32_t> (0, std::min<uint32_t> (this->settings.screenshot.delay, 5000));
- // std::cout directly, in case logging is disabled, so this is still visible
- std::stringbuf buffer;
- std::ostream bufferStream (&buffer);
- bufferStream << "Running with: ";
- for (int i = 0; i < this->m_argc; i++) {
- bufferStream << this->m_argv[i];
- bufferStream << " ";
- }
- if (!isHelperProcess (this->m_argc, this->m_argv, this->settings.general.webHost)) {
- std::cout << buffer.str () << std::endl;
- }
- this->validateAssets ();
- this->validateScreenshot ();
- this->state.general.keepRunning = true;
- this->state.audio.enabled = this->settings.audio.enabled;
- this->state.audio.volume = this->settings.audio.volume;
- this->state.mouse.enabled = this->settings.mouse.enabled;
- #if DEMOMODE
- sLog.error ("WARNING: RUNNING IN DEMO MODE WILL STOP WALLPAPERS AFTER 5 SECONDS SO VIDEO CAN BE RECORDED");
- this->settings.render.maximumFPS = 30;
- this->settings.screenshot.take = false;
- this->settings.render.pauseOnFullscreen = false;
- #endif /* DEMOMODE */
- } catch (const std::runtime_error& e) {
- throw std::runtime_error (
- std::string (e.what ()) + ". Use " + std::string (this->m_argv[0]) + " --help for more information"
- );
- }
- }
- int ApplicationContext::getArgc () const { return this->m_argc; }
- char** ApplicationContext::getArgv () const { return this->m_argv; }
- std::filesystem::path ApplicationContext::translateBackground (const std::string& bgIdOrPath) {
- if (bgIdOrPath.find ('/') == std::string::npos) {
- return Steam::FileSystem::workshopDirectory (WORKSHOP_APP_ID, bgIdOrPath);
- }
- return bgIdOrPath;
- }
- void ApplicationContext::validateAssets () {
- if (!this->settings.general.assets.empty ()) {
- if (!isHelperProcess (this->m_argc, this->m_argv, this->settings.general.webHost)) {
- sLog.out (
- "Using wallpaper engine's assets at ", this->settings.general.assets, " based on --assets-dir parameter"
- );
- }
- return;
- }
- try {
- this->settings.general.assets = Steam::FileSystem::appDirectory (APP_DIRECTORY, "assets");
- } catch (std::runtime_error&) {
- this->settings.general.assets = std::filesystem::canonical ("/proc/self/exe").parent_path () / "assets";
- }
- }
- void ApplicationContext::validateScreenshot () const {
- if (!this->settings.screenshot.take) {
- return;
- }
- if (!this->settings.screenshot.path.has_extension ()) {
- sLog.exception ("Cannot determine screenshot format");
- }
- const std::string extension = this->settings.screenshot.path.extension ();
- if (extension != ".bmp" && extension != ".png" && extension != ".jpeg" && extension != ".jpg") {
- sLog.exception ("Cannot determine screenshot format, unknown extension ", extension);
- }
- }
|