From dfd3d090dc8779f566a224051d9c366511a8556b Mon Sep 17 00:00:00 2001 From: Stephen Toth Date: Sun, 25 Feb 2024 17:05:58 -0600 Subject: [PATCH] core: fix being able to assign a wallpaper to a nonexistent monitor (#141) clarified README to specifics of the handleWallpaper function --- README.md | 2 +- src/config/ConfigManager.cpp | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8ee8234..78fedd1 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ splash = true ``` -Preload will tell Hyprland to load a particular image (supported formats: png, jpg, jpeg, webp). Wallpaper will apply the wallpaper to the selected output (`monitor` is the monitor's name, easily can be retrieved with `hyprctl monitors`. You can leave it empty for a wildcard (aka fallback). You can also use `desc:` followed by the monitor's description without the (PORT) at the end) +Preload will tell Hyprland to load a particular image (supported formats: png, jpg, jpeg, webp). Wallpaper will apply the wallpaper to the selected output (`monitor` is the monitor's name, easily can be retrieved with `hyprctl monitors`. You can leave it empty to set all monitors without an active wallpaper. You can also use `desc:` followed by the monitor's description without the (PORT) at the end) You may add `contain:` before the file path in `wallpaper=` to set the mode to contain instead of cover: diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 21c66bb..cdf3672 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -36,24 +36,29 @@ static Hyprlang::CParseResult handleWallpaper(const char* C, const char* V) { return result; } - g_pHyprpaper->clearWallpaperFromMonitor(MONITOR); - g_pHyprpaper->m_mMonitorActiveWallpapers[MONITOR] = WALLPAPER; - g_pHyprpaper->m_mMonitorWallpaperRenderData[MONITOR].contain = contain; - - if (MONITOR.empty()) { + if (MONITOR.empty()) { //if the monitor string is empty we set all the empty monitors to the same wallpaper for (auto& m : g_pHyprpaper->m_vMonitors) { if (!m->hasATarget || m->wildcard) { + Debug::log(LOG, "Setting wallpaper for monitor %s", m->name); g_pHyprpaper->clearWallpaperFromMonitor(m->name); g_pHyprpaper->m_mMonitorActiveWallpapers[m->name] = WALLPAPER; g_pHyprpaper->m_mMonitorWallpaperRenderData[m->name].contain = contain; } } - } else { - const auto PMON = g_pHyprpaper->getMonitorFromName(MONITOR); - if (PMON) - PMON->wildcard = false; + return result; } + const auto PMON = g_pHyprpaper->getMonitorFromName(MONITOR); + if (!PMON){ //does monitor by name of MONITOR exist? + result.setError("wallpaper failed (no such monitor)"); + return result; + } + + g_pHyprpaper->clearWallpaperFromMonitor(MONITOR); //should be fine to keep using MONITOR instead of using PMON->name here + g_pHyprpaper->m_mMonitorActiveWallpapers[MONITOR] = WALLPAPER; + g_pHyprpaper->m_mMonitorWallpaperRenderData[MONITOR].contain = contain; + + PMON->wildcard = false; return result; }