From 66b3ba8d9faa6b6a8894ecc03ac61667d344b8bc Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:44:51 +0100 Subject: [PATCH] internal: allow desc: for monitors --- README.md | 2 +- src/Hyprpaper.cpp | 25 +++++++++++++++++++++++++ src/events/Events.cpp | 4 +++- src/helpers/Monitor.hpp | 1 + 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 47cd8dc..612e09c 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ wallpaper = monitor2,/path/to/next_image.png # .. more monitors ``` -Preload will tell Hyprland to load a particular image (supported formats: png, jpg, jpeg). 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)) +Preload will tell Hyprland to load a particular image (supported formats: png, jpg, jpeg). 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) You may add `contain:` before the file path in `wallpaper=` to set the mode to contain instead of cover: diff --git a/src/Hyprpaper.cpp b/src/Hyprpaper.cpp index 09b45c8..8548ad9 100644 --- a/src/Hyprpaper.cpp +++ b/src/Hyprpaper.cpp @@ -184,7 +184,17 @@ void CHyprpaper::removeOldHyprpaperImages() { } SMonitor* CHyprpaper::getMonitorFromName(const std::string& monname) { + bool useDesc = false; + std::string desc = ""; + if (monname.find("desc:") == 0) { + useDesc = true; + desc = monname.substr(5); + } + for (auto& m : m_vMonitors) { + if (useDesc && m->description.find(desc) == 0) + return m.get(); + if (m->name == monname) return m.get(); } @@ -270,6 +280,21 @@ void CHyprpaper::ensureMonitorHasActiveWallpaper(SMonitor* pMonitor) { return; // has // get the target + for (auto& [mon, path1] : m_mMonitorActiveWallpapers) { + if (mon.find("desc:") != 0) + continue; + + if (pMonitor->description.find(mon.substr(5)) == 0) { + for (auto& [path2, target] : m_mWallpaperTargets) { + if (path1 == path2) { + it->second = ⌖ + break; + } + } + break; + } + } + for (auto& [mon, path1] : m_mMonitorActiveWallpapers) { if (mon == pMonitor->name) { for (auto& [path2, target] : m_mWallpaperTargets) { diff --git a/src/events/Events.cpp b/src/events/Events.cpp index 0222710..1852ae4 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -32,7 +32,9 @@ void Events::name(void *data, wl_output *wl_output, const char *name) { } void Events::description(void *data, wl_output *wl_output, const char *description) { - // i do not care + const auto PMONITOR = (SMonitor*)data; + + PMONITOR->description = description; } void Events::handleCapabilities(void *data, wl_seat *wl_seat, uint32_t capabilities) { diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index 9debb72..6950544 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -6,6 +6,7 @@ struct SMonitor { std::string name = ""; + std::string description = ""; wl_output* output = nullptr; uint32_t wayland_name = 0; Vector2D size;