From d2eb4fee76f8e8158f34c38647ced42fbe25ef0d Mon Sep 17 00:00:00 2001 From: Tuur Vanhoutte <4633209+zjeffer@users.noreply.github.com> Date: Tue, 18 Jul 2023 12:12:05 +0200 Subject: Avoid connected monitor reusing unavailable ID (#2731) --- src/Compositor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 0929b7c1..520b4342 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1707,17 +1707,17 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) { } int CCompositor::getNextAvailableMonitorID(std::string const& name) { - // reuse ID if it's already in the map - if (m_mMonitorIDMap.contains(name)) + // reuse ID if it's already in the map, and the monitor with that ID is not being used by another monitor + if (m_mMonitorIDMap.contains(name) && !std::any_of(m_vRealMonitors.begin(), m_vRealMonitors.end(), [&](auto m) { return m->ID == m_mMonitorIDMap[name]; })) return m_mMonitorIDMap[name]; // otherwise, find minimum available ID that is not in the map - std::unordered_set usedIDs; + std::unordered_set usedIDs; for (auto const& monitor : m_vRealMonitors) { usedIDs.insert(monitor->ID); } - int nextID = 0; + uint64_t nextID = 0; while (usedIDs.count(nextID) > 0) { nextID++; } -- cgit v1.2.3