mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 06:25:58 +01:00
Reuse same ID when reconnecting monitor, otherwise use minimum available ID (#2666)
Fixes #2601
This commit is contained in:
parent
b33d82734f
commit
b99ac063ea
3 changed files with 20 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include "Compositor.hpp"
|
#include "Compositor.hpp"
|
||||||
#include "helpers/Splashes.hpp"
|
#include "helpers/Splashes.hpp"
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <unordered_set>
|
||||||
#include "debug/HyprCtl.hpp"
|
#include "debug/HyprCtl.hpp"
|
||||||
#include "debug/CrashReporter.hpp"
|
#include "debug/CrashReporter.hpp"
|
||||||
#ifdef USES_SYSTEMD
|
#ifdef USES_SYSTEMD
|
||||||
|
@ -1697,14 +1698,23 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
|
||||||
d->updateWindow(pWindow);
|
d->updateWindow(pWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCompositor::getNextAvailableMonitorID() {
|
int CCompositor::getNextAvailableMonitorID(std::string const& name) {
|
||||||
int64_t topID = -1;
|
// reuse ID if it's already in the map
|
||||||
for (auto& m : m_vRealMonitors) {
|
if (m_mMonitorIDMap.contains(name))
|
||||||
if ((int64_t)m->ID > topID)
|
return m_mMonitorIDMap[name];
|
||||||
topID = m->ID;
|
|
||||||
|
// otherwise, find minimum available ID that is not in the map
|
||||||
|
std::unordered_set<int> 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) {
|
void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) {
|
||||||
|
|
|
@ -101,6 +101,8 @@ class CCompositor {
|
||||||
std::vector<CWindow*> m_vWindowsFadingOut;
|
std::vector<CWindow*> m_vWindowsFadingOut;
|
||||||
std::vector<SLayerSurface*> m_vSurfacesFadingOut;
|
std::vector<SLayerSurface*> m_vSurfacesFadingOut;
|
||||||
|
|
||||||
|
std::unordered_map<std::string, int64_t> m_mMonitorIDMap;
|
||||||
|
|
||||||
void initServer();
|
void initServer();
|
||||||
void startCompositor();
|
void startCompositor();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
@ -168,7 +170,7 @@ class CCompositor {
|
||||||
CMonitor* getMonitorInDirection(const char&);
|
CMonitor* getMonitorInDirection(const char&);
|
||||||
void updateAllWindowsAnimatedDecorationValues();
|
void updateAllWindowsAnimatedDecorationValues();
|
||||||
void updateWindowAnimatedDecorationValues(CWindow*);
|
void updateWindowAnimatedDecorationValues(CWindow*);
|
||||||
int getNextAvailableMonitorID();
|
int getNextAvailableMonitorID(std::string const & name);
|
||||||
void moveWorkspaceToMonitor(CWorkspace*, CMonitor*);
|
void moveWorkspaceToMonitor(CWorkspace*, CMonitor*);
|
||||||
void swapActiveWorkspaces(CMonitor*, CMonitor*);
|
void swapActiveWorkspaces(CMonitor*, CMonitor*);
|
||||||
CMonitor* getMonitorFromString(const std::string&);
|
CMonitor* getMonitorFromString(const std::string&);
|
||||||
|
|
|
@ -76,7 +76,7 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
|
||||||
Debug::log(LOG, "Adding completely new monitor.");
|
Debug::log(LOG, "Adding completely new monitor.");
|
||||||
PNEWMONITORWRAP = &g_pCompositor->m_vRealMonitors.emplace_back(std::make_shared<CMonitor>());
|
PNEWMONITORWRAP = &g_pCompositor->m_vRealMonitors.emplace_back(std::make_shared<CMonitor>());
|
||||||
|
|
||||||
(*PNEWMONITORWRAP)->ID = g_pCompositor->getNextAvailableMonitorID();
|
(*PNEWMONITORWRAP)->ID = g_pCompositor->getNextAvailableMonitorID(OUTPUT->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto PNEWMONITOR = PNEWMONITORWRAP->get();
|
const auto PNEWMONITOR = PNEWMONITORWRAP->get();
|
||||||
|
|
Loading…
Reference in a new issue