diff options
author | vaxerski <[email protected]> | 2022-05-29 20:15:34 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2022-05-29 20:15:34 +0200 |
commit | b76b32b458ab6e67632a110758ac5fe6e3701948 (patch) | |
tree | 33f55ff4e9080754f1d706f404066030b89be33c | |
parent | f5645805d8db9e6d45dd4d82bff12054b3b81180 (diff) | |
download | Hyprland-b76b32b458ab6e67632a110758ac5fe6e3701948.tar.gz Hyprland-b76b32b458ab6e67632a110758ac5fe6e3701948.zip |
don't add existing and invalid monitors
-rw-r--r-- | src/Compositor.cpp | 10 | ||||
-rw-r--r-- | src/Compositor.hpp | 1 | ||||
-rw-r--r-- | src/events/Monitors.cpp | 10 |
3 files changed, 21 insertions, 0 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 49844286..29e2f188 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -255,6 +255,16 @@ SMonitor* CCompositor::getMonitorFromID(const int& id) { return nullptr; } +SMonitor* CCompositor::getMonitorFromName(const std::string& name) { + for (auto& m : m_lMonitors) { + if (m.szName == name) { + return &m; + } + } + + return nullptr; +} + SMonitor* CCompositor::getMonitorFromCursor() { const auto COORDS = Vector2D(m_sWLRCursor->x, m_sWLRCursor->y); diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 870819fb..d2839103 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -86,6 +86,7 @@ public: // ------------------------------------------------- // SMonitor* getMonitorFromID(const int&); + SMonitor* getMonitorFromName(const std::string&); SMonitor* getMonitorFromCursor(); SMonitor* getMonitorFromVector(const Vector2D&); void removeWindowFromVectorSafe(CWindow*); diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index 3acea781..2e05d278 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -48,6 +48,16 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { // new monitor added, let's accomodate for that. const auto OUTPUT = (wlr_output*)data; + if (!OUTPUT->name) { + Debug::log(ERR, "New monitor has no name?? Ignoring"); + return; + } + + if (g_pCompositor->getMonitorFromName(std::string(OUTPUT->name))) { + Debug::log(WARN, "Monitor with name %s already exists, not adding as new!", OUTPUT->name); + return; + } + // get monitor rule that matches SMonitorRule monitorRule = g_pConfigManager->getMonitorRuleFor(OUTPUT->name); |