mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-23 03:29:48 +01:00
added experimental monitor saving
This commit is contained in:
parent
9b39a0c2e0
commit
58ff04fdf3
3 changed files with 53 additions and 29 deletions
|
@ -97,6 +97,7 @@ public:
|
||||||
bool m_bReadyToProcess = false;
|
bool m_bReadyToProcess = false;
|
||||||
bool m_bSessionActive = true;
|
bool m_bSessionActive = true;
|
||||||
bool m_bDPMSStateON = true;
|
bool m_bDPMSStateON = true;
|
||||||
|
bool m_bUnsafeState = false; // unsafe state is when there is no monitors.
|
||||||
|
|
||||||
// ------------------------------------------------- //
|
// ------------------------------------------------- //
|
||||||
|
|
||||||
|
@ -159,6 +160,7 @@ public:
|
||||||
SLayerSurface* getLayerSurfaceFromSurface(wlr_surface*);
|
SLayerSurface* getLayerSurfaceFromSurface(wlr_surface*);
|
||||||
void closeWindow(CWindow*);
|
void closeWindow(CWindow*);
|
||||||
|
|
||||||
|
|
||||||
std::string explicitConfigPath;
|
std::string explicitConfigPath;
|
||||||
|
|
||||||
void startHyprCtlTick();
|
void startHyprCtlTick();
|
||||||
|
|
|
@ -53,16 +53,29 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_pCompositor->getMonitorFromName(std::string(OUTPUT->name))) {
|
if (g_pCompositor->m_bUnsafeState) {
|
||||||
Debug::log(WARN, "Monitor with name %s already exists, not adding as new!", OUTPUT->name);
|
Debug::log(WARN, "Recovering from an unsafe state. May you be lucky.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add it to real
|
// add it to real
|
||||||
const auto PNEWMONITORWRAP = &g_pCompositor->m_vRealMonitors.emplace_back(std::make_shared<CMonitor>());
|
std::shared_ptr<CMonitor>* PNEWMONITORWRAP = nullptr;
|
||||||
const auto PNEWMONITOR = PNEWMONITORWRAP->get();
|
|
||||||
|
|
||||||
PNEWMONITOR->ID = g_pCompositor->getNextAvailableMonitorID();
|
for (auto& rm : g_pCompositor->m_vRealMonitors) {
|
||||||
|
if (rm->szName == OUTPUT->name) {
|
||||||
|
PNEWMONITORWRAP = &rm;
|
||||||
|
Debug::log(LOG, "Recovering a removed monitor.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!PNEWMONITORWRAP) {
|
||||||
|
Debug::log(LOG, "Adding completely new monitor.");
|
||||||
|
PNEWMONITORWRAP = &g_pCompositor->m_vRealMonitors.emplace_back(std::make_shared<CMonitor>());
|
||||||
|
|
||||||
|
(*PNEWMONITORWRAP)->ID = g_pCompositor->getNextAvailableMonitorID();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto PNEWMONITOR = PNEWMONITORWRAP->get();
|
||||||
|
|
||||||
PNEWMONITOR->output = OUTPUT;
|
PNEWMONITOR->output = OUTPUT;
|
||||||
PNEWMONITOR->m_pThisWrap = PNEWMONITORWRAP;
|
PNEWMONITOR->m_pThisWrap = PNEWMONITORWRAP;
|
||||||
|
@ -73,14 +86,16 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
|
||||||
pMostHzMonitor = PNEWMONITOR;
|
pMostHzMonitor = PNEWMONITOR;
|
||||||
|
|
||||||
// ready to process cuz we have a monitor
|
// ready to process cuz we have a monitor
|
||||||
if (PNEWMONITOR->m_bEnabled)
|
if (PNEWMONITOR->m_bEnabled) {
|
||||||
g_pCompositor->m_bReadyToProcess = true;
|
g_pCompositor->m_bReadyToProcess = true;
|
||||||
|
g_pCompositor->m_bUnsafeState = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::listener_monitorFrame(void* owner, void* data) {
|
void Events::listener_monitorFrame(void* owner, void* data) {
|
||||||
CMonitor* const PMONITOR = (CMonitor*)owner;
|
CMonitor* const PMONITOR = (CMonitor*)owner;
|
||||||
|
|
||||||
if ((g_pCompositor->m_sWLRSession && !g_pCompositor->m_sWLRSession->active) || !g_pCompositor->m_bSessionActive) {
|
if ((g_pCompositor->m_sWLRSession && !g_pCompositor->m_sWLRSession->active) || !g_pCompositor->m_bSessionActive || g_pCompositor->m_bUnsafeState) {
|
||||||
Debug::log(WARN, "Attempted to render frame on inactive session!");
|
Debug::log(WARN, "Attempted to render frame on inactive session!");
|
||||||
return; // cannot draw on session inactive (different tty)
|
return; // cannot draw on session inactive (different tty)
|
||||||
}
|
}
|
||||||
|
@ -294,20 +309,23 @@ void Events::listener_monitorDestroy(void* owner, void* data) {
|
||||||
|
|
||||||
pMonitor->onDisconnect();
|
pMonitor->onDisconnect();
|
||||||
|
|
||||||
// cleanup
|
// cleanup if not unsafe
|
||||||
g_pCompositor->m_vRealMonitors.erase(std::remove_if(g_pCompositor->m_vRealMonitors.begin(), g_pCompositor->m_vRealMonitors.end(), [&](std::shared_ptr<CMonitor>& el) { return el.get() == pMonitor; }));
|
|
||||||
|
|
||||||
if (pMostHzMonitor == pMonitor) {
|
if (!g_pCompositor->m_bUnsafeState) {
|
||||||
int mostHz = 0;
|
g_pCompositor->m_vRealMonitors.erase(std::remove_if(g_pCompositor->m_vRealMonitors.begin(), g_pCompositor->m_vRealMonitors.end(), [&](std::shared_ptr<CMonitor>& el) { return el.get() == pMonitor; }));
|
||||||
CMonitor* pMonitorMostHz = nullptr;
|
|
||||||
|
|
||||||
for (auto& m : g_pCompositor->m_vMonitors) {
|
if (pMostHzMonitor == pMonitor) {
|
||||||
if (m->refreshRate > mostHz) {
|
int mostHz = 0;
|
||||||
pMonitorMostHz = m.get();
|
CMonitor* pMonitorMostHz = nullptr;
|
||||||
mostHz = m->refreshRate;
|
|
||||||
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
||||||
|
if (m->refreshRate > mostHz) {
|
||||||
|
pMonitorMostHz = m.get();
|
||||||
|
mostHz = m->refreshRate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pMostHzMonitor = pMonitorMostHz;
|
pMostHzMonitor = pMonitorMostHz;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,6 +160,9 @@ void CMonitor::onConnect(bool noRule) {
|
||||||
|
|
||||||
wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, scale);
|
wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, scale);
|
||||||
|
|
||||||
|
g_pHyprRenderer->arrangeLayersForMonitor(ID);
|
||||||
|
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID);
|
||||||
|
|
||||||
g_pEventManager->postEvent(SHyprIPCEvent{"monitoradded", szName});
|
g_pEventManager->postEvent(SHyprIPCEvent{"monitoradded", szName});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,16 +180,21 @@ void CMonitor::onDisconnect() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!BACKUPMON) {
|
|
||||||
Debug::log(CRIT, "No monitors! Unplugged last! Exiting.");
|
|
||||||
g_pCompositor->cleanup();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_bEnabled = false;
|
m_bEnabled = false;
|
||||||
|
|
||||||
hyprListener_monitorFrame.removeCallback();
|
hyprListener_monitorFrame.removeCallback();
|
||||||
|
|
||||||
|
if (!BACKUPMON) {
|
||||||
|
Debug::log(WARN, "Unplugged last monitor, entering an unsafe state. Good luck my friend.");
|
||||||
|
|
||||||
|
hyprListener_monitorMode.removeCallback();
|
||||||
|
hyprListener_monitorDestroy.removeCallback();
|
||||||
|
|
||||||
|
g_pCompositor->m_bUnsafeState = true;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto BACKUPWORKSPACE = BACKUPMON->activeWorkspace > 0 ? std::to_string(BACKUPMON->activeWorkspace) : "name:" + g_pCompositor->getWorkspaceByID(BACKUPMON->activeWorkspace)->m_szName;
|
const auto BACKUPWORKSPACE = BACKUPMON->activeWorkspace > 0 ? std::to_string(BACKUPMON->activeWorkspace) : "name:" + g_pCompositor->getWorkspaceByID(BACKUPMON->activeWorkspace)->m_szName;
|
||||||
|
|
||||||
// snap cursor
|
// snap cursor
|
||||||
|
@ -215,10 +223,6 @@ void CMonitor::onDisconnect() {
|
||||||
|
|
||||||
wlr_output_commit(output);
|
wlr_output_commit(output);
|
||||||
|
|
||||||
for (auto& lsl : m_aLayerSurfaceLists) {
|
|
||||||
lsl.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
g_pCompositor->m_vWorkspaces.erase(std::remove_if(g_pCompositor->m_vWorkspaces.begin(), g_pCompositor->m_vWorkspaces.end(), [&](std::unique_ptr<CWorkspace>& el) { return el->m_iMonitorID == ID; }));
|
g_pCompositor->m_vWorkspaces.erase(std::remove_if(g_pCompositor->m_vWorkspaces.begin(), g_pCompositor->m_vWorkspaces.end(), [&](std::unique_ptr<CWorkspace>& el) { return el->m_iMonitorID == ID; }));
|
||||||
|
|
||||||
Debug::log(LOG, "Removed monitor %s!", szName.c_str());
|
Debug::log(LOG, "Removed monitor %s!", szName.c_str());
|
||||||
|
|
Loading…
Reference in a new issue