Avoid connected monitor reusing unavailable ID (#2731)

This commit is contained in:
Tuur Vanhoutte 2023-07-18 12:12:05 +02:00 committed by GitHub
parent 4537860079
commit d2eb4fee76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -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<int> usedIDs;
std::unordered_set<uint64_t> usedIDs;
for (auto const& monitor : m_vRealMonitors) {
usedIDs.insert(monitor->ID);
}
int nextID = 0;
uint64_t nextID = 0;
while (usedIDs.count(nextID) > 0) {
nextID++;
}

View file

@ -102,7 +102,7 @@ class CCompositor {
std::vector<CWindow*> m_vWindowsFadingOut;
std::vector<SLayerSurface*> m_vSurfacesFadingOut;
std::unordered_map<std::string, int64_t> m_mMonitorIDMap;
std::unordered_map<std::string, uint64_t> m_mMonitorIDMap;
void initServer();
void startCompositor();