From b99ac063eae32995ba83047a4c5d4cb3490a4b10 Mon Sep 17 00:00:00 2001 From: Tuur Vanhoutte <4633209+zjeffer@users.noreply.github.com> Date: Sun, 9 Jul 2023 23:08:40 +0200 Subject: Reuse same ID when reconnecting monitor, otherwise use minimum available ID (#2666) Fixes #2601 --- src/Compositor.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index ae3ef109..50ea0b5d 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1,6 +1,7 @@ #include "Compositor.hpp" #include "helpers/Splashes.hpp" #include +#include #include "debug/HyprCtl.hpp" #include "debug/CrashReporter.hpp" #ifdef USES_SYSTEMD @@ -1697,14 +1698,23 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) { d->updateWindow(pWindow); } -int CCompositor::getNextAvailableMonitorID() { - int64_t topID = -1; - for (auto& m : m_vRealMonitors) { - if ((int64_t)m->ID > topID) - topID = m->ID; +int CCompositor::getNextAvailableMonitorID(std::string const& name) { + // reuse ID if it's already in the map + if (m_mMonitorIDMap.contains(name)) + return m_mMonitorIDMap[name]; + + // otherwise, find minimum available ID that is not in the map + std::unordered_set usedIDs; + for (auto const& monitor : m_vRealMonitors) { + usedIDs.insert(monitor->ID); } - return topID + 1; + int nextID = 0; + while (usedIDs.count(nextID) > 0) { + nextID++; + } + m_mMonitorIDMap[name] = nextID; + return nextID; } void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) { -- cgit v1.2.3