monitor: move to sharedptr

This commit is contained in:
Vaxry 2024-06-13 16:11:08 +02:00
parent 9e781040d9
commit eeb0a83984
74 changed files with 604 additions and 602 deletions

View file

@ -315,7 +315,7 @@ void CCompositor::cleanup() {
m_vWindows.clear(); m_vWindows.clear();
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
g_pHyprOpenGL->destroyMonitorResources(m.get()); g_pHyprOpenGL->destroyMonitorResources(m);
wlr_output_state_set_enabled(m->state.wlr(), false); wlr_output_state_set_enabled(m->state.wlr(), false);
m->state.commit(); m->state.commit();
@ -570,39 +570,39 @@ void CCompositor::startCompositor() {
g_pEventLoopManager->enterLoop(m_sWLDisplay, m_sWLEventLoop); g_pEventLoopManager->enterLoop(m_sWLDisplay, m_sWLEventLoop);
} }
CMonitor* CCompositor::getMonitorFromID(const int& id) { PHLMONITOR CCompositor::getMonitorFromID(const int& id) {
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
if (m->ID == (uint64_t)id) { if (m->ID == (uint64_t)id) {
return m.get(); return m;
} }
} }
return nullptr; return nullptr;
} }
CMonitor* CCompositor::getMonitorFromName(const std::string& name) { PHLMONITOR CCompositor::getMonitorFromName(const std::string& name) {
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
if (m->szName == name) { if (m->szName == name) {
return m.get(); return m;
} }
} }
return nullptr; return nullptr;
} }
CMonitor* CCompositor::getMonitorFromDesc(const std::string& desc) { PHLMONITOR CCompositor::getMonitorFromDesc(const std::string& desc) {
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
if (m->szDescription.starts_with(desc)) if (m->szDescription.starts_with(desc))
return m.get(); return m;
} }
return nullptr; return nullptr;
} }
CMonitor* CCompositor::getMonitorFromCursor() { PHLMONITOR CCompositor::getMonitorFromCursor() {
return getMonitorFromVector(g_pPointerManager->position()); return getMonitorFromVector(g_pPointerManager->position());
} }
CMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) { PHLMONITOR CCompositor::getMonitorFromVector(const Vector2D& point) {
SP<CMonitor> mon; PHLMONITOR mon;
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
if (CBox{m->vecPosition, m->vecSize}.containsPoint(point)) { if (CBox{m->vecPosition, m->vecSize}.containsPoint(point)) {
mon = m; mon = m;
@ -612,7 +612,7 @@ CMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
if (!mon) { if (!mon) {
float bestDistance = 0.f; float bestDistance = 0.f;
SP<CMonitor> pBestMon; PHLMONITOR pBestMon;
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
float dist = vecToRectDistanceSquared(point, m->vecPosition, m->vecPosition + m->vecSize); float dist = vecToRectDistanceSquared(point, m->vecPosition, m->vecPosition + m->vecSize);
@ -625,13 +625,13 @@ CMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
if (!pBestMon) { // ????? if (!pBestMon) { // ?????
Debug::log(WARN, "getMonitorFromVector no close mon???"); Debug::log(WARN, "getMonitorFromVector no close mon???");
return m_vMonitors.front().get(); return m_vMonitors.front();
} }
return pBestMon.get(); return pBestMon;
} }
return mon.get(); return mon;
} }
void CCompositor::removeWindowFromVectorSafe(PHLWINDOW pWindow) { void CCompositor::removeWindowFromVectorSafe(PHLWINDOW pWindow) {
@ -643,15 +643,6 @@ void CCompositor::removeWindowFromVectorSafe(PHLWINDOW pWindow) {
} }
} }
bool CCompositor::monitorExists(CMonitor* pMonitor) {
for (auto& m : m_vRealMonitors) {
if (m.get() == pMonitor)
return true;
}
return false;
}
PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t properties, PHLWINDOW pIgnoreWindow) { PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t properties, PHLWINDOW pIgnoreWindow) {
const auto PMONITOR = getMonitorFromVector(pos); const auto PMONITOR = getMonitorFromVector(pos);
static auto PRESIZEONBORDER = CConfigValue<Hyprlang::INT>("general:resize_on_border"); static auto PRESIZEONBORDER = CConfigValue<Hyprlang::INT>("general:resize_on_border");
@ -834,20 +825,20 @@ Vector2D CCompositor::vectorToSurfaceLocal(const Vector2D& vec, PHLWINDOW pWindo
return vec - pWindow->m_vRealPosition.goal() - std::get<1>(iterData) + Vector2D{geom.x, geom.y}; return vec - pWindow->m_vRealPosition.goal() - std::get<1>(iterData) + Vector2D{geom.x, geom.y};
} }
CMonitor* CCompositor::getMonitorFromOutput(wlr_output* out) { PHLMONITOR CCompositor::getMonitorFromOutput(wlr_output* out) {
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
if (m->output == out) { if (m->output == out) {
return m.get(); return m;
} }
} }
return nullptr; return nullptr;
} }
CMonitor* CCompositor::getRealMonitorFromOutput(wlr_output* out) { PHLMONITOR CCompositor::getRealMonitorFromOutput(wlr_output* out) {
for (auto& m : m_vRealMonitors) { for (auto& m : m_vRealMonitors) {
if (m->output == out) { if (m->output == out) {
return m.get(); return m;
} }
} }
@ -1035,7 +1026,7 @@ void CCompositor::focusSurface(SP<CWLSurfaceResource> pSurface, PHLWINDOW pWindo
SURF->constraint()->activate(); SURF->constraint()->activate();
} }
SP<CWLSurfaceResource> CCompositor::vectorToLayerPopupSurface(const Vector2D& pos, CMonitor* monitor, Vector2D* sCoords, PHLLS* ppLayerSurfaceFound) { SP<CWLSurfaceResource> CCompositor::vectorToLayerPopupSurface(const Vector2D& pos, PHLMONITOR monitor, Vector2D* sCoords, PHLLS* ppLayerSurfaceFound) {
for (auto& lsl : monitor->m_aLayerSurfaceLayers | std::views::reverse) { for (auto& lsl : monitor->m_aLayerSurfaceLayers | std::views::reverse) {
for (auto& ls : lsl | std::views::reverse) { for (auto& ls : lsl | std::views::reverse) {
if (ls->fadingOut || !ls->layerSurface || (ls->layerSurface && !ls->layerSurface->mapped) || ls->alpha.value() == 0.f) if (ls->fadingOut || !ls->layerSurface || (ls->layerSurface && !ls->layerSurface->mapped) || ls->alpha.value() == 0.f)
@ -1628,7 +1619,7 @@ bool CCompositor::isPointOnAnyMonitor(const Vector2D& point) {
return false; return false;
} }
bool CCompositor::isPointOnReservedArea(const Vector2D& point, const CMonitor* pMonitor) { bool CCompositor::isPointOnReservedArea(const Vector2D& point, const PHLMONITOR pMonitor) {
const auto PMONITOR = pMonitor ? pMonitor : getMonitorFromVector(point); const auto PMONITOR = pMonitor ? pMonitor : getMonitorFromVector(point);
const auto XY1 = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; const auto XY1 = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft;
@ -1637,11 +1628,11 @@ bool CCompositor::isPointOnReservedArea(const Vector2D& point, const CMonitor* p
return !VECINRECT(point, XY1.x, XY1.y, XY2.x, XY2.y); return !VECINRECT(point, XY1.x, XY1.y, XY2.x, XY2.y);
} }
CMonitor* CCompositor::getMonitorInDirection(const char& dir) { PHLMONITOR CCompositor::getMonitorInDirection(const char& dir) {
return this->getMonitorInDirection(m_pLastMonitor.get(), dir); return getMonitorInDirection(m_pLastMonitor.lock(), dir);
} }
CMonitor* CCompositor::getMonitorInDirection(CMonitor* pSourceMonitor, const char& dir) { PHLMONITOR CCompositor::getMonitorInDirection(PHLMONITOR pSourceMonitor, const char& dir) {
if (!pSourceMonitor) if (!pSourceMonitor)
return nullptr; return nullptr;
@ -1649,7 +1640,7 @@ CMonitor* CCompositor::getMonitorInDirection(CMonitor* pSourceMonitor, const cha
const auto SIZEA = pSourceMonitor->vecSize; const auto SIZEA = pSourceMonitor->vecSize;
auto longestIntersect = -1; auto longestIntersect = -1;
CMonitor* longestIntersectMonitor = nullptr; PHLMONITOR longestIntersectMonitor = nullptr;
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
if (m == m_pLastMonitor) if (m == m_pLastMonitor)
@ -1663,7 +1654,7 @@ CMonitor* CCompositor::getMonitorInDirection(CMonitor* pSourceMonitor, const cha
const auto INTERSECTLEN = std::max(0.0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y)); const auto INTERSECTLEN = std::max(0.0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
if (INTERSECTLEN > longestIntersect) { if (INTERSECTLEN > longestIntersect) {
longestIntersect = INTERSECTLEN; longestIntersect = INTERSECTLEN;
longestIntersectMonitor = m.get(); longestIntersectMonitor = m;
} }
} }
break; break;
@ -1672,7 +1663,7 @@ CMonitor* CCompositor::getMonitorInDirection(CMonitor* pSourceMonitor, const cha
const auto INTERSECTLEN = std::max(0.0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y)); const auto INTERSECTLEN = std::max(0.0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
if (INTERSECTLEN > longestIntersect) { if (INTERSECTLEN > longestIntersect) {
longestIntersect = INTERSECTLEN; longestIntersect = INTERSECTLEN;
longestIntersectMonitor = m.get(); longestIntersectMonitor = m;
} }
} }
break; break;
@ -1682,7 +1673,7 @@ CMonitor* CCompositor::getMonitorInDirection(CMonitor* pSourceMonitor, const cha
const auto INTERSECTLEN = std::max(0.0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x)); const auto INTERSECTLEN = std::max(0.0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
if (INTERSECTLEN > longestIntersect) { if (INTERSECTLEN > longestIntersect) {
longestIntersect = INTERSECTLEN; longestIntersect = INTERSECTLEN;
longestIntersectMonitor = m.get(); longestIntersectMonitor = m;
} }
} }
break; break;
@ -1692,7 +1683,7 @@ CMonitor* CCompositor::getMonitorInDirection(CMonitor* pSourceMonitor, const cha
const auto INTERSECTLEN = std::max(0.0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x)); const auto INTERSECTLEN = std::max(0.0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
if (INTERSECTLEN > longestIntersect) { if (INTERSECTLEN > longestIntersect) {
longestIntersect = INTERSECTLEN; longestIntersect = INTERSECTLEN;
longestIntersectMonitor = m.get(); longestIntersectMonitor = m;
} }
} }
break; break;
@ -1841,7 +1832,7 @@ int CCompositor::getNextAvailableMonitorID(std::string const& name) {
return nextID; return nextID;
} }
void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) { void CCompositor::swapActiveWorkspaces(PHLMONITOR pMonitorA, PHLMONITOR pMonitorB) {
const auto PWORKSPACEA = pMonitorA->activeWorkspace; const auto PWORKSPACEA = pMonitorA->activeWorkspace;
const auto PWORKSPACEB = pMonitorB->activeWorkspace; const auto PWORKSPACEB = pMonitorB->activeWorkspace;
@ -1928,16 +1919,16 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB)
EMIT_HOOK_EVENT("moveWorkspace", (std::vector<std::any>{PWORKSPACEB, pMonitorA})); EMIT_HOOK_EVENT("moveWorkspace", (std::vector<std::any>{PWORKSPACEB, pMonitorA}));
} }
CMonitor* CCompositor::getMonitorFromString(const std::string& name) { PHLMONITOR CCompositor::getMonitorFromString(const std::string& name) {
if (name == "current") if (name == "current")
return g_pCompositor->m_pLastMonitor.get(); return g_pCompositor->m_pLastMonitor.lock();
else if (isDirection(name)) else if (isDirection(name))
return getMonitorInDirection(name[0]); return getMonitorInDirection(name[0]);
else if (name[0] == '+' || name[0] == '-') { else if (name[0] == '+' || name[0] == '-') {
// relative // relative
if (m_vMonitors.size() == 1) if (m_vMonitors.size() == 1)
return m_vMonitors.begin()->get(); return *m_vMonitors.begin();
const auto OFFSET = name[0] == '-' ? name : name.substr(1); const auto OFFSET = name[0] == '-' ? name : name.substr(1);
@ -1970,7 +1961,7 @@ CMonitor* CCompositor::getMonitorFromString(const std::string& name) {
currentPlace = std::clamp(currentPlace, 0, (int)m_vMonitors.size() - 1); currentPlace = std::clamp(currentPlace, 0, (int)m_vMonitors.size() - 1);
} }
return m_vMonitors[currentPlace].get(); return m_vMonitors.at(currentPlace);
} else if (isNumber(name)) { } else if (isNumber(name)) {
// change by ID // change by ID
int monID = -1; int monID = -1;
@ -1994,7 +1985,7 @@ CMonitor* CCompositor::getMonitorFromString(const std::string& name) {
continue; continue;
if (m->matchesStaticSelector(name)) { if (m->matchesStaticSelector(name)) {
return m.get(); return m;
} }
} }
} }
@ -2002,7 +1993,7 @@ CMonitor* CCompositor::getMonitorFromString(const std::string& name) {
return nullptr; return nullptr;
} }
void CCompositor::moveWorkspaceToMonitor(PHLWORKSPACE pWorkspace, CMonitor* pMonitor, bool noWarpCursor) { void CCompositor::moveWorkspaceToMonitor(PHLWORKSPACE pWorkspace, PHLMONITOR pMonitor, bool noWarpCursor) {
// We trust the monitor to be correct. // We trust the monitor to be correct.
@ -2077,7 +2068,7 @@ void CCompositor::moveWorkspaceToMonitor(PHLWORKSPACE pWorkspace, CMonitor* pMon
} }
} }
if (SWITCHINGISACTIVE && POLDMON == g_pCompositor->m_pLastMonitor.get()) { // if it was active, preserve its' status. If it wasn't, don't. if (SWITCHINGISACTIVE && POLDMON == g_pCompositor->m_pLastMonitor.lock()) { // if it was active, preserve its' status. If it wasn't, don't.
Debug::log(LOG, "moveWorkspaceToMonitor: SWITCHINGISACTIVE, active {} -> {}", pMonitor->activeWorkspaceID(), pWorkspace->m_iID); Debug::log(LOG, "moveWorkspaceToMonitor: SWITCHINGISACTIVE, active {} -> {}", pMonitor->activeWorkspaceID(), pWorkspace->m_iID);
if (valid(pMonitor->activeWorkspace)) { if (valid(pMonitor->activeWorkspace)) {
@ -2245,11 +2236,11 @@ void CCompositor::updateWorkspaceSpecialRenderData(const int& id) {
} }
} }
void CCompositor::scheduleFrameForMonitor(CMonitor* pMonitor) { void CCompositor::scheduleFrameForMonitor(PHLMONITOR pMonitor) {
if ((m_sWLRSession && !m_sWLRSession->active) || !m_bSessionActive) if ((m_sWLRSession && !m_sWLRSession->active) || !m_bSessionActive)
return; return;
if (!pMonitor->m_bEnabled) if (!pMonitor->m_bEnabled || !pMonitor->output)
return; return;
if (pMonitor->renderingActive) if (pMonitor->renderingActive)
@ -2359,7 +2350,7 @@ void CCompositor::warpCursorTo(const Vector2D& pos, bool force) {
if (*PNOWARPS && !force) { if (*PNOWARPS && !force) {
const auto PMONITORNEW = getMonitorFromVector(pos); const auto PMONITORNEW = getMonitorFromVector(pos);
if (PMONITORNEW != m_pLastMonitor.get()) if (PMONITORNEW != m_pLastMonitor.lock())
setActiveMonitor(PMONITORNEW); setActiveMonitor(PMONITORNEW);
return; return;
} }
@ -2367,7 +2358,7 @@ void CCompositor::warpCursorTo(const Vector2D& pos, bool force) {
g_pPointerManager->warpTo(pos); g_pPointerManager->warpTo(pos);
const auto PMONITORNEW = getMonitorFromVector(pos); const auto PMONITORNEW = getMonitorFromVector(pos);
if (PMONITORNEW != m_pLastMonitor.get()) if (PMONITORNEW != m_pLastMonitor.lock())
setActiveMonitor(PMONITORNEW); setActiveMonitor(PMONITORNEW);
} }
@ -2494,8 +2485,8 @@ void CCompositor::renameWorkspace(const int& id, const std::string& name) {
g_pEventManager->postEvent({"renameworkspace", std::to_string(PWORKSPACE->m_iID) + "," + PWORKSPACE->m_szName}); g_pEventManager->postEvent({"renameworkspace", std::to_string(PWORKSPACE->m_iID) + "," + PWORKSPACE->m_szName});
} }
void CCompositor::setActiveMonitor(CMonitor* pMonitor) { void CCompositor::setActiveMonitor(PHLMONITOR pMonitor) {
if (m_pLastMonitor.get() == pMonitor) if (m_pLastMonitor == pMonitor)
return; return;
if (!pMonitor) { if (!pMonitor) {
@ -2596,11 +2587,11 @@ PHLWINDOW CCompositor::getForceFocus() {
void CCompositor::arrangeMonitors() { void CCompositor::arrangeMonitors() {
static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling");
std::vector<CMonitor*> toArrange; std::vector<PHLMONITOR> toArrange;
std::vector<CMonitor*> arranged; std::vector<PHLMONITOR> arranged;
for (auto& m : m_vMonitors) for (auto& m : m_vMonitors)
toArrange.push_back(m.get()); toArrange.push_back(m);
Debug::log(LOG, "arrangeMonitors: {} to arrange", toArrange.size()); Debug::log(LOG, "arrangeMonitors: {} to arrange", toArrange.size());
@ -2697,7 +2688,7 @@ void CCompositor::enterUnsafeState() {
m_bUnsafeState = true; m_bUnsafeState = true;
setActiveMonitor(m_pUnsafeOutput); setActiveMonitor(m_pUnsafeOutput.lock());
} }
void CCompositor::leaveUnsafeState() { void CCompositor::leaveUnsafeState() {
@ -2708,10 +2699,10 @@ void CCompositor::leaveUnsafeState() {
m_bUnsafeState = false; m_bUnsafeState = false;
CMonitor* pNewMonitor = nullptr; PHLMONITOR pNewMonitor = nullptr;
for (auto& pMonitor : m_vMonitors) { for (auto& pMonitor : m_vMonitors) {
if (pMonitor->output != m_pUnsafeOutput->output) { if (pMonitor->output != m_pUnsafeOutput->output) {
pNewMonitor = pMonitor.get(); pNewMonitor = pMonitor;
break; break;
} }
} }
@ -2722,7 +2713,7 @@ void CCompositor::leaveUnsafeState() {
m_pUnsafeOutput->onDisconnect(); m_pUnsafeOutput->onDisconnect();
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
scheduleFrameForMonitor(m.get()); scheduleFrameForMonitor(m);
} }
} }

View file

@ -66,8 +66,8 @@ class CCompositor {
std::string m_szInstancePath = ""; std::string m_szInstancePath = "";
std::string m_szCurrentSplash = "error"; std::string m_szCurrentSplash = "error";
std::vector<SP<CMonitor>> m_vMonitors; std::vector<PHLMONITOR> m_vMonitors;
std::vector<SP<CMonitor>> m_vRealMonitors; // for all monitors, even those turned off std::vector<PHLMONITOR> m_vRealMonitors; // for all monitors, even those turned off
std::vector<PHLWINDOW> m_vWindows; std::vector<PHLWINDOW> m_vWindows;
std::vector<PHLLS> m_vLayers; std::vector<PHLLS> m_vLayers;
std::vector<PHLWORKSPACE> m_vWorkspaces; std::vector<PHLWORKSPACE> m_vWorkspaces;
@ -84,7 +84,7 @@ class CCompositor {
WP<CWLSurfaceResource> m_pLastFocus; WP<CWLSurfaceResource> m_pLastFocus;
PHLWINDOWREF m_pLastWindow; PHLWINDOWREF m_pLastWindow;
WP<CMonitor> m_pLastMonitor; PHLMONITORREF m_pLastMonitor;
std::vector<PHLWINDOWREF> m_vWindowFocusHistory; // first element is the most recently focused. std::vector<PHLWINDOWREF> m_vWindowFocusHistory; // first element is the most recently focused.
@ -93,28 +93,27 @@ class CCompositor {
bool m_bDPMSStateON = true; bool m_bDPMSStateON = true;
bool m_bUnsafeState = false; // unsafe state is when there is no monitors. bool m_bUnsafeState = false; // unsafe state is when there is no monitors.
bool m_bNextIsUnsafe = false; // because wlroots bool m_bNextIsUnsafe = false; // because wlroots
CMonitor* m_pUnsafeOutput = nullptr; // fallback output for the unsafe state PHLMONITORREF m_pUnsafeOutput; // fallback output for the unsafe state
bool m_bExitTriggered = false; // For exit dispatcher bool m_bExitTriggered = false; // For exit dispatcher
bool m_bIsShuttingDown = false; bool m_bIsShuttingDown = false;
// ------------------------------------------------- // // ------------------------------------------------- //
CMonitor* getMonitorFromID(const int&); PHLMONITOR getMonitorFromID(const int&);
CMonitor* getMonitorFromName(const std::string&); PHLMONITOR getMonitorFromName(const std::string&);
CMonitor* getMonitorFromDesc(const std::string&); PHLMONITOR getMonitorFromDesc(const std::string&);
CMonitor* getMonitorFromCursor(); PHLMONITOR getMonitorFromCursor();
CMonitor* getMonitorFromVector(const Vector2D&); PHLMONITOR getMonitorFromVector(const Vector2D&);
void removeWindowFromVectorSafe(PHLWINDOW); void removeWindowFromVectorSafe(PHLWINDOW);
void focusWindow(PHLWINDOW, SP<CWLSurfaceResource> pSurface = nullptr); void focusWindow(PHLWINDOW, SP<CWLSurfaceResource> pSurface = nullptr);
void focusSurface(SP<CWLSurfaceResource>, PHLWINDOW pWindowOwner = nullptr); void focusSurface(SP<CWLSurfaceResource>, PHLWINDOW pWindowOwner = nullptr);
bool monitorExists(CMonitor*);
PHLWINDOW vectorToWindowUnified(const Vector2D&, uint8_t properties, PHLWINDOW pIgnoreWindow = nullptr); PHLWINDOW vectorToWindowUnified(const Vector2D&, uint8_t properties, PHLWINDOW pIgnoreWindow = nullptr);
SP<CWLSurfaceResource> vectorToLayerSurface(const Vector2D&, std::vector<PHLLSREF>*, Vector2D*, PHLLS*); SP<CWLSurfaceResource> vectorToLayerSurface(const Vector2D&, std::vector<PHLLSREF>*, Vector2D*, PHLLS*);
SP<CWLSurfaceResource> vectorToLayerPopupSurface(const Vector2D&, CMonitor* monitor, Vector2D*, PHLLS*); SP<CWLSurfaceResource> vectorToLayerPopupSurface(const Vector2D&, PHLMONITOR monitor, Vector2D*, PHLLS*);
SP<CWLSurfaceResource> vectorWindowToSurface(const Vector2D&, PHLWINDOW, Vector2D& sl); SP<CWLSurfaceResource> vectorWindowToSurface(const Vector2D&, PHLWINDOW, Vector2D& sl);
Vector2D vectorToSurfaceLocal(const Vector2D&, PHLWINDOW, SP<CWLSurfaceResource>); Vector2D vectorToSurfaceLocal(const Vector2D&, PHLWINDOW, SP<CWLSurfaceResource>);
CMonitor* getMonitorFromOutput(wlr_output*); PHLMONITOR getMonitorFromOutput(wlr_output*);
CMonitor* getRealMonitorFromOutput(wlr_output*); PHLMONITOR getRealMonitorFromOutput(wlr_output*);
PHLWINDOW getWindowFromSurface(SP<CWLSurfaceResource>); PHLWINDOW getWindowFromSurface(SP<CWLSurfaceResource>);
PHLWINDOW getWindowFromHandle(uint32_t); PHLWINDOW getWindowFromHandle(uint32_t);
bool isWorkspaceVisible(PHLWORKSPACE); bool isWorkspaceVisible(PHLWORKSPACE);
@ -140,21 +139,21 @@ class CCompositor {
PHLWINDOW getPrevWindowOnWorkspace(PHLWINDOW, bool focusableOnly = false, std::optional<bool> floating = {}); PHLWINDOW getPrevWindowOnWorkspace(PHLWINDOW, bool focusableOnly = false, std::optional<bool> floating = {});
int getNextAvailableNamedWorkspace(); int getNextAvailableNamedWorkspace();
bool isPointOnAnyMonitor(const Vector2D&); bool isPointOnAnyMonitor(const Vector2D&);
bool isPointOnReservedArea(const Vector2D& point, const CMonitor* monitor = nullptr); bool isPointOnReservedArea(const Vector2D& point, const PHLMONITOR monitor = nullptr);
CMonitor* getMonitorInDirection(const char&); PHLMONITOR getMonitorInDirection(const char&);
CMonitor* getMonitorInDirection(CMonitor*, const char&); PHLMONITOR getMonitorInDirection(PHLMONITOR, const char&);
void updateAllWindowsAnimatedDecorationValues(); void updateAllWindowsAnimatedDecorationValues();
void updateWorkspaceWindows(const int64_t& id); void updateWorkspaceWindows(const int64_t& id);
void updateWindowAnimatedDecorationValues(PHLWINDOW); void updateWindowAnimatedDecorationValues(PHLWINDOW);
int getNextAvailableMonitorID(std::string const& name); int getNextAvailableMonitorID(std::string const& name);
void moveWorkspaceToMonitor(PHLWORKSPACE, CMonitor*, bool noWarpCursor = false); void moveWorkspaceToMonitor(PHLWORKSPACE, PHLMONITOR, bool noWarpCursor = false);
void swapActiveWorkspaces(CMonitor*, CMonitor*); void swapActiveWorkspaces(PHLMONITOR, PHLMONITOR);
CMonitor* getMonitorFromString(const std::string&); PHLMONITOR getMonitorFromString(const std::string&);
bool workspaceIDOutOfBounds(const int64_t&); bool workspaceIDOutOfBounds(const int64_t&);
void setWindowFullscreen(PHLWINDOW, bool, eFullscreenMode mode = FULLSCREEN_INVALID); void setWindowFullscreen(PHLWINDOW, bool, eFullscreenMode mode = FULLSCREEN_INVALID);
void updateFullscreenFadeOnWorkspace(PHLWORKSPACE); void updateFullscreenFadeOnWorkspace(PHLWORKSPACE);
PHLWINDOW getX11Parent(PHLWINDOW); PHLWINDOW getX11Parent(PHLWINDOW);
void scheduleFrameForMonitor(CMonitor*); void scheduleFrameForMonitor(PHLMONITOR);
void addToFadingOutSafe(PHLLS); void addToFadingOutSafe(PHLLS);
void removeFromFadingOutSafe(PHLLS); void removeFromFadingOutSafe(PHLLS);
void addToFadingOutSafe(PHLWINDOW); void addToFadingOutSafe(PHLWINDOW);
@ -166,7 +165,7 @@ class CCompositor {
void forceReportSizesToWindowsOnWorkspace(const int&); void forceReportSizesToWindowsOnWorkspace(const int&);
PHLWORKSPACE createNewWorkspace(const int&, const int&, const std::string& name = "", bool isEmtpy = true); // will be deleted next frame if left empty and unfocused! PHLWORKSPACE createNewWorkspace(const int&, const int&, const std::string& name = "", bool isEmtpy = true); // will be deleted next frame if left empty and unfocused!
void renameWorkspace(const int&, const std::string& name = ""); void renameWorkspace(const int&, const std::string& name = "");
void setActiveMonitor(CMonitor*); void setActiveMonitor(PHLMONITOR);
bool isWorkspaceSpecial(const int&); bool isWorkspaceSpecial(const int&);
int getNewSpecialID(); int getNewSpecialID();
void performUserChecks(); void performUserChecks();

View file

@ -861,9 +861,9 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
// mark blur dirty // mark blur dirty
g_pHyprOpenGL->markBlurDirtyForMonitor(m.get()); g_pHyprOpenGL->markBlurDirtyForMonitor(m);
g_pCompositor->scheduleFrameForMonitor(m.get()); g_pCompositor->scheduleFrameForMonitor(m);
// Force the compositor to fully re-render all monitors // Force the compositor to fully re-render all monitors
m->forceFullFrames = 2; m->forceFullFrames = 2;
@ -1326,7 +1326,7 @@ void CConfigManager::performMonitorReload() {
auto rule = getMonitorRuleFor(*m); auto rule = getMonitorRuleFor(*m);
if (!g_pHyprRenderer->applyMonitorRule(m.get(), &rule)) { if (!g_pHyprRenderer->applyMonitorRule(m, &rule)) {
overAgain = true; overAgain = true;
break; break;
} }
@ -1384,14 +1384,14 @@ void CConfigManager::ensureMonitorStatus() {
auto rule = getMonitorRuleFor(*rm); auto rule = getMonitorRuleFor(*rm);
if (rule.disabled == rm->m_bEnabled) if (rule.disabled == rm->m_bEnabled)
g_pHyprRenderer->applyMonitorRule(rm.get(), &rule); g_pHyprRenderer->applyMonitorRule(rm, &rule);
} }
} }
void CConfigManager::ensureVRR(CMonitor* pMonitor) { void CConfigManager::ensureVRR(PHLMONITOR pMonitor) {
static auto PVRR = reinterpret_cast<Hyprlang::INT* const*>(getConfigValuePtr("misc:vrr")); static auto PVRR = reinterpret_cast<Hyprlang::INT* const*>(getConfigValuePtr("misc:vrr"));
static auto ensureVRRForDisplay = [&](CMonitor* m) -> void { static auto ensureVRRForDisplay = [&](PHLMONITOR m) -> void {
if (!m->output || m->createdByUser) if (!m->output || m->createdByUser)
return; return;
@ -1457,7 +1457,7 @@ void CConfigManager::ensureVRR(CMonitor* pMonitor) {
} }
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
ensureVRRForDisplay(m.get()); ensureVRRForDisplay(m);
} }
} }
@ -1469,7 +1469,7 @@ void CConfigManager::addParseError(const std::string& err) {
g_pHyprError->queueCreate(err + "\nHyprland may not work correctly.", CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); g_pHyprError->queueCreate(err + "\nHyprland may not work correctly.", CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0));
} }
CMonitor* CConfigManager::getBoundMonitorForWS(const std::string& wsname) { PHLMONITOR CConfigManager::getBoundMonitorForWS(const std::string& wsname) {
auto monitor = getBoundMonitorStringForWS(wsname); auto monitor = getBoundMonitorStringForWS(wsname);
if (monitor.substr(0, 5) == "desc:") if (monitor.substr(0, 5) == "desc:")
return g_pCompositor->getMonitorFromDesc(monitor.substr(5)); return g_pCompositor->getMonitorFromDesc(monitor.substr(5));

View file

@ -109,7 +109,7 @@ class CConfigManager {
SWorkspaceRule getWorkspaceRuleFor(PHLWORKSPACE workspace); SWorkspaceRule getWorkspaceRuleFor(PHLWORKSPACE workspace);
std::string getDefaultWorkspaceFor(const std::string&); std::string getDefaultWorkspaceFor(const std::string&);
CMonitor* getBoundMonitorForWS(const std::string&); PHLMONITOR getBoundMonitorForWS(const std::string&);
std::string getBoundMonitorStringForWS(const std::string&); std::string getBoundMonitorStringForWS(const std::string&);
const std::deque<SWorkspaceRule>& getAllWorkspaceRules(); const std::deque<SWorkspaceRule>& getAllWorkspaceRules();
@ -134,7 +134,7 @@ class CConfigManager {
bool m_bForceReload = false; bool m_bForceReload = false;
bool m_bNoMonitorReload = false; bool m_bNoMonitorReload = false;
void ensureMonitorStatus(); void ensureMonitorStatus();
void ensureVRR(CMonitor* pMonitor = nullptr); void ensureVRR(PHLMONITOR pMonitor = nullptr);
std::string parseKeyword(const std::string&, const std::string&); std::string parseKeyword(const std::string&, const std::string&);

View file

@ -48,9 +48,12 @@ static std::string formatToString(uint32_t drmFormat) {
return "Invalid"; return "Invalid";
} }
static std::string availableModesForOutput(CMonitor* pMonitor, eHyprCtlOutputFormat format) { static std::string availableModesForOutput(PHLMONITOR pMonitor, eHyprCtlOutputFormat format) {
std::string result; std::string result;
if (!pMonitor || !pMonitor->output)
return "";
if (!wl_list_empty(&pMonitor->output->modes)) { if (!wl_list_empty(&pMonitor->output->modes)) {
wlr_output_mode* mode; wlr_output_mode* mode;
@ -125,7 +128,7 @@ std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) {
escapeJSONStrings(m->activeSpecialWorkspace ? m->activeSpecialWorkspace->m_szName : ""), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, escapeJSONStrings(m->activeSpecialWorkspace ? m->activeSpecialWorkspace->m_szName : ""), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y,
(int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m == g_pCompositor->m_pLastMonitor ? "true" : "false"), (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m == g_pCompositor->m_pLastMonitor ? "true" : "false"),
(m->dpmsStatus ? "true" : "false"), (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false"), (m->dpmsStatus ? "true" : "false"), (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false"),
(m->tearingState.activelyTearing ? "true" : "false"), (m->m_bEnabled ? "false" : "true"), formatToString(m->drmFormat), availableModesForOutput(m.get(), format)); (m->tearingState.activelyTearing ? "true" : "false"), (m->m_bEnabled ? "false" : "true"), formatToString(m->drmFormat), availableModesForOutput(m, format));
} }
trimTrailingComma(result); trimTrailingComma(result);
@ -145,7 +148,7 @@ std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) {
(!m->activeWorkspace ? "" : m->activeWorkspace->m_szName), m->activeSpecialWorkspaceID(), (m->activeSpecialWorkspace ? m->activeSpecialWorkspace->m_szName : ""), (!m->activeWorkspace ? "" : m->activeWorkspace->m_szName), m->activeSpecialWorkspaceID(), (m->activeSpecialWorkspace ? m->activeSpecialWorkspace->m_szName : ""),
(int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform,
(m == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus, (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED), (m == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus, (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED),
m->tearingState.activelyTearing, !m->m_bEnabled, formatToString(m->drmFormat), availableModesForOutput(m.get(), format)); m->tearingState.activelyTearing, !m->m_bEnabled, formatToString(m->drmFormat), availableModesForOutput(m, format));
} }
} }
@ -542,7 +545,7 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {
"name": "{}", "name": "{}",
"defaultSpeed": {:.5f} "defaultSpeed": {:.5f}
}},)#", }},)#",
(uintptr_t)m.get(), escapeJSONStrings(m->hlName), (uintptr_t)m, escapeJSONStrings(m->hlName),
wlr_input_device_is_libinput(&m->wlr()->base) ? libinput_device_config_accel_get_default_speed((libinput_device*)wlr_libinput_get_device_handle(&m->wlr()->base)) : wlr_input_device_is_libinput(&m->wlr()->base) ? libinput_device_config_accel_get_default_speed((libinput_device*)wlr_libinput_get_device_handle(&m->wlr()->base)) :
0.f); 0.f);
} }
@ -644,7 +647,7 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {
result += "mice:\n"; result += "mice:\n";
for (auto& m : g_pInputManager->m_vPointers) { for (auto& m : g_pInputManager->m_vPointers) {
result += std::format("\tMouse at {:x}:\n\t\t{}\n\t\t\tdefault speed: {:.5f}\n", (uintptr_t)m.get(), m->hlName, result += std::format("\tMouse at {:x}:\n\t\t{}\n\t\t\tdefault speed: {:.5f}\n", (uintptr_t)m, m->hlName,
(wlr_input_device_is_libinput(&m->wlr()->base) ? (wlr_input_device_is_libinput(&m->wlr()->base) ?
libinput_device_config_accel_get_default_speed((libinput_device*)wlr_libinput_get_device_handle(&m->wlr()->base)) : libinput_device_config_accel_get_default_speed((libinput_device*)wlr_libinput_get_device_handle(&m->wlr()->base)) :
0.f)); 0.f));
@ -986,7 +989,7 @@ std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) {
// decorations will probably need a repaint // decorations will probably need a repaint
if (COMMAND.contains("decoration:") || COMMAND.contains("border") || COMMAND == "workspace" || COMMAND.contains("zoom_factor") || COMMAND == "source") { if (COMMAND.contains("decoration:") || COMMAND.contains("border") || COMMAND == "workspace" || COMMAND.contains("zoom_factor") || COMMAND == "source") {
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
g_pHyprRenderer->damageMonitor(m.get()); g_pHyprRenderer->damageMonitor(m);
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
} }
} }
@ -1720,7 +1723,7 @@ std::string CHyprCtl::getReply(std::string request) {
} }
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
g_pHyprRenderer->damageMonitor(m.get()); g_pHyprRenderer->damageMonitor(m);
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
} }
} }

View file

@ -7,7 +7,7 @@ CHyprDebugOverlay::CHyprDebugOverlay() {
m_pTexture = makeShared<CTexture>(); m_pTexture = makeShared<CTexture>();
} }
void CHyprMonitorDebugOverlay::renderData(CMonitor* pMonitor, float µs) { void CHyprMonitorDebugOverlay::renderData(PHLMONITOR pMonitor, float µs) {
m_dLastRenderTimes.push_back(µs / 1000.f); m_dLastRenderTimes.push_back(µs / 1000.f);
if (m_dLastRenderTimes.size() > (long unsigned int)pMonitor->refreshRate) if (m_dLastRenderTimes.size() > (long unsigned int)pMonitor->refreshRate)
@ -17,7 +17,7 @@ void CHyprMonitorDebugOverlay::renderData(CMonitor* pMonitor, float µs) {
m_pMonitor = pMonitor; m_pMonitor = pMonitor;
} }
void CHyprMonitorDebugOverlay::renderDataNoOverlay(CMonitor* pMonitor, float µs) { void CHyprMonitorDebugOverlay::renderDataNoOverlay(PHLMONITOR pMonitor, float µs) {
m_dLastRenderTimesNoOverlay.push_back(µs / 1000.f); m_dLastRenderTimesNoOverlay.push_back(µs / 1000.f);
if (m_dLastRenderTimesNoOverlay.size() > (long unsigned int)pMonitor->refreshRate) if (m_dLastRenderTimesNoOverlay.size() > (long unsigned int)pMonitor->refreshRate)
@ -27,7 +27,7 @@ void CHyprMonitorDebugOverlay::renderDataNoOverlay(CMonitor* pMonitor, float µs
m_pMonitor = pMonitor; m_pMonitor = pMonitor;
} }
void CHyprMonitorDebugOverlay::frameData(CMonitor* pMonitor) { void CHyprMonitorDebugOverlay::frameData(PHLMONITOR pMonitor) {
m_dLastFrametimes.push_back(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - m_tpLastFrame).count() / 1000.f); m_dLastFrametimes.push_back(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - m_tpLastFrame).count() / 1000.f);
if (m_dLastFrametimes.size() > (long unsigned int)pMonitor->refreshRate) if (m_dLastFrametimes.size() > (long unsigned int)pMonitor->refreshRate)
@ -39,7 +39,7 @@ void CHyprMonitorDebugOverlay::frameData(CMonitor* pMonitor) {
m_pMonitor = pMonitor; m_pMonitor = pMonitor;
// anim data too // anim data too
const auto PMONITORFORTICKS = g_pHyprRenderer->m_pMostHzMonitor ? g_pHyprRenderer->m_pMostHzMonitor : g_pCompositor->m_pLastMonitor.get(); const auto PMONITORFORTICKS = g_pHyprRenderer->m_pMostHzMonitor ? g_pHyprRenderer->m_pMostHzMonitor : g_pCompositor->m_pLastMonitor;
if (PMONITORFORTICKS) { if (PMONITORFORTICKS) {
if (m_dLastAnimationTicks.size() > (long unsigned int)PMONITORFORTICKS->refreshRate) if (m_dLastAnimationTicks.size() > (long unsigned int)PMONITORFORTICKS->refreshRate)
m_dLastAnimationTicks.pop_front(); m_dLastAnimationTicks.pop_front();
@ -188,15 +188,15 @@ int CHyprMonitorDebugOverlay::draw(int offset) {
return posY - offset; return posY - offset;
} }
void CHyprDebugOverlay::renderData(CMonitor* pMonitor, float µs) { void CHyprDebugOverlay::renderData(PHLMONITOR pMonitor, float µs) {
m_mMonitorOverlays[pMonitor].renderData(pMonitor, µs); m_mMonitorOverlays[pMonitor].renderData(pMonitor, µs);
} }
void CHyprDebugOverlay::renderDataNoOverlay(CMonitor* pMonitor, float µs) { void CHyprDebugOverlay::renderDataNoOverlay(PHLMONITOR pMonitor, float µs) {
m_mMonitorOverlays[pMonitor].renderDataNoOverlay(pMonitor, µs); m_mMonitorOverlays[pMonitor].renderDataNoOverlay(pMonitor, µs);
} }
void CHyprDebugOverlay::frameData(CMonitor* pMonitor) { void CHyprDebugOverlay::frameData(PHLMONITOR pMonitor) {
m_mMonitorOverlays[pMonitor].frameData(pMonitor); m_mMonitorOverlays[pMonitor].frameData(pMonitor);
} }
@ -218,7 +218,7 @@ void CHyprDebugOverlay::draw() {
// draw the things // draw the things
int offsetY = 0; int offsetY = 0;
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
offsetY += m_mMonitorOverlays[m.get()].draw(offsetY); offsetY += m_mMonitorOverlays[m].draw(offsetY);
offsetY += 5; // for padding between mons offsetY += 5; // for padding between mons
} }

View file

@ -13,9 +13,9 @@ class CHyprMonitorDebugOverlay {
public: public:
int draw(int offset); int draw(int offset);
void renderData(CMonitor* pMonitor, float µs); void renderData(PHLMONITOR pMonitor, float µs);
void renderDataNoOverlay(CMonitor* pMonitor, float µs); void renderDataNoOverlay(PHLMONITOR pMonitor, float µs);
void frameData(CMonitor* pMonitor); void frameData(PHLMONITOR pMonitor);
private: private:
std::deque<float> m_dLastFrametimes; std::deque<float> m_dLastFrametimes;
@ -23,7 +23,7 @@ class CHyprMonitorDebugOverlay {
std::deque<float> m_dLastRenderTimesNoOverlay; std::deque<float> m_dLastRenderTimesNoOverlay;
std::deque<float> m_dLastAnimationTicks; std::deque<float> m_dLastAnimationTicks;
std::chrono::high_resolution_clock::time_point m_tpLastFrame; std::chrono::high_resolution_clock::time_point m_tpLastFrame;
CMonitor* m_pMonitor = nullptr; PHLMONITORREF m_pMonitor;
CBox m_wbLastDrawnBox; CBox m_wbLastDrawnBox;
friend class CHyprRenderer; friend class CHyprRenderer;
@ -33,12 +33,12 @@ class CHyprDebugOverlay {
public: public:
CHyprDebugOverlay(); CHyprDebugOverlay();
void draw(); void draw();
void renderData(CMonitor*, float µs); void renderData(PHLMONITOR, float µs);
void renderDataNoOverlay(CMonitor*, float µs); void renderDataNoOverlay(PHLMONITOR, float µs);
void frameData(CMonitor*); void frameData(PHLMONITOR);
private: private:
std::unordered_map<CMonitor*, CHyprMonitorDebugOverlay> m_mMonitorOverlays; std::unordered_map<PHLMONITOR, CHyprMonitorDebugOverlay> m_mMonitorOverlays;
cairo_surface_t* m_pCairoSurface = nullptr; cairo_surface_t* m_pCairoSurface = nullptr;
cairo_t* m_pCairo = nullptr; cairo_t* m_pCairo = nullptr;

View file

@ -45,7 +45,7 @@ void CHyprNotificationOverlay::addNotification(const std::string& text, const CC
PNOTIF->fontSize = fontSize; PNOTIF->fontSize = fontSize;
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
g_pCompositor->scheduleFrameForMonitor(m.get()); g_pCompositor->scheduleFrameForMonitor(m);
} }
} }
@ -61,7 +61,7 @@ void CHyprNotificationOverlay::dismissNotifications(const int amount) {
} }
} }
CBox CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) { CBox CHyprNotificationOverlay::drawNotifications(PHLMONITOR pMonitor) {
static constexpr auto ANIM_DURATION_MS = 600.0; static constexpr auto ANIM_DURATION_MS = 600.0;
static constexpr auto ANIM_LAG_MS = 100.0; static constexpr auto ANIM_LAG_MS = 100.0;
static constexpr auto NOTIF_LEFTBAR_SIZE = 5.0; static constexpr auto NOTIF_LEFTBAR_SIZE = 5.0;
@ -187,7 +187,7 @@ CBox CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) {
return CBox{(int)(pMonitor->vecPosition.x + pMonitor->vecSize.x - maxWidth - 20), (int)pMonitor->vecPosition.y, (int)maxWidth + 20, (int)offsetY + 10}; return CBox{(int)(pMonitor->vecPosition.x + pMonitor->vecSize.x - maxWidth - 20), (int)pMonitor->vecPosition.y, (int)maxWidth + 20, (int)offsetY + 10};
} }
void CHyprNotificationOverlay::draw(CMonitor* pMonitor) { void CHyprNotificationOverlay::draw(PHLMONITOR pMonitor) {
const auto MONSIZE = pMonitor->vecTransformedSize; const auto MONSIZE = pMonitor->vecTransformedSize;

View file

@ -41,13 +41,13 @@ class CHyprNotificationOverlay {
CHyprNotificationOverlay(); CHyprNotificationOverlay();
~CHyprNotificationOverlay(); ~CHyprNotificationOverlay();
void draw(CMonitor* pMonitor); void draw(PHLMONITOR pMonitor);
void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE, const float fontSize = 13.f); void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE, const float fontSize = 13.f);
void dismissNotifications(const int amount); void dismissNotifications(const int amount);
bool hasAny(); bool hasAny();
private: private:
CBox drawNotifications(CMonitor* pMonitor); CBox drawNotifications(PHLMONITOR pMonitor);
CBox m_bLastDamage; CBox m_bLastDamage;
std::deque<std::unique_ptr<SNotification>> m_dNotifications; std::deque<std::unique_ptr<SNotification>> m_dNotifications;
@ -55,7 +55,7 @@ class CHyprNotificationOverlay {
cairo_surface_t* m_pCairoSurface = nullptr; cairo_surface_t* m_pCairoSurface = nullptr;
cairo_t* m_pCairo = nullptr; cairo_t* m_pCairo = nullptr;
CMonitor* m_pLastMonitor = nullptr; PHLMONITORREF m_pLastMonitor;
Vector2D m_vecLastSize = Vector2D(-1, -1); Vector2D m_vecLastSize = Vector2D(-1, -1);
SP<CTexture> m_pTexture; SP<CTexture> m_pTexture;

View file

@ -3,6 +3,7 @@
class CWorkspace; class CWorkspace;
class CWindow; class CWindow;
class CLayerSurface; class CLayerSurface;
class CMonitor;
/* Shared pointer to a workspace */ /* Shared pointer to a workspace */
typedef SP<CWorkspace> PHLWORKSPACE; typedef SP<CWorkspace> PHLWORKSPACE;
@ -18,3 +19,8 @@ typedef WP<CWindow> PHLWINDOWREF;
typedef SP<CLayerSurface> PHLLS; typedef SP<CLayerSurface> PHLLS;
/* Weak pointer to a layer surface */ /* Weak pointer to a layer surface */
typedef WP<CLayerSurface> PHLLSREF; typedef WP<CLayerSurface> PHLLSREF;
/* Shared pointer to a monitor */
typedef SP<CMonitor> PHLMONITOR;
/* Weak pointer to a monitor */
typedef WP<CMonitor> PHLMONITORREF;

View file

@ -8,7 +8,7 @@
PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) { PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
PHLLS pLS = SP<CLayerSurface>(new CLayerSurface(resource)); PHLLS pLS = SP<CLayerSurface>(new CLayerSurface(resource));
CMonitor* pMonitor = resource->monitor.empty() ? g_pCompositor->getMonitorFromCursor() : g_pCompositor->getMonitorFromName(resource->monitor); PHLMONITOR pMonitor = resource->monitor.empty() ? g_pCompositor->getMonitorFromCursor() : g_pCompositor->getMonitorFromName(resource->monitor);
pLS->surface->assign(resource->surface.lock(), pLS); pLS->surface->assign(resource->surface.lock(), pLS);
@ -18,7 +18,7 @@ PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
} }
if (pMonitor->pMirrorOf) if (pMonitor->pMirrorOf)
pMonitor = g_pCompositor->m_vMonitors.front().get(); pMonitor = g_pCompositor->m_vMonitors.front();
pLS->self = pLS; pLS->self = pLS;

View file

@ -1217,7 +1217,7 @@ void CWindow::setSuspended(bool suspend) {
m_bSuspended = suspend; m_bSuspended = suspend;
} }
bool CWindow::visibleOnMonitor(CMonitor* pMonitor) { bool CWindow::visibleOnMonitor(PHLMONITOR pMonitor) {
CBox wbox = {m_vRealPosition.value(), m_vRealSize.value()}; CBox wbox = {m_vRealPosition.value(), m_vRealSize.value()};
return !wbox.intersection({pMonitor->vecPosition, pMonitor->vecSize}).empty(); return !wbox.intersection({pMonitor->vecPosition, pMonitor->vecSize}).empty();

View file

@ -412,7 +412,7 @@ class CWindow {
bool canBeTorn(); bool canBeTorn();
bool shouldSendFullscreenState(); bool shouldSendFullscreenState();
void setSuspended(bool suspend); void setSuspended(bool suspend);
bool visibleOnMonitor(CMonitor* pMonitor); bool visibleOnMonitor(PHLMONITOR pMonitor);
int workspaceID(); int workspaceID();
bool onSpecialWorkspace(); bool onSpecialWorkspace();
void activate(bool force = false); void activate(bool force = false);

View file

@ -35,8 +35,8 @@ void Events::listener_sessionActive(wl_listener* listener, void* data) {
g_pCompositor->m_bSessionActive = true; g_pCompositor->m_bSessionActive = true;
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
g_pCompositor->scheduleFrameForMonitor(m.get()); g_pCompositor->scheduleFrameForMonitor(m);
g_pHyprRenderer->applyMonitorRule(m.get(), &m->activeMonitorRule, true); g_pHyprRenderer->applyMonitorRule(m, &m->activeMonitorRule, true);
} }
g_pConfigManager->m_bWantsMonitorReload = true; g_pConfigManager->m_bWantsMonitorReload = true;

View file

@ -16,7 +16,7 @@
// // // //
// --------------------------------------------------------- // // --------------------------------------------------------- //
static void checkDefaultCursorWarp(SP<CMonitor> PNEWMONITOR, std::string monitorName) { static void checkDefaultCursorWarp(PHLMONITOR PNEWMONITOR, std::string monitorName) {
static auto PCURSORMONITOR = CConfigValue<std::string>("cursor:default_monitor"); static auto PCURSORMONITOR = CConfigValue<std::string>("cursor:default_monitor");
static auto firstMonitorAdded = std::chrono::system_clock::now(); static auto firstMonitorAdded = std::chrono::system_clock::now();
@ -62,7 +62,7 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
// add it to real // add it to real
auto PNEWMONITOR = g_pCompositor->m_vRealMonitors.emplace_back(makeShared<CMonitor>()); auto PNEWMONITOR = g_pCompositor->m_vRealMonitors.emplace_back(makeShared<CMonitor>());
if (std::string("HEADLESS-1") == OUTPUT->name) if (std::string("HEADLESS-1") == OUTPUT->name)
g_pCompositor->m_pUnsafeOutput = PNEWMONITOR.get(); g_pCompositor->m_pUnsafeOutput = PNEWMONITOR;
PNEWMONITOR->output = OUTPUT; PNEWMONITOR->output = OUTPUT;
PNEWMONITOR->self = PNEWMONITOR; PNEWMONITOR->self = PNEWMONITOR;
@ -81,12 +81,12 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
// ready to process if we have a real monitor // ready to process if we have a real monitor
if ((!g_pHyprRenderer->m_pMostHzMonitor || PNEWMONITOR->refreshRate > g_pHyprRenderer->m_pMostHzMonitor->refreshRate) && PNEWMONITOR->m_bEnabled) if ((!g_pHyprRenderer->m_pMostHzMonitor || PNEWMONITOR->refreshRate > g_pHyprRenderer->m_pMostHzMonitor->refreshRate) && PNEWMONITOR->m_bEnabled)
g_pHyprRenderer->m_pMostHzMonitor = PNEWMONITOR.get(); g_pHyprRenderer->m_pMostHzMonitor = PNEWMONITOR;
g_pCompositor->m_bReadyToProcess = true; g_pCompositor->m_bReadyToProcess = true;
g_pConfigManager->m_bWantsMonitorReload = true; g_pConfigManager->m_bWantsMonitorReload = true;
g_pCompositor->scheduleFrameForMonitor(PNEWMONITOR.get()); g_pCompositor->scheduleFrameForMonitor(PNEWMONITOR);
checkDefaultCursorWarp(PNEWMONITOR, OUTPUT->name); checkDefaultCursorWarp(PNEWMONITOR, OUTPUT->name);
@ -97,148 +97,3 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
} }
} }
} }
void Events::listener_monitorFrame(void* owner, void* data) {
if (g_pCompositor->m_bExitTriggered) {
// Only signal cleanup once
g_pCompositor->m_bExitTriggered = false;
g_pCompositor->cleanup();
return;
}
CMonitor* const PMONITOR = (CMonitor*)owner;
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!");
if (g_pCompositor->m_bUnsafeState && std::ranges::any_of(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](auto& m) {
return m->output != g_pCompositor->m_pUnsafeOutput->output;
})) {
// restore from unsafe state
g_pCompositor->leaveUnsafeState();
}
return; // cannot draw on session inactive (different tty)
}
if (!PMONITOR->m_bEnabled)
return;
g_pHyprRenderer->recheckSolitaryForMonitor(PMONITOR);
PMONITOR->tearingState.busy = false;
if (PMONITOR->tearingState.activelyTearing && PMONITOR->solitaryClient.lock() /* can be invalidated by a recheck */) {
if (!PMONITOR->tearingState.frameScheduledWhileBusy)
return; // we did not schedule a frame yet to be displayed, but we are tearing. Why render?
PMONITOR->tearingState.nextRenderTorn = true;
PMONITOR->tearingState.frameScheduledWhileBusy = false;
}
static auto PENABLERAT = CConfigValue<Hyprlang::INT>("misc:render_ahead_of_time");
static auto PRATSAFE = CConfigValue<Hyprlang::INT>("misc:render_ahead_safezone");
PMONITOR->lastPresentationTimer.reset();
if (*PENABLERAT && !PMONITOR->tearingState.nextRenderTorn) {
if (!PMONITOR->RATScheduled) {
// render
g_pHyprRenderer->renderMonitor(PMONITOR);
}
PMONITOR->RATScheduled = false;
const auto& [avg, max, min] = g_pHyprRenderer->getRenderTimes(PMONITOR);
if (max + *PRATSAFE > 1000.0 / PMONITOR->refreshRate)
return;
const auto MSLEFT = 1000.0 / PMONITOR->refreshRate - PMONITOR->lastPresentationTimer.getMillis();
PMONITOR->RATScheduled = true;
const auto ESTRENDERTIME = std::ceil(avg + *PRATSAFE);
const auto TIMETOSLEEP = std::floor(MSLEFT - ESTRENDERTIME);
if (MSLEFT < 1 || MSLEFT < ESTRENDERTIME || TIMETOSLEEP < 1)
g_pHyprRenderer->renderMonitor(PMONITOR);
else
wl_event_source_timer_update(PMONITOR->renderTimer, TIMETOSLEEP);
} else {
g_pHyprRenderer->renderMonitor(PMONITOR);
}
}
void Events::listener_monitorDestroy(void* owner, void* data) {
const auto OUTPUT = (wlr_output*)data;
CMonitor* pMonitor = nullptr;
for (auto& m : g_pCompositor->m_vRealMonitors) {
if (m->output == OUTPUT) {
pMonitor = m.get();
break;
}
}
if (!pMonitor)
return;
Debug::log(LOG, "Destroy called for monitor {}", pMonitor->output->name);
pMonitor->onDisconnect(true);
pMonitor->output = nullptr;
pMonitor->m_bRenderingInitPassed = false;
Debug::log(LOG, "Removing monitor {} from realMonitors", pMonitor->szName);
std::erase_if(g_pCompositor->m_vRealMonitors, [&](SP<CMonitor>& el) { return el.get() == pMonitor; });
}
void Events::listener_monitorStateRequest(void* owner, void* data) {
const auto PMONITOR = (CMonitor*)owner;
const auto E = (wlr_output_event_request_state*)data;
if (!PMONITOR->createdByUser)
return;
const auto SIZE = E->state->mode ? Vector2D{E->state->mode->width, E->state->mode->height} : Vector2D{E->state->custom_mode.width, E->state->custom_mode.height};
PMONITOR->forceSize = SIZE;
SMonitorRule rule = PMONITOR->activeMonitorRule;
rule.resolution = SIZE;
g_pHyprRenderer->applyMonitorRule(PMONITOR, &rule);
}
void Events::listener_monitorDamage(void* owner, void* data) {
const auto PMONITOR = (CMonitor*)owner;
const auto E = (wlr_output_event_damage*)data;
PMONITOR->addDamage(E->damage);
}
void Events::listener_monitorNeedsFrame(void* owner, void* data) {
const auto PMONITOR = (CMonitor*)owner;
g_pCompositor->scheduleFrameForMonitor(PMONITOR);
}
void Events::listener_monitorCommit(void* owner, void* data) {
const auto PMONITOR = (CMonitor*)owner;
const auto E = (wlr_output_event_commit*)data;
if (E->state->committed & WLR_OUTPUT_STATE_BUFFER) {
g_pProtocolManager->m_pScreencopyProtocolManager->onOutputCommit(PMONITOR, E);
g_pProtocolManager->m_pToplevelExportProtocolManager->onOutputCommit(PMONITOR, E);
}
}
void Events::listener_monitorBind(void* owner, void* data) {
;
}

View file

@ -48,10 +48,10 @@ void Events::listener_mapWindow(void* owner, void* data) {
static auto PNEWTAKESOVERFS = CConfigValue<Hyprlang::INT>("misc:new_window_takes_over_fullscreen"); static auto PNEWTAKESOVERFS = CConfigValue<Hyprlang::INT>("misc:new_window_takes_over_fullscreen");
static auto PINITIALWSTRACKING = CConfigValue<Hyprlang::INT>("misc:initial_workspace_tracking"); static auto PINITIALWSTRACKING = CConfigValue<Hyprlang::INT>("misc:initial_workspace_tracking");
auto PMONITOR = g_pCompositor->m_pLastMonitor.get(); auto PMONITOR = g_pCompositor->m_pLastMonitor.lock();
if (!g_pCompositor->m_pLastMonitor) { if (!g_pCompositor->m_pLastMonitor) {
g_pCompositor->setActiveMonitor(g_pCompositor->getMonitorFromVector({})); g_pCompositor->setActiveMonitor(g_pCompositor->getMonitorFromVector({}));
PMONITOR = g_pCompositor->m_pLastMonitor.get(); PMONITOR = g_pCompositor->m_pLastMonitor.lock();
} }
auto PWORKSPACE = PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace : PMONITOR->activeWorkspace; auto PWORKSPACE = PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace : PMONITOR->activeWorkspace;
PWINDOW->m_iMonitorID = PMONITOR->ID; PWINDOW->m_iMonitorID = PMONITOR->ID;
@ -317,7 +317,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
else if (PMONITOR->activeWorkspaceID() != REQUESTEDWORKSPACEID) else if (PMONITOR->activeWorkspaceID() != REQUESTEDWORKSPACEID)
g_pKeybindManager->m_mDispatchers["workspace"](requestedWorkspaceName); g_pKeybindManager->m_mDispatchers["workspace"](requestedWorkspaceName);
PMONITOR = g_pCompositor->m_pLastMonitor.get(); PMONITOR = g_pCompositor->m_pLastMonitor.lock();
} }
} else } else
workspaceSilent = false; workspaceSilent = false;

View file

@ -10,7 +10,7 @@
using namespace Hyprutils::String; using namespace Hyprutils::String;
int ratHandler(void* data) { int ratHandler(void* data) {
g_pHyprRenderer->renderMonitor((CMonitor*)data); g_pHyprRenderer->renderMonitor(((CMonitor*)data)->self.lock());
return 1; return 1;
} }
@ -33,13 +33,6 @@ CMonitor::~CMonitor() {
events.destroy.emit(); events.destroy.emit();
} }
static void onPresented(void* owner, void* data) {
const auto PMONITOR = (CMonitor*)owner;
auto E = (wlr_output_event_present*)data;
PROTO::presentation->onPresented(PMONITOR, E->when, E->refresh, E->seq, E->flags);
}
void CMonitor::onConnect(bool noRule) { void CMonitor::onConnect(bool noRule) {
hyprListener_monitorDestroy.removeCallback(); hyprListener_monitorDestroy.removeCallback();
hyprListener_monitorFrame.removeCallback(); hyprListener_monitorFrame.removeCallback();
@ -49,14 +42,22 @@ void CMonitor::onConnect(bool noRule) {
hyprListener_monitorCommit.removeCallback(); hyprListener_monitorCommit.removeCallback();
hyprListener_monitorBind.removeCallback(); hyprListener_monitorBind.removeCallback();
hyprListener_monitorPresented.removeCallback(); hyprListener_monitorPresented.removeCallback();
hyprListener_monitorFrame.initCallback(&output->events.frame, &Events::listener_monitorFrame, this, "CMonitor"); hyprListener_monitorFrame.initCallback(
hyprListener_monitorDestroy.initCallback(&output->events.destroy, &Events::listener_monitorDestroy, this, "CMonitor"); &output->events.frame, [this](void* owner, void* data) { this->onFrame(data); }, this, "CMonitor");
hyprListener_monitorStateRequest.initCallback(&output->events.request_state, &Events::listener_monitorStateRequest, this, "CMonitor"); hyprListener_monitorDestroy.initCallback(
hyprListener_monitorDamage.initCallback(&output->events.damage, &Events::listener_monitorDamage, this, "CMonitor"); &output->events.destroy, [this](void* owner, void* data) { this->onDestroy(data); }, this, "CMonitor");
hyprListener_monitorNeedsFrame.initCallback(&output->events.needs_frame, &Events::listener_monitorNeedsFrame, this, "CMonitor"); hyprListener_monitorStateRequest.initCallback(
hyprListener_monitorCommit.initCallback(&output->events.commit, &Events::listener_monitorCommit, this, "CMonitor"); &output->events.request_state, [this](void* owner, void* data) { this->onStateRequest(data); }, this, "CMonitor");
hyprListener_monitorBind.initCallback(&output->events.bind, &Events::listener_monitorBind, this, "CMonitor"); hyprListener_monitorDamage.initCallback(
hyprListener_monitorPresented.initCallback(&output->events.present, ::onPresented, this, "CMonitor"); &output->events.damage, [this](void* owner, void* data) { this->onDamage(data); }, this, "CMonitor");
hyprListener_monitorNeedsFrame.initCallback(
&output->events.needs_frame, [this](void* owner, void* data) { this->onNeedsFrame(data); }, this, "CMonitor");
hyprListener_monitorCommit.initCallback(
&output->events.commit, [this](void* owner, void* data) { this->onCommit(data); }, this, "CMonitor");
hyprListener_monitorBind.initCallback(
&output->events.bind, [this](void* owner, void* data) { this->onBind(data); }, this, "CMonitor");
hyprListener_monitorPresented.initCallback(
&output->events.present, [this](void* owner, void* data) { this->onPresented(data); }, this, "CMonitor");
tearingState.canTear = wlr_backend_is_drm(output->backend); // tearing only works on drm tearingState.canTear = wlr_backend_is_drm(output->backend); // tearing only works on drm
@ -135,7 +136,7 @@ void CMonitor::onConnect(bool noRule) {
m_bRenderingInitPassed = true; m_bRenderingInitPassed = true;
} }
SP<CMonitor>* thisWrapper = nullptr; PHLMONITOR* thisWrapper = nullptr;
// find the wrap // find the wrap
for (auto& m : g_pCompositor->m_vRealMonitors) { for (auto& m : g_pCompositor->m_vRealMonitors) {
@ -156,7 +157,7 @@ void CMonitor::onConnect(bool noRule) {
// set mode, also applies // set mode, also applies
if (!noRule) if (!noRule)
g_pHyprRenderer->applyMonitorRule(this, &monitorRule, true); g_pHyprRenderer->applyMonitorRule(self.lock(), &monitorRule, true);
if (!state.commit()) if (!state.commit())
Debug::log(WARN, "wlr_output_commit_state failed in CMonitor::onCommit"); Debug::log(WARN, "wlr_output_commit_state failed in CMonitor::onCommit");
@ -172,7 +173,7 @@ void CMonitor::onConnect(bool noRule) {
continue; continue;
if (ws->m_szLastMonitor == szName || g_pCompositor->m_vMonitors.size() == 1 /* avoid lost workspaces on recover */) { if (ws->m_szLastMonitor == szName || g_pCompositor->m_vMonitors.size() == 1 /* avoid lost workspaces on recover */) {
g_pCompositor->moveWorkspaceToMonitor(ws, this); g_pCompositor->moveWorkspaceToMonitor(ws, self.lock());
ws->startAnim(true, true, true); ws->startAnim(true, true, true);
ws->m_szLastMonitor = ""; ws->m_szLastMonitor = "";
} }
@ -190,16 +191,16 @@ void CMonitor::onConnect(bool noRule) {
g_pEventManager->postEvent(SHyprIPCEvent{"monitoradded", szName}); g_pEventManager->postEvent(SHyprIPCEvent{"monitoradded", szName});
g_pEventManager->postEvent(SHyprIPCEvent{"monitoraddedv2", std::format("{},{},{}", ID, szName, szShortDescription)}); g_pEventManager->postEvent(SHyprIPCEvent{"monitoraddedv2", std::format("{},{},{}", ID, szName, szShortDescription)});
EMIT_HOOK_EVENT("monitorAdded", this); EMIT_HOOK_EVENT("monitorAdded", self.lock());
if (!g_pCompositor->m_pLastMonitor) // set the last monitor if it isnt set yet if (!g_pCompositor->m_pLastMonitor) // set the last monitor if it isnt set yet
g_pCompositor->setActiveMonitor(this); g_pCompositor->setActiveMonitor(self.lock());
g_pHyprRenderer->arrangeLayersForMonitor(ID); g_pHyprRenderer->arrangeLayersForMonitor(ID);
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID);
// ensure VRR (will enable if necessary) // ensure VRR (will enable if necessary)
g_pConfigManager->ensureVRR(this); g_pConfigManager->ensureVRR(self.lock());
// verify last mon valid // verify last mon valid
bool found = false; bool found = false;
@ -211,13 +212,13 @@ void CMonitor::onConnect(bool noRule) {
} }
if (!found) if (!found)
g_pCompositor->setActiveMonitor(this); g_pCompositor->setActiveMonitor(self.lock());
renderTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, ratHandler, this); renderTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, ratHandler, this);
g_pCompositor->scheduleFrameForMonitor(this); g_pCompositor->scheduleFrameForMonitor(self.lock());
PROTO::gamma->applyGammaToState(this); PROTO::gamma->applyGammaToState(self.lock());
events.connect.emit(); events.connect.emit();
} }
@ -237,18 +238,18 @@ void CMonitor::onDisconnect(bool destroy) {
events.disconnect.emit(); events.disconnect.emit();
// Cleanup everything. Move windows back, snap cursor, shit. // Cleanup everything. Move windows back, snap cursor, shit.
CMonitor* BACKUPMON = nullptr; PHLMONITOR BACKUPMON = nullptr;
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
if (m.get() != this) { if (m.get() != this) {
BACKUPMON = m.get(); BACKUPMON = m;
break; break;
} }
} }
// remove mirror // remove mirror
if (pMirrorOf) { if (pMirrorOf) {
pMirrorOf->mirrors.erase(std::find_if(pMirrorOf->mirrors.begin(), pMirrorOf->mirrors.end(), [&](const auto& other) { return other == this; })); pMirrorOf->mirrors.erase(std::find_if(pMirrorOf->mirrors.begin(), pMirrorOf->mirrors.end(), [this](const auto& other) { return other.get() == this || !other; }));
pMirrorOf = nullptr; pMirrorOf.reset();
} }
if (!mirrors.empty()) { if (!mirrors.empty()) {
@ -320,31 +321,31 @@ void CMonitor::onDisconnect(bool destroy) {
Debug::log(WARN, "wlr_output_commit_state failed in CMonitor::onDisconnect"); Debug::log(WARN, "wlr_output_commit_state failed in CMonitor::onDisconnect");
if (g_pCompositor->m_pLastMonitor.get() == this) if (g_pCompositor->m_pLastMonitor.get() == this)
g_pCompositor->setActiveMonitor(BACKUPMON ? BACKUPMON : g_pCompositor->m_pUnsafeOutput); g_pCompositor->setActiveMonitor(BACKUPMON ? BACKUPMON : g_pCompositor->m_pUnsafeOutput.lock());
if (g_pHyprRenderer->m_pMostHzMonitor == this) { if (g_pHyprRenderer->m_pMostHzMonitor == self) {
int mostHz = 0; int mostHz = 0;
CMonitor* pMonitorMostHz = nullptr; PHLMONITOR pMonitorMostHz = nullptr;
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
if (m->refreshRate > mostHz && m.get() != this) { if (m->refreshRate > mostHz && m.get() != this) {
pMonitorMostHz = m.get(); pMonitorMostHz = m;
mostHz = m->refreshRate; mostHz = m->refreshRate;
} }
} }
g_pHyprRenderer->m_pMostHzMonitor = pMonitorMostHz; g_pHyprRenderer->m_pMostHzMonitor = pMonitorMostHz;
} }
std::erase_if(g_pCompositor->m_vMonitors, [&](SP<CMonitor>& el) { return el.get() == this; }); std::erase_if(g_pCompositor->m_vMonitors, [&](PHLMONITOR& el) { return el.get() == this; });
} }
void CMonitor::addDamage(const pixman_region32_t* rg) { void CMonitor::addDamage(const pixman_region32_t* rg) {
static auto PZOOMFACTOR = CConfigValue<Hyprlang::FLOAT>("cursor:zoom_factor"); static auto PZOOMFACTOR = CConfigValue<Hyprlang::FLOAT>("cursor:zoom_factor");
if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == self.lock()) {
wlr_damage_ring_add_whole(&damage); wlr_damage_ring_add_whole(&damage);
g_pCompositor->scheduleFrameForMonitor(this); g_pCompositor->scheduleFrameForMonitor(self.lock());
} else if (wlr_damage_ring_add(&damage, rg)) } else if (wlr_damage_ring_add(&damage, rg))
g_pCompositor->scheduleFrameForMonitor(this); g_pCompositor->scheduleFrameForMonitor(self.lock());
} }
void CMonitor::addDamage(const CRegion* rg) { void CMonitor::addDamage(const CRegion* rg) {
@ -353,13 +354,13 @@ void CMonitor::addDamage(const CRegion* rg) {
void CMonitor::addDamage(const CBox* box) { void CMonitor::addDamage(const CBox* box) {
static auto PZOOMFACTOR = CConfigValue<Hyprlang::FLOAT>("cursor:zoom_factor"); static auto PZOOMFACTOR = CConfigValue<Hyprlang::FLOAT>("cursor:zoom_factor");
if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == self.lock()) {
wlr_damage_ring_add_whole(&damage); wlr_damage_ring_add_whole(&damage);
g_pCompositor->scheduleFrameForMonitor(this); g_pCompositor->scheduleFrameForMonitor(self.lock());
} }
if (wlr_damage_ring_add_box(&damage, const_cast<CBox*>(box)->pWlr())) if (wlr_damage_ring_add_box(&damage, const_cast<CBox*>(box)->pWlr()))
g_pCompositor->scheduleFrameForMonitor(this); g_pCompositor->scheduleFrameForMonitor(self.lock());
} }
bool CMonitor::isMirror() { bool CMonitor::isMirror() {
@ -412,7 +413,7 @@ void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) {
if (PNEWWORKSPACE) { if (PNEWWORKSPACE) {
// workspace exists, move it to the newly connected monitor // workspace exists, move it to the newly connected monitor
g_pCompositor->moveWorkspaceToMonitor(PNEWWORKSPACE, this); g_pCompositor->moveWorkspaceToMonitor(PNEWWORKSPACE, self.lock());
activeWorkspace = PNEWWORKSPACE; activeWorkspace = PNEWWORKSPACE;
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID);
PNEWWORKSPACE->startAnim(true, true, true); PNEWWORKSPACE->startAnim(true, true, true);
@ -441,7 +442,7 @@ void CMonitor::setMirror(const std::string& mirrorOf) {
return; return;
} }
if (PMIRRORMON == this) { if (PMIRRORMON == self) {
Debug::log(ERR, "Cannot mirror self!"); Debug::log(ERR, "Cannot mirror self!");
return; return;
} }
@ -449,11 +450,10 @@ void CMonitor::setMirror(const std::string& mirrorOf) {
if (!PMIRRORMON) { if (!PMIRRORMON) {
// disable mirroring // disable mirroring
if (pMirrorOf) { if (pMirrorOf)
pMirrorOf->mirrors.erase(std::find_if(pMirrorOf->mirrors.begin(), pMirrorOf->mirrors.end(), [&](const auto& other) { return other == this; })); pMirrorOf->mirrors.erase(std::find_if(pMirrorOf->mirrors.begin(), pMirrorOf->mirrors.end(), [this](const auto& other) { return other.get() == this; }));
}
pMirrorOf = nullptr; pMirrorOf.reset();
// set rule // set rule
const auto RULE = g_pConfigManager->getMonitorRuleFor(*this); const auto RULE = g_pConfigManager->getMonitorRuleFor(*this);
@ -462,7 +462,7 @@ void CMonitor::setMirror(const std::string& mirrorOf) {
// push to mvmonitors // push to mvmonitors
SP<CMonitor>* thisWrapper = nullptr; PHLMONITOR* thisWrapper = nullptr;
// find the wrap // find the wrap
for (auto& m : g_pCompositor->m_vRealMonitors) { for (auto& m : g_pCompositor->m_vRealMonitors) {
@ -481,12 +481,12 @@ void CMonitor::setMirror(const std::string& mirrorOf) {
setupDefaultWS(RULE); setupDefaultWS(RULE);
g_pHyprRenderer->applyMonitorRule(this, (SMonitorRule*)&RULE, true); // will apply the offset and stuff g_pHyprRenderer->applyMonitorRule(self.lock(), (SMonitorRule*)&RULE, true); // will apply the offset and stuff
} else { } else {
CMonitor* BACKUPMON = nullptr; PHLMONITOR BACKUPMON = nullptr;
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
if (m.get() != this) { if (m.get() != this) {
BACKUPMON = m.get(); BACKUPMON = m;
break; break;
} }
} }
@ -510,14 +510,14 @@ void CMonitor::setMirror(const std::string& mirrorOf) {
pMirrorOf = PMIRRORMON; pMirrorOf = PMIRRORMON;
pMirrorOf->mirrors.push_back(this); pMirrorOf->mirrors.push_back(self);
// remove from mvmonitors // remove from mvmonitors
std::erase_if(g_pCompositor->m_vMonitors, [&](const auto& other) { return other.get() == this; }); std::erase_if(g_pCompositor->m_vMonitors, [&](const auto& other) { return other.get() == this; });
g_pCompositor->arrangeMonitors(); g_pCompositor->arrangeMonitors();
g_pCompositor->setActiveMonitor(g_pCompositor->m_vMonitors.front().get()); g_pCompositor->setActiveMonitor(g_pCompositor->m_vMonitors.front());
g_pCompositor->sanityCheckWorkspaces(); g_pCompositor->sanityCheckWorkspaces();
} }
@ -604,11 +604,11 @@ void CMonitor::changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal, bo
EMIT_HOOK_EVENT("workspace", pWorkspace); EMIT_HOOK_EVENT("workspace", pWorkspace);
} }
g_pHyprRenderer->damageMonitor(this); g_pHyprRenderer->damageMonitor(self.lock());
g_pCompositor->updateFullscreenFadeOnWorkspace(pWorkspace); g_pCompositor->updateFullscreenFadeOnWorkspace(pWorkspace);
g_pConfigManager->ensureVRR(this); g_pConfigManager->ensureVRR(self.lock());
g_pCompositor->updateSuspendedStates(); g_pCompositor->updateSuspendedStates();
@ -621,7 +621,7 @@ void CMonitor::changeWorkspace(const int& id, bool internal, bool noMouseMove, b
} }
void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) { void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) {
g_pHyprRenderer->damageMonitor(this); g_pHyprRenderer->damageMonitor(self.lock());
if (!pWorkspace) { if (!pWorkspace) {
// remove special if exists // remove special if exists
@ -643,7 +643,7 @@ void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) {
g_pCompositor->updateFullscreenFadeOnWorkspace(activeWorkspace); g_pCompositor->updateFullscreenFadeOnWorkspace(activeWorkspace);
g_pConfigManager->ensureVRR(this); g_pConfigManager->ensureVRR(self.lock());
g_pCompositor->updateSuspendedStates(); g_pCompositor->updateSuspendedStates();
@ -711,15 +711,145 @@ void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) {
g_pEventManager->postEvent(SHyprIPCEvent{"activespecial", pWorkspace->m_szName + "," + szName}); g_pEventManager->postEvent(SHyprIPCEvent{"activespecial", pWorkspace->m_szName + "," + szName});
g_pHyprRenderer->damageMonitor(this); g_pHyprRenderer->damageMonitor(self.lock());
g_pCompositor->updateFullscreenFadeOnWorkspace(pWorkspace); g_pCompositor->updateFullscreenFadeOnWorkspace(pWorkspace);
g_pConfigManager->ensureVRR(this); g_pConfigManager->ensureVRR(self.lock());
g_pCompositor->updateSuspendedStates(); g_pCompositor->updateSuspendedStates();
} }
void CMonitor::onPresented(void* data) {
auto E = (wlr_output_event_present*)data;
PROTO::presentation->onPresented(self.lock(), E->when, E->refresh, E->seq, E->flags);
}
void CMonitor::onFrame(void* data) {
if (g_pCompositor->m_bExitTriggered) {
// Only signal cleanup once
g_pCompositor->m_bExitTriggered = false;
g_pCompositor->cleanup();
return;
}
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!");
if (g_pCompositor->m_bUnsafeState && std::ranges::any_of(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](auto& m) {
return m->output != g_pCompositor->m_pUnsafeOutput->output;
})) {
// restore from unsafe state
g_pCompositor->leaveUnsafeState();
}
return; // cannot draw on session inactive (different tty)
}
if (!m_bEnabled)
return;
g_pHyprRenderer->recheckSolitaryForMonitor(self.lock());
tearingState.busy = false;
if (tearingState.activelyTearing && solitaryClient.lock() /* can be invalidated by a recheck */) {
if (!tearingState.frameScheduledWhileBusy)
return; // we did not schedule a frame yet to be displayed, but we are tearing. Why render?
tearingState.nextRenderTorn = true;
tearingState.frameScheduledWhileBusy = false;
}
static auto PENABLERAT = CConfigValue<Hyprlang::INT>("misc:render_ahead_of_time");
static auto PRATSAFE = CConfigValue<Hyprlang::INT>("misc:render_ahead_safezone");
lastPresentationTimer.reset();
if (*PENABLERAT && !tearingState.nextRenderTorn) {
if (!RATScheduled) {
// render
g_pHyprRenderer->renderMonitor(self.lock());
}
RATScheduled = false;
const auto& [avg, max, min] = g_pHyprRenderer->getRenderTimes(self.lock());
if (max + *PRATSAFE > 1000.0 / refreshRate)
return;
const auto MSLEFT = 1000.0 / refreshRate - lastPresentationTimer.getMillis();
RATScheduled = true;
const auto ESTRENDERTIME = std::ceil(avg + *PRATSAFE);
const auto TIMETOSLEEP = std::floor(MSLEFT - ESTRENDERTIME);
if (MSLEFT < 1 || MSLEFT < ESTRENDERTIME || TIMETOSLEEP < 1)
g_pHyprRenderer->renderMonitor(self.lock());
else
wl_event_source_timer_update(renderTimer, TIMETOSLEEP);
} else
g_pHyprRenderer->renderMonitor(self.lock());
}
void CMonitor::onStateRequest(void* data) {
const auto E = (wlr_output_event_request_state*)data;
if (!createdByUser)
return;
const auto SIZE = E->state->mode ? Vector2D{E->state->mode->width, E->state->mode->height} : Vector2D{E->state->custom_mode.width, E->state->custom_mode.height};
forceSize = SIZE;
SMonitorRule rule = activeMonitorRule;
rule.resolution = SIZE;
g_pHyprRenderer->applyMonitorRule(self.lock(), &rule);
}
void CMonitor::onDamage(void* data) {
const auto E = (wlr_output_event_damage*)data;
addDamage(E->damage);
}
void CMonitor::onCommit(void* data) {
const auto E = (wlr_output_event_commit*)data;
if (E->state->committed & WLR_OUTPUT_STATE_BUFFER) {
g_pProtocolManager->m_pScreencopyProtocolManager->onOutputCommit(self.lock(), E);
g_pProtocolManager->m_pToplevelExportProtocolManager->onOutputCommit(self.lock(), E);
}
}
void CMonitor::onNeedsFrame(void* data) {
g_pCompositor->scheduleFrameForMonitor(self.lock());
}
void CMonitor::onBind(void* data) {
; // noop
}
void CMonitor::onDestroy(void* data) {
Debug::log(LOG, "Destroy called for monitor {}", szName);
onDisconnect(true);
output = nullptr;
m_bRenderingInitPassed = false;
Debug::log(LOG, "Removing monitor {} from realMonitors", szName);
std::erase_if(g_pCompositor->m_vMonitors, [this](PHLMONITOR& el) { return el.get() == this; });
std::erase_if(g_pCompositor->m_vRealMonitors, [this](PHLMONITOR& el) { return el.get() == this; });
}
void CMonitor::setSpecialWorkspace(const int& id) { void CMonitor::setSpecialWorkspace(const int& id) {
setSpecialWorkspace(g_pCompositor->getWorkspaceByID(id)); setSpecialWorkspace(g_pCompositor->getWorkspaceByID(id));
} }

View file

@ -115,11 +115,11 @@ class CMonitor {
SMonitorRule activeMonitorRule; SMonitorRule activeMonitorRule;
WP<CMonitor> self; PHLMONITORREF self;
// mirroring // mirroring
CMonitor* pMirrorOf = nullptr; PHLMONITORREF pMirrorOf;
std::vector<CMonitor*> mirrors; std::vector<PHLMONITORREF> mirrors;
// for tearing // for tearing
PHLWINDOWREF solitaryClient; PHLWINDOWREF solitaryClient;
@ -185,4 +185,13 @@ class CMonitor {
private: private:
void setupDefaultWS(const SMonitorRule&); void setupDefaultWS(const SMonitorRule&);
int findAvailableDefaultWS(); int findAvailableDefaultWS();
void onFrame(void* data);
void onStateRequest(void* data);
void onDamage(void* data);
void onCommit(void* data);
void onNeedsFrame(void* data);
void onBind(void* data);
void onDestroy(void* data);
void onPresented(void* data);
}; };

View file

@ -16,7 +16,7 @@ class IKeyboard;
class CWLSurfaceResource; class CWLSurfaceResource;
struct SRenderData { struct SRenderData {
CMonitor* pMonitor; PHLMONITOR pMonitor;
timespec* when; timespec* when;
double x, y; double x, y;
@ -63,7 +63,7 @@ struct SSwipeGesture {
int speedPoints = 0; int speedPoints = 0;
int touch_id = 0; int touch_id = 0;
CMonitor* pMonitor = nullptr; PHLMONITOR pMonitor = nullptr;
}; };
struct SSwitchDevice { struct SSwitchDevice {

View file

@ -11,7 +11,7 @@ CHyprError::CHyprError() {
if (!m_bIsCreated) if (!m_bIsCreated)
return; return;
g_pHyprRenderer->damageMonitor(g_pCompositor->m_pLastMonitor.get()); g_pHyprRenderer->damageMonitor(g_pCompositor->m_pLastMonitor.lock());
m_bMonitorChanged = true; m_bMonitorChanged = true;
}); });
@ -44,7 +44,7 @@ void CHyprError::createQueued() {
m_fFadeOpacity.setValueAndWarp(0.f); m_fFadeOpacity.setValueAndWarp(0.f);
m_fFadeOpacity = 1.f; m_fFadeOpacity = 1.f;
const auto PMONITOR = g_pCompositor->m_vMonitors.front().get(); const auto PMONITOR = g_pCompositor->m_vMonitors.front();
const auto SCALE = PMONITOR->scale; const auto SCALE = PMONITOR->scale;

View file

@ -101,12 +101,12 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
if (pNode->isNode) if (pNode->isNode)
return; return;
CMonitor* PMONITOR = nullptr; PHLMONITOR PMONITOR = nullptr;
if (g_pCompositor->isWorkspaceSpecial(pNode->workspaceID)) { if (g_pCompositor->isWorkspaceSpecial(pNode->workspaceID)) {
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
if (m->activeSpecialWorkspaceID() == pNode->workspaceID) { if (m->activeSpecialWorkspaceID() == pNode->workspaceID) {
PMONITOR = m.get(); PMONITOR = m;
break; break;
} }
} }

View file

@ -586,12 +586,12 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) {
} }
void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) {
CMonitor* PMONITOR = nullptr; PHLMONITOR PMONITOR = nullptr;
if (g_pCompositor->isWorkspaceSpecial(pNode->workspaceID)) { if (g_pCompositor->isWorkspaceSpecial(pNode->workspaceID)) {
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
if (m->activeSpecialWorkspaceID() == pNode->workspaceID) { if (m->activeSpecialWorkspaceID() == pNode->workspaceID) {
PMONITOR = m.get(); PMONITOR = m;
break; break;
} }
} }

View file

@ -84,7 +84,7 @@ void CAnimationManager::tick() {
PHLWINDOW PWINDOW = av->m_pWindow.lock(); PHLWINDOW PWINDOW = av->m_pWindow.lock();
PHLWORKSPACE PWORKSPACE = av->m_pWorkspace.lock(); PHLWORKSPACE PWORKSPACE = av->m_pWorkspace.lock();
PHLLS PLAYER = av->m_pLayer.lock(); PHLLS PLAYER = av->m_pLayer.lock();
CMonitor* PMONITOR = nullptr; PHLMONITOR PMONITOR = nullptr;
bool animationsDisabled = animGlobalDisabled; bool animationsDisabled = animGlobalDisabled;
if (PWINDOW) { if (PWINDOW) {

View file

@ -283,7 +283,7 @@ void CCursorManager::updateTheme() {
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
m->forceFullFrames = 5; m->forceFullFrames = 5;
g_pCompositor->scheduleFrameForMonitor(m.get()); g_pCompositor->scheduleFrameForMonitor(m);
} }
} }

View file

@ -270,11 +270,11 @@ void updateRelativeCursorCoords() {
g_pCompositor->m_pLastWindow->m_vRelativeCursorCoordsOnLastWarp = g_pInputManager->getMouseCoordsInternal() - g_pCompositor->m_pLastWindow->m_vPosition; g_pCompositor->m_pLastWindow->m_vRelativeCursorCoordsOnLastWarp = g_pInputManager->getMouseCoordsInternal() - g_pCompositor->m_pLastWindow->m_vPosition;
} }
bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) { bool CKeybindManager::tryMoveFocusToMonitor(PHLMONITOR monitor) {
if (!monitor) if (!monitor)
return false; return false;
const auto LASTMONITOR = g_pCompositor->m_pLastMonitor.get(); const auto LASTMONITOR = g_pCompositor->m_pLastMonitor.lock();
if (LASTMONITOR == monitor) { if (LASTMONITOR == monitor) {
Debug::log(LOG, "Tried to move to active monitor"); Debug::log(LOG, "Tried to move to active monitor");
return false; return false;
@ -1029,7 +1029,7 @@ void CKeybindManager::changeworkspace(std::string args) {
static auto PALLOWWORKSPACECYCLES = CConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles"); static auto PALLOWWORKSPACECYCLES = CConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles");
static auto PWORKSPACECENTERON = CConfigValue<Hyprlang::INT>("binds:workspace_center_on"); static auto PWORKSPACECENTERON = CConfigValue<Hyprlang::INT>("binds:workspace_center_on");
const auto PMONITOR = g_pCompositor->m_pLastMonitor.get(); const auto PMONITOR = g_pCompositor->m_pLastMonitor.lock();
if (!PMONITOR) if (!PMONITOR)
return; return;
@ -1157,7 +1157,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
} }
auto pWorkspace = g_pCompositor->getWorkspaceByID(WORKSPACEID); auto pWorkspace = g_pCompositor->getWorkspaceByID(WORKSPACEID);
CMonitor* pMonitor = nullptr; PHLMONITOR pMonitor = nullptr;
const auto POLDWS = PWINDOW->m_pWorkspace; const auto POLDWS = PWINDOW->m_pWorkspace;
static auto PALLOWWORKSPACECYCLES = CConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles"); static auto PALLOWWORKSPACECYCLES = CConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles");
@ -1643,7 +1643,7 @@ void CKeybindManager::exitHyprland(std::string argz) {
} }
void CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) { void CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) {
CMonitor* PMONITOR = g_pCompositor->getMonitorFromString(args); PHLMONITOR PMONITOR = g_pCompositor->getMonitorFromString(args);
if (!PMONITOR) { if (!PMONITOR) {
Debug::log(ERR, "Ignoring moveCurrentWorkspaceToMonitor: monitor doesnt exist"); Debug::log(ERR, "Ignoring moveCurrentWorkspaceToMonitor: monitor doesnt exist");
@ -1702,7 +1702,7 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) {
return; return;
} }
const auto PCURRMONITOR = g_pCompositor->m_pLastMonitor.get(); const auto PCURRMONITOR = g_pCompositor->m_pLastMonitor.lock();
if (!PCURRMONITOR) { if (!PCURRMONITOR) {
Debug::log(ERR, "focusWorkspaceOnCurrentMonitor monitor doesn't exist!"); Debug::log(ERR, "focusWorkspaceOnCurrentMonitor monitor doesn't exist!");
@ -1791,7 +1791,7 @@ void CKeybindManager::forceRendererReload(std::string args) {
continue; continue;
auto rule = g_pConfigManager->getMonitorRuleFor(*m); auto rule = g_pConfigManager->getMonitorRuleFor(*m);
if (!g_pHyprRenderer->applyMonitorRule(m.get(), &rule, true)) { if (!g_pHyprRenderer->applyMonitorRule(m, &rule, true)) {
overAgain = true; overAgain = true;
break; break;
} }
@ -2255,7 +2255,7 @@ void CKeybindManager::dpms(std::string arg) {
} }
if (enable) if (enable)
g_pHyprRenderer->damageMonitor(m.get()); g_pHyprRenderer->damageMonitor(m);
m->events.dpmsChanged.emit(); m->events.dpmsChanged.emit();
} }

View file

@ -136,7 +136,7 @@ class CKeybindManager {
void updateXKBTranslationState(); void updateXKBTranslationState();
bool ensureMouseBindState(); bool ensureMouseBindState();
static bool tryMoveFocusToMonitor(CMonitor* monitor); static bool tryMoveFocusToMonitor(PHLMONITOR monitor);
static void moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir = ""); static void moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir = "");
static void moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection); static void moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection);
static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO); static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO);

View file

@ -135,7 +135,7 @@ static bool output_pick_cursor_format(struct wlr_output* output, struct wlr_drm_
CPointerManager::CPointerManager() { CPointerManager::CPointerManager() {
hooks.monitorAdded = g_pHookSystem->hookDynamic("newMonitor", [this](void* self, SCallbackInfo& info, std::any data) { hooks.monitorAdded = g_pHookSystem->hookDynamic("newMonitor", [this](void* self, SCallbackInfo& info, std::any data) {
auto PMONITOR = std::any_cast<SP<CMonitor>>(data); auto PMONITOR = std::any_cast<PHLMONITOR>(data);
onMonitorLayoutChange(); onMonitorLayoutChange();
@ -164,7 +164,7 @@ void CPointerManager::unlockSoftwareAll() {
updateCursorBackend(); updateCursorBackend();
} }
void CPointerManager::lockSoftwareForMonitor(SP<CMonitor> mon) { void CPointerManager::lockSoftwareForMonitor(PHLMONITOR mon) {
auto state = stateFor(mon); auto state = stateFor(mon);
state->softwareLocks++; state->softwareLocks++;
@ -172,7 +172,7 @@ void CPointerManager::lockSoftwareForMonitor(SP<CMonitor> mon) {
updateCursorBackend(); updateCursorBackend();
} }
void CPointerManager::unlockSoftwareForMonitor(SP<CMonitor> mon) { void CPointerManager::unlockSoftwareForMonitor(PHLMONITOR mon) {
auto state = stateFor(mon); auto state = stateFor(mon);
state->softwareLocks--; state->softwareLocks--;
if (state->softwareLocks < 0) if (state->softwareLocks < 0)
@ -182,6 +182,12 @@ void CPointerManager::unlockSoftwareForMonitor(SP<CMonitor> mon) {
updateCursorBackend(); updateCursorBackend();
} }
bool CPointerManager::isSoftwareLockedFor(PHLMONITOR mon) {
auto state = stateFor(mon);
return state->softwareLocks;
}
Vector2D CPointerManager::position() { Vector2D CPointerManager::position() {
return pointerPos; return pointerPos;
} }
@ -190,7 +196,7 @@ bool CPointerManager::hasCursor() {
return currentCursorImage.pBuffer || currentCursorImage.surface; return currentCursorImage.pBuffer || currentCursorImage.surface;
} }
SP<CPointerManager::SMonitorPointerState> CPointerManager::stateFor(SP<CMonitor> mon) { SP<CPointerManager::SMonitorPointerState> CPointerManager::stateFor(PHLMONITOR mon) {
auto it = std::find_if(monitorStates.begin(), monitorStates.end(), [mon](const auto& other) { return other->monitor == mon; }); auto it = std::find_if(monitorStates.begin(), monitorStates.end(), [mon](const auto& other) { return other->monitor == mon; });
if (it == monitorStates.end()) if (it == monitorStates.end())
return monitorStates.emplace_back(makeShared<CPointerManager::SMonitorPointerState>(mon)); return monitorStates.emplace_back(makeShared<CPointerManager::SMonitorPointerState>(mon));
@ -455,7 +461,7 @@ bool CPointerManager::setHWCursorBuffer(SP<SMonitorPointerState> state, wlr_buff
wlr_buffer_unlock(state->cursorFrontBuffer); wlr_buffer_unlock(state->cursorFrontBuffer);
state->cursorFrontBuffer = buf; state->cursorFrontBuffer = buf;
g_pCompositor->scheduleFrameForMonitor(state->monitor.get()); g_pCompositor->scheduleFrameForMonitor(state->monitor.lock());
if (buf) if (buf)
wlr_buffer_lock(buf); wlr_buffer_lock(buf);
@ -507,12 +513,12 @@ wlr_buffer* CPointerManager::renderHWCursorBuffer(SP<CPointerManager::SMonitorPo
CRegion damage = {0, 0, INT16_MAX, INT16_MAX}; CRegion damage = {0, 0, INT16_MAX, INT16_MAX};
g_pHyprRenderer->makeEGLCurrent(); g_pHyprRenderer->makeEGLCurrent();
g_pHyprOpenGL->m_RenderData.pMonitor = state->monitor.get(); // has to be set cuz allocs g_pHyprOpenGL->m_RenderData.pMonitor = state->monitor; // has to be set cuz allocs
const auto RBO = g_pHyprRenderer->getOrCreateRenderbuffer(buf, DRM_FORMAT_ARGB8888); const auto RBO = g_pHyprRenderer->getOrCreateRenderbuffer(buf, DRM_FORMAT_ARGB8888);
RBO->bind(); RBO->bind();
g_pHyprOpenGL->beginSimple(state->monitor.get(), damage, RBO); g_pHyprOpenGL->beginSimple(state->monitor.lock(), damage, RBO);
g_pHyprOpenGL->clear(CColor{0.F, 0.F, 0.F, 0.F}); g_pHyprOpenGL->clear(CColor{0.F, 0.F, 0.F, 0.F});
CBox xbox = {{}, Vector2D{currentCursorImage.size / currentCursorImage.scale * state->monitor->scale}.round()}; CBox xbox = {{}, Vector2D{currentCursorImage.size / currentCursorImage.scale * state->monitor->scale}.round()};
@ -523,7 +529,7 @@ wlr_buffer* CPointerManager::renderHWCursorBuffer(SP<CPointerManager::SMonitorPo
g_pHyprOpenGL->end(); g_pHyprOpenGL->end();
glFlush(); glFlush();
g_pHyprOpenGL->m_RenderData.pMonitor = nullptr; g_pHyprOpenGL->m_RenderData.pMonitor.reset();
g_pHyprRenderer->onRenderbufferDestroy(RBO); g_pHyprRenderer->onRenderbufferDestroy(RBO);
@ -532,7 +538,7 @@ wlr_buffer* CPointerManager::renderHWCursorBuffer(SP<CPointerManager::SMonitorPo
return buf; return buf;
} }
void CPointerManager::renderSoftwareCursorsFor(SP<CMonitor> pMonitor, timespec* now, CRegion& damage, std::optional<Vector2D> overridePos) { void CPointerManager::renderSoftwareCursorsFor(PHLMONITOR pMonitor, timespec* now, CRegion& damage, std::optional<Vector2D> overridePos) {
if (!hasCursor()) if (!hasCursor())
return; return;
@ -565,14 +571,14 @@ void CPointerManager::renderSoftwareCursorsFor(SP<CMonitor> pMonitor, timespec*
currentCursorImage.surface->resource()->frame(now); currentCursorImage.surface->resource()->frame(now);
} }
Vector2D CPointerManager::getCursorPosForMonitor(SP<CMonitor> pMonitor) { Vector2D CPointerManager::getCursorPosForMonitor(PHLMONITOR pMonitor) {
return CBox{pointerPos - pMonitor->vecPosition, {0, 0}} return CBox{pointerPos - pMonitor->vecPosition, {0, 0}}
//.transform(pMonitor->transform, pMonitor->vecTransformedSize.x / pMonitor->scale, pMonitor->vecTransformedSize.y / pMonitor->scale) //.transform(pMonitor->transform, pMonitor->vecTransformedSize.x / pMonitor->scale, pMonitor->vecTransformedSize.y / pMonitor->scale)
.pos() * .pos() *
pMonitor->scale; pMonitor->scale;
} }
Vector2D CPointerManager::transformedHotspot(SP<CMonitor> pMonitor) { Vector2D CPointerManager::transformedHotspot(PHLMONITOR pMonitor) {
if (!pMonitor->output->cursor_swapchain) if (!pMonitor->output->cursor_swapchain)
return {}; // doesn't matter, we have no hw cursor, and this is only for hw cursors return {}; // doesn't matter, we have no hw cursor, and this is only for hw cursors
@ -581,7 +587,7 @@ Vector2D CPointerManager::transformedHotspot(SP<CMonitor> pMonitor) {
.pos(); .pos();
} }
CBox CPointerManager::getCursorBoxLogicalForMonitor(SP<CMonitor> pMonitor) { CBox CPointerManager::getCursorBoxLogicalForMonitor(PHLMONITOR pMonitor) {
return getCursorBoxGlobal().translate(-pMonitor->vecPosition); return getCursorBoxGlobal().translate(-pMonitor->vecPosition);
} }
@ -700,7 +706,7 @@ void CPointerManager::move(const Vector2D& deltaLogical) {
void CPointerManager::warpAbsolute(Vector2D abs, SP<IHID> dev) { void CPointerManager::warpAbsolute(Vector2D abs, SP<IHID> dev) {
SP<CMonitor> currentMonitor = g_pCompositor->m_pLastMonitor.lock(); PHLMONITOR currentMonitor = g_pCompositor->m_pLastMonitor.lock();
if (!currentMonitor) if (!currentMonitor)
return; return;
@ -978,7 +984,7 @@ void CPointerManager::detachTablet(SP<CTablet> tablet) {
std::erase_if(tabletListeners, [tablet](const auto& e) { return e->tablet.expired() || e->tablet == tablet; }); std::erase_if(tabletListeners, [tablet](const auto& e) { return e->tablet.expired() || e->tablet == tablet; });
} }
void CPointerManager::damageCursor(SP<CMonitor> pMonitor) { void CPointerManager::damageCursor(PHLMONITOR pMonitor) {
for (auto& mw : monitorStates) { for (auto& mw : monitorStates) {
if (mw->monitor != pMonitor) if (mw->monitor != pMonitor)
continue; continue;

View file

@ -41,17 +41,18 @@ class CPointerManager {
void setCursorSurface(SP<CWLSurface> buf, const Vector2D& hotspot); void setCursorSurface(SP<CWLSurface> buf, const Vector2D& hotspot);
void resetCursorImage(bool apply = true); void resetCursorImage(bool apply = true);
void lockSoftwareForMonitor(SP<CMonitor> pMonitor); void lockSoftwareForMonitor(PHLMONITOR pMonitor);
void unlockSoftwareForMonitor(SP<CMonitor> pMonitor); void unlockSoftwareForMonitor(PHLMONITOR pMonitor);
void lockSoftwareAll(); void lockSoftwareAll();
void unlockSoftwareAll(); void unlockSoftwareAll();
bool isSoftwareLockedFor(PHLMONITOR pMonitor);
void renderSoftwareCursorsFor(SP<CMonitor> pMonitor, timespec* now, CRegion& damage /* logical */, std::optional<Vector2D> overridePos = {} /* monitor-local */); void renderSoftwareCursorsFor(PHLMONITOR pMonitor, timespec* now, CRegion& damage /* logical */, std::optional<Vector2D> overridePos = {} /* monitor-local */);
// this is needed e.g. during screensharing where // this is needed e.g. during screensharing where
// the software cursors aren't locked during the cursor move, but they // the software cursors aren't locked during the cursor move, but they
// are rendered later. // are rendered later.
void damageCursor(SP<CMonitor> pMonitor); void damageCursor(PHLMONITOR pMonitor);
// //
Vector2D position(); Vector2D position();
@ -71,13 +72,13 @@ class CPointerManager {
Vector2D closestValid(const Vector2D& pos); Vector2D closestValid(const Vector2D& pos);
// returns the thing in device coordinates. Is NOT offset by the hotspot, relies on set_cursor with hotspot. // returns the thing in device coordinates. Is NOT offset by the hotspot, relies on set_cursor with hotspot.
Vector2D getCursorPosForMonitor(SP<CMonitor> pMonitor); Vector2D getCursorPosForMonitor(PHLMONITOR pMonitor);
// returns the thing in logical coordinates of the monitor // returns the thing in logical coordinates of the monitor
CBox getCursorBoxLogicalForMonitor(SP<CMonitor> pMonitor); CBox getCursorBoxLogicalForMonitor(PHLMONITOR pMonitor);
// returns the thing in global coords // returns the thing in global coords
CBox getCursorBoxGlobal(); CBox getCursorBoxGlobal();
Vector2D transformedHotspot(SP<CMonitor> pMonitor); Vector2D transformedHotspot(PHLMONITOR pMonitor);
SP<CTexture> getCurrentCursorTexture(); SP<CTexture> getCurrentCursorTexture();
@ -149,13 +150,13 @@ class CPointerManager {
Vector2D pointerPos = {0, 0}; Vector2D pointerPos = {0, 0};
struct SMonitorPointerState { struct SMonitorPointerState {
SMonitorPointerState(SP<CMonitor> m) : monitor(m) {} SMonitorPointerState(PHLMONITOR m) : monitor(m) {}
~SMonitorPointerState() { ~SMonitorPointerState() {
if (cursorFrontBuffer) if (cursorFrontBuffer)
wlr_buffer_unlock(cursorFrontBuffer); wlr_buffer_unlock(cursorFrontBuffer);
} }
WP<CMonitor> monitor; PHLMONITORREF monitor;
int softwareLocks = 0; int softwareLocks = 0;
bool hardwareFailed = false; bool hardwareFailed = false;
@ -167,7 +168,7 @@ class CPointerManager {
}; };
std::vector<SP<SMonitorPointerState>> monitorStates; std::vector<SP<SMonitorPointerState>> monitorStates;
SP<SMonitorPointerState> stateFor(SP<CMonitor> mon); SP<SMonitorPointerState> stateFor(PHLMONITOR mon);
bool attemptHardwareCursor(SP<SMonitorPointerState> state); bool attemptHardwareCursor(SP<SMonitorPointerState> state);
wlr_buffer* renderHWCursorBuffer(SP<SMonitorPointerState> state, SP<CTexture> texture); wlr_buffer* renderHWCursorBuffer(SP<SMonitorPointerState> state, SP<CTexture> texture);
bool setHWCursorBuffer(SP<SMonitorPointerState> state, wlr_buffer* buf); bool setHWCursorBuffer(SP<SMonitorPointerState> state, wlr_buffer* buf);

View file

@ -46,7 +46,7 @@
#include "../helpers/Monitor.hpp" #include "../helpers/Monitor.hpp"
#include "../render/Renderer.hpp" #include "../render/Renderer.hpp"
void CProtocolManager::onMonitorModeChange(CMonitor* pMonitor) { void CProtocolManager::onMonitorModeChange(PHLMONITOR pMonitor) {
const bool ISMIRROR = pMonitor->isMirror(); const bool ISMIRROR = pMonitor->isMirror();
// onModeChanged we check if the current mirror status matches the global. // onModeChanged we check if the current mirror status matches the global.
@ -67,7 +67,7 @@ CProtocolManager::CProtocolManager() {
// Outputs are a bit dumb, we have to agree. // Outputs are a bit dumb, we have to agree.
static auto P = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) { static auto P = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) {
auto M = std::any_cast<CMonitor*>(param); auto M = std::any_cast<PHLMONITOR>(param);
// ignore mirrored outputs. I don't think this will ever be hit as mirrors are applied after // ignore mirrored outputs. I don't think this will ever be hit as mirrors are applied after
// this event is emitted iirc. // this event is emitted iirc.
@ -82,7 +82,7 @@ CProtocolManager::CProtocolManager() {
}); });
static auto P2 = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) { static auto P2 = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
auto M = std::any_cast<CMonitor*>(param); auto M = std::any_cast<PHLMONITOR>(param);
if (!PROTO::outputs.contains(M->szName)) if (!PROTO::outputs.contains(M->szName))
return; return;
PROTO::outputs.at(M->szName)->remove(); PROTO::outputs.at(M->szName)->remove();

View file

@ -22,7 +22,7 @@ class CProtocolManager {
private: private:
std::unordered_map<std::string, CHyprSignalListener> m_mModeChangeListeners; std::unordered_map<std::string, CHyprSignalListener> m_mModeChangeListeners;
void onMonitorModeChange(CMonitor* pMonitor); void onMonitorModeChange(PHLMONITOR pMonitor);
}; };
inline std::unique_ptr<CProtocolManager> g_pProtocolManager; inline std::unique_ptr<CProtocolManager> g_pProtocolManager;

View file

@ -67,14 +67,14 @@ void CSessionLockManager::onNewSessionLock(SP<CSessionLock> pLock) {
g_pInputManager->refocus(); g_pInputManager->refocus();
for (auto& m : g_pCompositor->m_vMonitors) for (auto& m : g_pCompositor->m_vMonitors)
g_pHyprRenderer->damageMonitor(m.get()); g_pHyprRenderer->damageMonitor(m);
}); });
m_pSessionLock->listeners.destroy = pLock->events.destroyed.registerListener([](std::any data) { m_pSessionLock->listeners.destroy = pLock->events.destroyed.registerListener([](std::any data) {
g_pCompositor->focusSurface(nullptr); g_pCompositor->focusSurface(nullptr);
for (auto& m : g_pCompositor->m_vMonitors) for (auto& m : g_pCompositor->m_vMonitors)
g_pHyprRenderer->damageMonitor(m.get()); g_pHyprRenderer->damageMonitor(m);
}); });
pLock->sendLocked(); pLock->sendLocked();

View file

@ -239,7 +239,7 @@ Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) {
static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling"); static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling");
CMonitor* pMonitor = nullptr; PHLMONITOR pMonitor = nullptr;
double bestDistance = __FLT_MAX__; double bestDistance = __FLT_MAX__;
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
const auto SIZ = *PXWLFORCESCALEZERO ? m->vecTransformedSize : m->vecSize; const auto SIZ = *PXWLFORCESCALEZERO ? m->vecTransformedSize : m->vecSize;
@ -249,7 +249,7 @@ Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) {
if (distance < bestDistance) { if (distance < bestDistance) {
bestDistance = distance; bestDistance = distance;
pMonitor = m.get(); pMonitor = m;
} }
} }

View file

@ -258,7 +258,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
g_pLayoutManager->getCurrentLayout()->onMouseMove(getMouseCoordsInternal()); g_pLayoutManager->getCurrentLayout()->onMouseMove(getMouseCoordsInternal());
if (PMONITOR && PMONITOR != g_pCompositor->m_pLastMonitor.get() && (*PMOUSEFOCUSMON || refocus) && m_pForcedFocus.expired()) if (PMONITOR && PMONITOR != g_pCompositor->m_pLastMonitor.lock() && (*PMOUSEFOCUSMON || refocus) && m_pForcedFocus.expired())
g_pCompositor->setActiveMonitor(PMONITOR); g_pCompositor->setActiveMonitor(PMONITOR);
if (g_pSessionLockManager->isSessionLocked()) { if (g_pSessionLockManager->isSessionLocked()) {
@ -370,8 +370,8 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
foundSurface = foundSurface =
g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &surfaceCoords, &pFoundLayerSurface); g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &surfaceCoords, &pFoundLayerSurface);
if (g_pCompositor->m_pLastMonitor->output->software_cursor_locks > 0) if (g_pPointerManager->isSoftwareLockedFor(g_pCompositor->m_pLastMonitor.lock()) > 0)
g_pCompositor->scheduleFrameForMonitor(g_pCompositor->m_pLastMonitor.get()); g_pCompositor->scheduleFrameForMonitor(g_pCompositor->m_pLastMonitor.lock());
// grabs // grabs
if (g_pSeatManager->seatGrab && !g_pSeatManager->seatGrab->accepts(foundSurface)) { if (g_pSeatManager->seatGrab && !g_pSeatManager->seatGrab->accepts(foundSurface)) {
@ -722,7 +722,7 @@ void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e) {
// notify app if we didnt handle it // notify app if we didnt handle it
g_pSeatManager->sendPointerButton(e.timeMs, e.button, e.state); g_pSeatManager->sendPointerButton(e.timeMs, e.button, e.state);
if (const auto PMON = g_pCompositor->getMonitorFromVector(mouseCoords); PMON != g_pCompositor->m_pLastMonitor.get() && PMON) if (const auto PMON = g_pCompositor->getMonitorFromVector(mouseCoords); PMON != g_pCompositor->m_pLastMonitor.lock() && PMON)
g_pCompositor->setActiveMonitor(PMON); g_pCompositor->setActiveMonitor(PMON);
if (g_pSeatManager->seatGrab && e.state == WL_POINTER_BUTTON_STATE_PRESSED) { if (g_pSeatManager->seatGrab && e.state == WL_POINTER_BUTTON_STATE_PRESSED) {
@ -1396,7 +1396,7 @@ void CInputManager::refocus() {
mouseMoveUnified(0, true); mouseMoveUnified(0, true);
} }
void CInputManager::refocusLastWindow(CMonitor* pMonitor) { void CInputManager::refocusLastWindow(PHLMONITOR pMonitor) {
if (!pMonitor) { if (!pMonitor) {
refocus(); refocus();
return; return;

View file

@ -104,7 +104,7 @@ class CInputManager {
Vector2D getMouseCoordsInternal(); Vector2D getMouseCoordsInternal();
void refocus(); void refocus();
void refocusLastWindow(CMonitor* pMonitor); void refocusLastWindow(PHLMONITOR pMonitor);
void simulateMouseMovement(); void simulateMouseMovement();
void sendMotionEventsToFocused(); void sendMotionEventsToFocused();

View file

@ -102,7 +102,7 @@ void CInputPopup::updateBox() {
Vector2D currentPopupSize = surface->getViewporterCorrectedSize(); Vector2D currentPopupSize = surface->getViewporterCorrectedSize();
CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle()); PHLMONITOR pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle());
Vector2D popupOffset(0, 0); Vector2D popupOffset(0, 0);

View file

@ -33,7 +33,7 @@ void CInputManager::beginWorkspaceSwipe() {
m_sActiveSwipe.pWorkspaceBegin = PWORKSPACE; m_sActiveSwipe.pWorkspaceBegin = PWORKSPACE;
m_sActiveSwipe.delta = 0; m_sActiveSwipe.delta = 0;
m_sActiveSwipe.pMonitor = g_pCompositor->m_pLastMonitor.get(); m_sActiveSwipe.pMonitor = g_pCompositor->m_pLastMonitor.lock();
m_sActiveSwipe.avgSpeed = 0; m_sActiveSwipe.avgSpeed = 0;
m_sActiveSwipe.speedPoints = 0; m_sActiveSwipe.speedPoints = 0;

View file

@ -17,7 +17,7 @@ void CInputManager::onTouchDown(ITouch::SDownEvent e) {
auto PMONITOR = g_pCompositor->getMonitorFromName(!e.device->boundOutput.empty() ? e.device->boundOutput : ""); auto PMONITOR = g_pCompositor->getMonitorFromName(!e.device->boundOutput.empty() ? e.device->boundOutput : "");
PMONITOR = PMONITOR ? PMONITOR : g_pCompositor->m_pLastMonitor.get(); PMONITOR = PMONITOR ? PMONITOR : g_pCompositor->m_pLastMonitor.lock();
g_pCompositor->warpCursorTo({PMONITOR->vecPosition.x + e.pos.x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e.pos.y * PMONITOR->vecSize.y}, true); g_pCompositor->warpCursorTo({PMONITOR->vecPosition.x + e.pos.x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e.pos.y * PMONITOR->vecSize.y}, true);

View file

@ -46,7 +46,7 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
if (PWINDOW->m_pWorkspace != monitor->activeWorkspace) { if (PWINDOW->m_pWorkspace != monitor->activeWorkspace) {
g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, monitor->activeWorkspace); g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, monitor->activeWorkspace);
g_pCompositor->setActiveMonitor(monitor.get()); g_pCompositor->setActiveMonitor(monitor);
} }
} }
} }
@ -118,7 +118,7 @@ wl_resource* CForeignToplevelHandleWlr::res() {
return resource->resource(); return resource->resource();
} }
void CForeignToplevelHandleWlr::sendMonitor(CMonitor* pMonitor) { void CForeignToplevelHandleWlr::sendMonitor(PHLMONITOR pMonitor) {
if (lastMonitorID == (int64_t)pMonitor->ID) if (lastMonitorID == (int64_t)pMonitor->ID)
return; return;

View file

@ -22,7 +22,7 @@ class CForeignToplevelHandleWlr {
bool closed = false; bool closed = false;
int64_t lastMonitorID = -1; int64_t lastMonitorID = -1;
void sendMonitor(CMonitor* pMonitor); void sendMonitor(PHLMONITOR pMonitor);
void sendState(); void sendState();
friend class CForeignToplevelWlrManager; friend class CForeignToplevelWlrManager;

View file

@ -19,7 +19,7 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out
return; return;
} }
pMonitor = OUTPUTRES->monitor.get(); pMonitor = OUTPUTRES->monitor.lock();
if (!pMonitor) { if (!pMonitor) {
LOGM(ERR, "No CMonitor"); LOGM(ERR, "No CMonitor");
@ -124,16 +124,16 @@ void CGammaControl::applyToMonitor() {
wlr_output_state_set_gamma_lut(pMonitor->state.wlr(), 0, nullptr, nullptr, nullptr); wlr_output_state_set_gamma_lut(pMonitor->state.wlr(), 0, nullptr, nullptr, nullptr);
} }
g_pHyprRenderer->damageMonitor(pMonitor); g_pHyprRenderer->damageMonitor(pMonitor.lock());
} }
CMonitor* CGammaControl::getMonitor() { PHLMONITOR CGammaControl::getMonitor() {
return pMonitor; return pMonitor.lock();
} }
void CGammaControl::onMonitorDestroy() { void CGammaControl::onMonitorDestroy() {
resource->sendFailed(); resource->sendFailed();
pMonitor = nullptr; pMonitor.reset();
} }
CGammaControlProtocol::CGammaControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CGammaControlProtocol::CGammaControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -167,7 +167,7 @@ void CGammaControlProtocol::onGetGammaControl(CZwlrGammaControlManagerV1* pMgr,
} }
} }
void CGammaControlProtocol::applyGammaToState(CMonitor* pMonitor) { void CGammaControlProtocol::applyGammaToState(PHLMONITOR pMonitor) {
for (auto& g : m_vGammaControllers) { for (auto& g : m_vGammaControllers) {
if (g->getMonitor() != pMonitor) if (g->getMonitor() != pMonitor)
continue; continue;

View file

@ -16,11 +16,11 @@ class CGammaControl {
bool good(); bool good();
void applyToMonitor(); void applyToMonitor();
CMonitor* getMonitor(); PHLMONITOR getMonitor();
private: private:
SP<CZwlrGammaControlV1> resource; SP<CZwlrGammaControlV1> resource;
CMonitor* pMonitor = nullptr; PHLMONITORREF pMonitor;
size_t gammaSize = 0; size_t gammaSize = 0;
bool gammaTableSet = false; bool gammaTableSet = false;
std::vector<uint16_t> gammaTable; std::vector<uint16_t> gammaTable;
@ -39,7 +39,7 @@ class CGammaControlProtocol : public IWaylandProtocol {
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
void applyGammaToState(CMonitor* pMonitor); void applyGammaToState(PHLMONITOR pMonitor);
private: private:
void onManagerResourceDestroy(wl_resource* res); void onManagerResourceDestroy(wl_resource* res);

View file

@ -16,8 +16,10 @@ void CLayerShellResource::SState::reset() {
margin = {0, 0, 0, 0}; margin = {0, 0, 0, 0};
} }
CLayerShellResource::CLayerShellResource(SP<CZwlrLayerSurfaceV1> resource_, SP<CWLSurfaceResource> surf_, std::string namespace_, CMonitor* pMonitor, zwlrLayerShellV1Layer layer) : CLayerShellResource::CLayerShellResource(SP<CZwlrLayerSurfaceV1> resource_, SP<CWLSurfaceResource> surf_, std::string namespace_, PHLMONITOR pMonitor,
layerNamespace(namespace_), surface(surf_), resource(resource_) { zwlrLayerShellV1Layer layer) :
layerNamespace(namespace_),
surface(surf_), resource(resource_) {
if (!good()) if (!good())
return; return;
@ -212,7 +214,7 @@ void CLayerShellProtocol::destroyResource(CLayerShellResource* surf) {
void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id, wl_resource* surface, wl_resource* output, zwlrLayerShellV1Layer layer, std::string namespace_) { void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id, wl_resource* surface, wl_resource* output, zwlrLayerShellV1Layer layer, std::string namespace_) {
const auto CLIENT = pMgr->client(); const auto CLIENT = pMgr->client();
const auto PMONITOR = output ? CWLOutputResource::fromResource(output)->monitor.get() : nullptr; const auto PMONITOR = output ? CWLOutputResource::fromResource(output)->monitor.lock() : nullptr;
auto SURF = CWLSurfaceResource::fromResource(surface); auto SURF = CWLSurfaceResource::fromResource(surface);
if (!SURF) { if (!SURF) {

View file

@ -15,7 +15,7 @@ class CWLSurfaceResource;
class CLayerShellResource : public ISurfaceRole { class CLayerShellResource : public ISurfaceRole {
public: public:
CLayerShellResource(SP<CZwlrLayerSurfaceV1> resource_, SP<CWLSurfaceResource> surf_, std::string namespace_, CMonitor* pMonitor, zwlrLayerShellV1Layer layer); CLayerShellResource(SP<CZwlrLayerSurfaceV1> resource_, SP<CWLSurfaceResource> surf_, std::string namespace_, PHLMONITOR pMonitor, zwlrLayerShellV1Layer layer);
~CLayerShellResource(); ~CLayerShellResource();
bool good(); bool good();

View file

@ -29,12 +29,12 @@ COutputManager::COutputManager(SP<CZwlrOutputManagerV1> resource_) : resource(re
// send all heads at start // send all heads at start
for (auto& m : g_pCompositor->m_vRealMonitors) { for (auto& m : g_pCompositor->m_vRealMonitors) {
if (m.get() == g_pCompositor->m_pUnsafeOutput) if (m == g_pCompositor->m_pUnsafeOutput)
continue; continue;
LOGM(LOG, " | sending output head for {}", m->szName); LOGM(LOG, " | sending output head for {}", m->szName);
makeAndSendNewHead(m.get()); makeAndSendNewHead(m);
} }
sendDone(); sendDone();
@ -44,7 +44,7 @@ bool COutputManager::good() {
return resource->resource(); return resource->resource();
} }
void COutputManager::makeAndSendNewHead(CMonitor* pMonitor) { void COutputManager::makeAndSendNewHead(PHLMONITOR pMonitor) {
if (stopped) if (stopped)
return; return;
@ -63,7 +63,7 @@ void COutputManager::makeAndSendNewHead(CMonitor* pMonitor) {
RESOURCE->sendAllData(); RESOURCE->sendAllData();
} }
void COutputManager::ensureMonitorSent(CMonitor* pMonitor) { void COutputManager::ensureMonitorSent(PHLMONITOR pMonitor) {
if (pMonitor == g_pCompositor->m_pUnsafeOutput) if (pMonitor == g_pCompositor->m_pUnsafeOutput)
return; return;
@ -86,7 +86,7 @@ void COutputManager::sendDone() {
resource->sendDone(wl_display_next_serial(g_pCompositor->m_sWLDisplay)); resource->sendDone(wl_display_next_serial(g_pCompositor->m_sWLDisplay));
} }
COutputHead::COutputHead(SP<CZwlrOutputHeadV1> resource_, CMonitor* pMonitor_) : resource(resource_), pMonitor(pMonitor_) { COutputHead::COutputHead(SP<CZwlrOutputHeadV1> resource_, PHLMONITOR pMonitor_) : resource(resource_), pMonitor(pMonitor_) {
if (!good()) if (!good())
return; return;
@ -105,7 +105,7 @@ COutputHead::COutputHead(SP<CZwlrOutputHeadV1> resource_, CMonitor* pMonitor_) :
m->resource->sendFinished(); m->resource->sendFinished();
} }
pMonitor = nullptr; pMonitor.reset();
for (auto& m : PROTO::outputManagement->m_vManagers) { for (auto& m : PROTO::outputManagement->m_vManagers) {
m->sendDone(); m->sendDone();
} }
@ -221,8 +221,8 @@ void COutputHead::makeAndSendNewMode(wlr_output_mode* mode) {
RESOURCE->sendAllData(); RESOURCE->sendAllData();
} }
CMonitor* COutputHead::monitor() { PHLMONITOR COutputHead::monitor() {
return pMonitor; return pMonitor.lock();
} }
COutputMode::COutputMode(SP<CZwlrOutputModeV1> resource_, wlr_output_mode* mode_) : resource(resource_), mode(mode_) { COutputMode::COutputMode(SP<CZwlrOutputModeV1> resource_, wlr_output_mode* mode_) : resource(resource_), mode(mode_) {
@ -396,7 +396,7 @@ bool COutputConfiguration::applyTestConfiguration(bool test) {
return true; return true;
} }
COutputConfigurationHead::COutputConfigurationHead(SP<CZwlrOutputConfigurationHeadV1> resource_, CMonitor* pMonitor_) : resource(resource_), pMonitor(pMonitor_) { COutputConfigurationHead::COutputConfigurationHead(SP<CZwlrOutputConfigurationHeadV1> resource_, PHLMONITOR pMonitor_) : resource(resource_), pMonitor(pMonitor_) {
if (!good()) if (!good())
return; return;
@ -579,7 +579,7 @@ void COutputManagementProtocol::destroyResource(COutputConfigurationHead* resour
void COutputManagementProtocol::updateAllOutputs() { void COutputManagementProtocol::updateAllOutputs() {
for (auto& m : g_pCompositor->m_vRealMonitors) { for (auto& m : g_pCompositor->m_vRealMonitors) {
for (auto& mgr : m_vManagers) { for (auto& mgr : m_vManagers) {
mgr->ensureMonitorSent(m.get()); mgr->ensureMonitorSent(m);
} }
} }
} }

View file

@ -17,7 +17,7 @@ class COutputManager {
COutputManager(SP<CZwlrOutputManagerV1> resource_); COutputManager(SP<CZwlrOutputManagerV1> resource_);
bool good(); bool good();
void ensureMonitorSent(CMonitor* pMonitor); void ensureMonitorSent(PHLMONITOR pMonitor);
void sendDone(); void sendDone();
private: private:
@ -28,7 +28,7 @@ class COutputManager {
std::vector<WP<COutputHead>> heads; std::vector<WP<COutputHead>> heads;
void makeAndSendNewHead(CMonitor* pMonitor); void makeAndSendNewHead(PHLMONITOR pMonitor);
friend class COutputManagementProtocol; friend class COutputManagementProtocol;
}; };
@ -50,16 +50,16 @@ class COutputMode {
class COutputHead { class COutputHead {
public: public:
COutputHead(SP<CZwlrOutputHeadV1> resource_, CMonitor* pMonitor_); COutputHead(SP<CZwlrOutputHeadV1> resource_, PHLMONITOR pMonitor_);
bool good(); bool good();
void sendAllData(); // this has to be separate as we need to send the head first, then set the data void sendAllData(); // this has to be separate as we need to send the head first, then set the data
void updateMode(); void updateMode();
CMonitor* monitor(); PHLMONITOR monitor();
private: private:
SP<CZwlrOutputHeadV1> resource; SP<CZwlrOutputHeadV1> resource;
CMonitor* pMonitor = nullptr; PHLMONITORREF pMonitor;
void makeAndSendNewMode(wlr_output_mode* mode); void makeAndSendNewMode(wlr_output_mode* mode);
void sendCurrentMode(); void sendCurrentMode();
@ -77,7 +77,7 @@ class COutputHead {
class COutputConfigurationHead { class COutputConfigurationHead {
public: public:
COutputConfigurationHead(SP<CZwlrOutputConfigurationHeadV1> resource_, CMonitor* pMonitor_); COutputConfigurationHead(SP<CZwlrOutputConfigurationHeadV1> resource_, PHLMONITOR pMonitor_);
bool good(); bool good();
@ -106,7 +106,7 @@ class COutputConfigurationHead {
private: private:
SP<CZwlrOutputConfigurationHeadV1> resource; SP<CZwlrOutputConfigurationHeadV1> resource;
CMonitor* pMonitor = nullptr; PHLMONITOR pMonitor = nullptr;
struct { struct {
CHyprSignalListener monitorDestroy; CHyprSignalListener monitorDestroy;

View file

@ -4,7 +4,7 @@
#define LOGM PROTO::outputPower->protoLog #define LOGM PROTO::outputPower->protoLog
COutputPower::COutputPower(SP<CZwlrOutputPowerV1> resource_, CMonitor* pMonitor_) : resource(resource_), pMonitor(pMonitor_) { COutputPower::COutputPower(SP<CZwlrOutputPowerV1> resource_, PHLMONITOR pMonitor_) : resource(resource_), pMonitor(pMonitor_) {
if (!resource->resource()) if (!resource->resource())
return; return;
@ -26,7 +26,7 @@ COutputPower::COutputPower(SP<CZwlrOutputPowerV1> resource_, CMonitor* pMonitor_
resource->sendMode(pMonitor->dpmsStatus ? ZWLR_OUTPUT_POWER_V1_MODE_ON : ZWLR_OUTPUT_POWER_V1_MODE_OFF); resource->sendMode(pMonitor->dpmsStatus ? ZWLR_OUTPUT_POWER_V1_MODE_ON : ZWLR_OUTPUT_POWER_V1_MODE_OFF);
listeners.monitorDestroy = pMonitor->events.destroy.registerListener([this](std::any v) { listeners.monitorDestroy = pMonitor->events.destroy.registerListener([this](std::any v) {
pMonitor = nullptr; pMonitor.reset();
resource->sendFailed(); resource->sendFailed();
}); });
@ -70,7 +70,7 @@ void COutputPowerProtocol::onGetOutputPower(CZwlrOutputPowerManagerV1* pMgr, uin
} }
const auto CLIENT = pMgr->client(); const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vOutputPowers.emplace_back(std::make_unique<COutputPower>(makeShared<CZwlrOutputPowerV1>(CLIENT, pMgr->version(), id), OUTPUT->monitor.get())).get(); const auto RESOURCE = m_vOutputPowers.emplace_back(std::make_unique<COutputPower>(makeShared<CZwlrOutputPowerV1>(CLIENT, pMgr->version(), id), OUTPUT->monitor.lock())).get();
if (!RESOURCE->good()) { if (!RESOURCE->good()) {
pMgr->noMemory(); pMgr->noMemory();

View file

@ -11,14 +11,14 @@ class CMonitor;
class COutputPower { class COutputPower {
public: public:
COutputPower(SP<CZwlrOutputPowerV1> resource_, CMonitor* pMonitor); COutputPower(SP<CZwlrOutputPowerV1> resource_, PHLMONITOR pMonitor);
bool good(); bool good();
private: private:
SP<CZwlrOutputPowerV1> resource; SP<CZwlrOutputPowerV1> resource;
CMonitor* pMonitor = nullptr; PHLMONITORREF pMonitor;
struct { struct {
CHyprSignalListener monitorDestroy; CHyprSignalListener monitorDestroy;

View file

@ -14,7 +14,7 @@ void CQueuedPresentationData::setPresentationType(bool zeroCopy_) {
zeroCopy = zeroCopy_; zeroCopy = zeroCopy_;
} }
void CQueuedPresentationData::attachMonitor(CMonitor* pMonitor_) { void CQueuedPresentationData::attachMonitor(PHLMONITOR pMonitor_) {
pMonitor = pMonitor_; pMonitor = pMonitor_;
} }
@ -69,7 +69,7 @@ void CPresentationFeedback::sendQueued(SP<CQueuedPresentationData> data, timespe
CPresentationProtocol::CPresentationProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CPresentationProtocol::CPresentationProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) { static auto P = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
const auto PMONITOR = std::any_cast<CMonitor*>(param); const auto PMONITOR = std::any_cast<PHLMONITOR>(param);
std::erase_if(m_vQueue, [PMONITOR](const auto& other) { return !other->surface || other->pMonitor == PMONITOR; }); std::erase_if(m_vQueue, [PMONITOR](const auto& other) { return !other->surface || other->pMonitor == PMONITOR; });
}); });
} }
@ -103,7 +103,7 @@ void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* su
} }
} }
void CPresentationProtocol::onPresented(CMonitor* pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) { void CPresentationProtocol::onPresented(PHLMONITOR pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
for (auto& feedback : m_vFeedbacks) { for (auto& feedback : m_vFeedbacks) {
if (!feedback->surface) if (!feedback->surface)
continue; continue;

View file

@ -14,7 +14,7 @@ class CQueuedPresentationData {
CQueuedPresentationData(SP<CWLSurfaceResource> surf); CQueuedPresentationData(SP<CWLSurfaceResource> surf);
void setPresentationType(bool zeroCopy); void setPresentationType(bool zeroCopy);
void attachMonitor(CMonitor* pMonitor); void attachMonitor(PHLMONITOR pMonitor);
void presented(); void presented();
void discarded(); void discarded();
@ -22,7 +22,7 @@ class CQueuedPresentationData {
private: private:
bool wasPresented = false; bool wasPresented = false;
bool zeroCopy = false; bool zeroCopy = false;
CMonitor* pMonitor = nullptr; PHLMONITORREF pMonitor;
WP<CWLSurfaceResource> surface; WP<CWLSurfaceResource> surface;
DYNLISTENER(destroySurface); DYNLISTENER(destroySurface);
@ -53,7 +53,7 @@ class CPresentationProtocol : public IWaylandProtocol {
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
void onPresented(CMonitor* pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags); void onPresented(PHLMONITOR pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
void queueData(SP<CQueuedPresentationData> data); void queueData(SP<CQueuedPresentationData> data);
private: private:

View file

@ -216,7 +216,7 @@ void CScreencopyProtocolManager::captureOutput(wl_client* client, wl_resource* r
const auto PFRAME = &m_lFrames.emplace_back(); const auto PFRAME = &m_lFrames.emplace_back();
PFRAME->overlayCursor = !!overlay_cursor; PFRAME->overlayCursor = !!overlay_cursor;
PFRAME->resource = wl_resource_create(client, &zwlr_screencopy_frame_v1_interface, wl_resource_get_version(resource), frame); PFRAME->resource = wl_resource_create(client, &zwlr_screencopy_frame_v1_interface, wl_resource_get_version(resource), frame);
PFRAME->pMonitor = CWLOutputResource::fromResource(output)->monitor.get(); PFRAME->pMonitor = CWLOutputResource::fromResource(output)->monitor.lock();
if (!PFRAME->pMonitor) { if (!PFRAME->pMonitor) {
Debug::log(ERR, "client requested sharing of a monitor that doesnt exist"); Debug::log(ERR, "client requested sharing of a monitor that doesnt exist");
@ -250,7 +250,7 @@ void CScreencopyProtocolManager::captureOutput(wl_client* client, wl_resource* r
} else } else
Debug::log(ERR, "No RDATA in screencopy???"); Debug::log(ERR, "No RDATA in screencopy???");
PFRAME->shmFormat = g_pHyprOpenGL->getPreferredReadFormat(PFRAME->pMonitor); PFRAME->shmFormat = g_pHyprOpenGL->getPreferredReadFormat(PFRAME->pMonitor.lock());
if (PFRAME->shmFormat == DRM_FORMAT_INVALID) { if (PFRAME->shmFormat == DRM_FORMAT_INVALID) {
Debug::log(ERR, "No format supported by renderer in capture output"); Debug::log(ERR, "No format supported by renderer in capture output");
zwlr_screencopy_frame_v1_send_failed(PFRAME->resource); zwlr_screencopy_frame_v1_send_failed(PFRAME->resource);
@ -302,7 +302,7 @@ void CScreencopyProtocolManager::copyFrame(wl_client* client, wl_resource* resou
return; return;
} }
if (!g_pCompositor->monitorExists(PFRAME->pMonitor)) { if (PFRAME->pMonitor.expired()) {
Debug::log(ERR, "client requested sharing of a monitor that is gone"); Debug::log(ERR, "client requested sharing of a monitor that is gone");
zwlr_screencopy_frame_v1_send_failed(PFRAME->resource); zwlr_screencopy_frame_v1_send_failed(PFRAME->resource);
removeFrame(PFRAME); removeFrame(PFRAME);
@ -380,16 +380,16 @@ void CScreencopyProtocolManager::copyFrame(wl_client* client, wl_resource* resou
} }
if (!PFRAME->withDamage) if (!PFRAME->withDamage)
g_pHyprRenderer->damageMonitor(PFRAME->pMonitor); g_pHyprRenderer->damageMonitor(PFRAME->pMonitor.lock());
} }
void CScreencopyProtocolManager::onOutputCommit(CMonitor* pMonitor, wlr_output_event_commit* e) { void CScreencopyProtocolManager::onOutputCommit(PHLMONITOR pMonitor, wlr_output_event_commit* e) {
m_pLastMonitorBackBuffer = e->state->buffer; m_pLastMonitorBackBuffer = e->state->buffer;
shareAllFrames(pMonitor); shareAllFrames(pMonitor);
m_pLastMonitorBackBuffer = nullptr; m_pLastMonitorBackBuffer = nullptr;
} }
void CScreencopyProtocolManager::shareAllFrames(CMonitor* pMonitor) { void CScreencopyProtocolManager::shareAllFrames(PHLMONITOR pMonitor) {
if (m_vFramesAwaitingWrite.empty()) if (m_vFramesAwaitingWrite.empty())
return; // nothing to share return; // nothing to share
@ -489,7 +489,7 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
CFramebuffer fb; CFramebuffer fb;
fb.alloc(frame->box.w, frame->box.h, g_pHyprRenderer->isNvidia() ? DRM_FORMAT_XBGR8888 : frame->pMonitor->drmFormat); fb.alloc(frame->box.w, frame->box.h, g_pHyprRenderer->isNvidia() ? DRM_FORMAT_XBGR8888 : frame->pMonitor->drmFormat);
if (!g_pHyprRenderer->beginRender(frame->pMonitor, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &fb, true)) { if (!g_pHyprRenderer->beginRender(frame->pMonitor.lock(), fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &fb, true)) {
wlr_texture_destroy(sourceTex); wlr_texture_destroy(sourceTex);
return false; return false;
} }
@ -537,7 +537,7 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
} }
} }
g_pHyprOpenGL->m_RenderData.pMonitor = nullptr; g_pHyprOpenGL->m_RenderData.pMonitor.reset();
wlr_texture_destroy(sourceTex); wlr_texture_destroy(sourceTex);
@ -553,7 +553,7 @@ bool CScreencopyProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame) {
CRegion fakeDamage = {0, 0, INT16_MAX, INT16_MAX}; CRegion fakeDamage = {0, 0, INT16_MAX, INT16_MAX};
if (!g_pHyprRenderer->beginRender(frame->pMonitor, fakeDamage, RENDER_MODE_TO_BUFFER, frame->buffer.lock(), nullptr, true)) if (!g_pHyprRenderer->beginRender(frame->pMonitor.lock(), fakeDamage, RENDER_MODE_TO_BUFFER, frame->buffer.lock(), nullptr, true))
return false; return false;
CBox monbox = CBox{0, 0, frame->pMonitor->vecPixelSize.x, frame->pMonitor->vecPixelSize.y} CBox monbox = CBox{0, 0, frame->pMonitor->vecPixelSize.x, frame->pMonitor->vecPixelSize.y}

View file

@ -58,7 +58,7 @@ struct SScreencopyFrame {
WP<IWLBuffer> buffer; WP<IWLBuffer> buffer;
CMonitor* pMonitor = nullptr; PHLMONITORREF pMonitor;
PHLWINDOWREF pWindow; PHLWINDOWREF pWindow;
bool operator==(const SScreencopyFrame& other) const { bool operator==(const SScreencopyFrame& other) const {
@ -79,7 +79,7 @@ class CScreencopyProtocolManager {
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer); void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer);
void onOutputCommit(CMonitor* pMonitor, wlr_output_event_commit* e); void onOutputCommit(PHLMONITOR pMonitor, wlr_output_event_commit* e);
private: private:
wl_global* m_pGlobal = nullptr; wl_global* m_pGlobal = nullptr;
@ -95,7 +95,7 @@ class CScreencopyProtocolManager {
wlr_buffer* m_pLastMonitorBackBuffer = nullptr; wlr_buffer* m_pLastMonitorBackBuffer = nullptr;
void shareAllFrames(CMonitor* pMonitor); void shareAllFrames(PHLMONITOR pMonitor);
void shareFrame(SScreencopyFrame* frame); void shareFrame(SScreencopyFrame* frame);
void sendFrameDamage(SScreencopyFrame* frame); void sendFrameDamage(SScreencopyFrame* frame);
bool copyFrameDmabuf(SScreencopyFrame* frame); bool copyFrameDmabuf(SScreencopyFrame* frame);

View file

@ -7,7 +7,7 @@
#define LOGM PROTO::sessionLock->protoLog #define LOGM PROTO::sessionLock->protoLog
CSessionLockSurface::CSessionLockSurface(SP<CExtSessionLockSurfaceV1> resource_, SP<CWLSurfaceResource> surface_, CMonitor* pMonitor_, WP<CSessionLock> owner_) : CSessionLockSurface::CSessionLockSurface(SP<CExtSessionLockSurfaceV1> resource_, SP<CWLSurfaceResource> surface_, PHLMONITOR pMonitor_, WP<CSessionLock> owner_) :
resource(resource_), sessionLock(owner_), pSurface(surface_), pMonitor(pMonitor_) { resource(resource_), sessionLock(owner_), pSurface(surface_), pMonitor(pMonitor_) {
if (!resource->resource()) if (!resource->resource())
return; return;
@ -84,8 +84,8 @@ bool CSessionLockSurface::inert() {
return sessionLock.expired(); return sessionLock.expired();
} }
CMonitor* CSessionLockSurface::monitor() { PHLMONITOR CSessionLockSurface::monitor() {
return pMonitor; return pMonitor.lock();
} }
SP<CWLSurfaceResource> CSessionLockSurface::surface() { SP<CWLSurfaceResource> CSessionLockSurface::surface() {
@ -193,7 +193,7 @@ void CSessionLockProtocol::onGetLockSurface(CExtSessionLockV1* lock, uint32_t id
LOGM(LOG, "New sessionLockSurface with id {}", id); LOGM(LOG, "New sessionLockSurface with id {}", id);
auto PSURFACE = CWLSurfaceResource::fromResource(surface); auto PSURFACE = CWLSurfaceResource::fromResource(surface);
auto PMONITOR = CWLOutputResource::fromResource(output)->monitor.get(); auto PMONITOR = CWLOutputResource::fromResource(output)->monitor.lock();
SP<CSessionLock> sessionLock; SP<CSessionLock> sessionLock;
for (auto& l : m_vLocks) { for (auto& l : m_vLocks) {

View file

@ -13,12 +13,12 @@ class CWLSurfaceResource;
class CSessionLockSurface { class CSessionLockSurface {
public: public:
CSessionLockSurface(SP<CExtSessionLockSurfaceV1> resource_, SP<CWLSurfaceResource> surface_, CMonitor* pMonitor_, WP<CSessionLock> owner_); CSessionLockSurface(SP<CExtSessionLockSurfaceV1> resource_, SP<CWLSurfaceResource> surface_, PHLMONITOR pMonitor_, WP<CSessionLock> owner_);
~CSessionLockSurface(); ~CSessionLockSurface();
bool good(); bool good();
bool inert(); bool inert();
CMonitor* monitor(); PHLMONITOR monitor();
SP<CWLSurfaceResource> surface(); SP<CWLSurfaceResource> surface();
struct { struct {
@ -31,7 +31,7 @@ class CSessionLockSurface {
SP<CExtSessionLockSurfaceV1> resource; SP<CExtSessionLockSurfaceV1> resource;
WP<CSessionLock> sessionLock; WP<CSessionLock> sessionLock;
WP<CWLSurfaceResource> pSurface; WP<CWLSurfaceResource> pSurface;
CMonitor* pMonitor = nullptr; PHLMONITORREF pMonitor;
bool ackdConfigure = false; bool ackdConfigure = false;
bool committed = false; bool committed = false;

View file

@ -289,7 +289,7 @@ void CToplevelExportProtocolManager::copyFrame(wl_client* client, wl_resource* r
m_vFramesAwaitingWrite.emplace_back(PFRAME); m_vFramesAwaitingWrite.emplace_back(PFRAME);
} }
void CToplevelExportProtocolManager::onOutputCommit(CMonitor* pMonitor, wlr_output_event_commit* e) { void CToplevelExportProtocolManager::onOutputCommit(PHLMONITOR pMonitor, wlr_output_event_commit* e) {
if (m_vFramesAwaitingWrite.empty()) if (m_vFramesAwaitingWrite.empty())
return; // nothing to share return; // nothing to share

View file

@ -21,7 +21,7 @@ class CToplevelExportProtocolManager {
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer, int32_t ignore_damage); void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer, int32_t ignore_damage);
void displayDestroy(); void displayDestroy();
void onWindowUnmap(PHLWINDOW pWindow); void onWindowUnmap(PHLWINDOW pWindow);
void onOutputCommit(CMonitor* pMonitor, wlr_output_event_commit* e); void onOutputCommit(PHLMONITOR pMonitor, wlr_output_event_commit* e);
private: private:
wl_global* m_pGlobal = nullptr; wl_global* m_pGlobal = nullptr;

View file

@ -40,10 +40,10 @@ CXDGOutputProtocol::CXDGOutputProtocol(const wl_interface* iface, const int& ver
static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); }); static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); });
static auto P2 = g_pHookSystem->hookDynamic("configReloaded", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); }); static auto P2 = g_pHookSystem->hookDynamic("configReloaded", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); });
static auto P3 = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) { static auto P3 = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
const auto PMONITOR = std::any_cast<CMonitor*>(param); const auto PMONITOR = std::any_cast<PHLMONITOR>(param);
for (auto& o : m_vXDGOutputs) { for (auto& o : m_vXDGOutputs) {
if (o->monitor == PMONITOR) if (o->monitor == PMONITOR)
o->monitor = nullptr; o->monitor.reset();
} }
}); });
} }
@ -51,7 +51,7 @@ CXDGOutputProtocol::CXDGOutputProtocol(const wl_interface* iface, const int& ver
void CXDGOutputProtocol::onManagerGetXDGOutput(CZxdgOutputManagerV1* mgr, uint32_t id, wl_resource* outputResource) { void CXDGOutputProtocol::onManagerGetXDGOutput(CZxdgOutputManagerV1* mgr, uint32_t id, wl_resource* outputResource) {
const auto OUTPUT = CWLOutputResource::fromResource(outputResource); const auto OUTPUT = CWLOutputResource::fromResource(outputResource);
const auto PMONITOR = OUTPUT->monitor.get(); const auto PMONITOR = OUTPUT->monitor.lock();
const auto CLIENT = mgr->client(); const auto CLIENT = mgr->client();
@ -99,7 +99,7 @@ void CXDGOutputProtocol::updateAllOutputs() {
// //
CXDGOutput::CXDGOutput(SP<CZxdgOutputV1> resource_, CMonitor* monitor_) : monitor(monitor_), resource(resource_) { CXDGOutput::CXDGOutput(SP<CZxdgOutputV1> resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) {
if (!resource->resource()) if (!resource->resource())
return; return;

View file

@ -9,12 +9,12 @@ class CXDGOutputProtocol;
class CXDGOutput { class CXDGOutput {
public: public:
CXDGOutput(SP<CZxdgOutputV1> resource, CMonitor* monitor_); CXDGOutput(SP<CZxdgOutputV1> resource, PHLMONITOR monitor_);
void sendDetails(); void sendDetails();
private: private:
CMonitor* monitor = nullptr; PHLMONITORREF monitor;
SP<CZxdgOutputV1> resource; SP<CZxdgOutputV1> resource;
std::optional<Vector2D> overridePosition; std::optional<Vector2D> overridePosition;

View file

@ -211,7 +211,7 @@ wl_client* CWLSurfaceResource::client() {
return pClient; return pClient;
} }
void CWLSurfaceResource::enter(SP<CMonitor> monitor) { void CWLSurfaceResource::enter(PHLMONITOR monitor) {
if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) != enteredOutputs.end()) if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) != enteredOutputs.end())
return; return;
@ -233,7 +233,7 @@ void CWLSurfaceResource::enter(SP<CMonitor> monitor) {
resource->sendEnter(output->getResource().get()); resource->sendEnter(output->getResource().get());
} }
void CWLSurfaceResource::leave(SP<CMonitor> monitor) { void CWLSurfaceResource::leave(PHLMONITOR monitor) {
if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end()) if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end())
return; return;

View file

@ -59,8 +59,8 @@ class CWLSurfaceResource {
bool good(); bool good();
wl_client* client(); wl_client* client();
void enter(SP<CMonitor> monitor); void enter(PHLMONITOR monitor);
void leave(SP<CMonitor> monitor); void leave(PHLMONITOR monitor);
void sendPreferredTransform(wl_output_transform t); void sendPreferredTransform(wl_output_transform t);
void sendPreferredScale(int32_t scale); void sendPreferredScale(int32_t scale);
void frame(timespec* now); void frame(timespec* now);
@ -110,7 +110,7 @@ class CWLSurfaceResource {
std::vector<SP<CWLCallbackResource>> callbacks; std::vector<SP<CWLCallbackResource>> callbacks;
WP<CWLSurfaceResource> self; WP<CWLSurfaceResource> self;
WP<CWLSurface> hlSurface; WP<CWLSurface> hlSurface;
std::vector<WP<CMonitor>> enteredOutputs; std::vector<PHLMONITORREF> enteredOutputs;
bool mapped = false; bool mapped = false;
std::vector<WP<CWLSubsurfaceResource>> subsurfaces; std::vector<WP<CWLSubsurfaceResource>> subsurfaces;
WP<ISurfaceRole> role; WP<ISurfaceRole> role;

View file

@ -636,7 +636,7 @@ void CWLDataDeviceProtocol::abortDrag() {
g_pSeatManager->resendEnterEvents(); g_pSeatManager->resendEnterEvents();
} }
void CWLDataDeviceProtocol::renderDND(CMonitor* pMonitor, timespec* when) { void CWLDataDeviceProtocol::renderDND(PHLMONITOR pMonitor, timespec* when) {
if (!dnd.dndSurface || !dnd.dndSurface->current.buffer || !dnd.dndSurface->current.buffer->texture) if (!dnd.dndSurface || !dnd.dndSurface->current.buffer || !dnd.dndSurface->current.buffer->texture)
return; return;

View file

@ -128,7 +128,7 @@ class CWLDataDeviceProtocol : public IWaylandProtocol {
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
// renders and damages the dnd icon, if present // renders and damages the dnd icon, if present
void renderDND(CMonitor* pMonitor, timespec* when); void renderDND(PHLMONITOR pMonitor, timespec* when);
// for inputmgr to force refocus // for inputmgr to force refocus
// TODO: move handling to seatmgr // TODO: move handling to seatmgr
bool dndActive(); bool dndActive();

View file

@ -1,7 +1,7 @@
#include "Output.hpp" #include "Output.hpp"
#include "../../helpers/Monitor.hpp" #include "../../helpers/Monitor.hpp"
CWLOutputResource::CWLOutputResource(SP<CWlOutput> resource_, SP<CMonitor> pMonitor) : monitor(pMonitor), resource(resource_) { CWLOutputResource::CWLOutputResource(SP<CWlOutput> resource_, PHLMONITOR pMonitor) : monitor(pMonitor), resource(resource_) {
if (!good()) if (!good())
return; return;
@ -58,7 +58,7 @@ void CWLOutputResource::updateState() {
resource->sendDone(); resource->sendDone();
} }
CWLOutputProtocol::CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, SP<CMonitor> pMonitor) : CWLOutputProtocol::CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, PHLMONITOR pMonitor) :
IWaylandProtocol(iface, ver, name), monitor(pMonitor), szName(pMonitor->szName) { IWaylandProtocol(iface, ver, name), monitor(pMonitor), szName(pMonitor->szName) {
listeners.modeChanged = monitor->events.modeChanged.registerListener([this](std::any d) { listeners.modeChanged = monitor->events.modeChanged.registerListener([this](std::any d) {

View file

@ -11,7 +11,7 @@ class CMonitor;
class CWLOutputResource { class CWLOutputResource {
public: public:
CWLOutputResource(SP<CWlOutput> resource_, SP<CMonitor> pMonitor); CWLOutputResource(SP<CWlOutput> resource_, PHLMONITOR pMonitor);
static SP<CWLOutputResource> fromResource(wl_resource*); static SP<CWLOutputResource> fromResource(wl_resource*);
bool good(); bool good();
@ -19,7 +19,7 @@ class CWLOutputResource {
SP<CWlOutput> getResource(); SP<CWlOutput> getResource();
void updateState(); void updateState();
WP<CMonitor> monitor; PHLMONITORREF monitor;
WP<CWLOutputResource> self; WP<CWLOutputResource> self;
@ -30,13 +30,13 @@ class CWLOutputResource {
class CWLOutputProtocol : public IWaylandProtocol { class CWLOutputProtocol : public IWaylandProtocol {
public: public:
CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, SP<CMonitor> pMonitor); CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, PHLMONITOR pMonitor);
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
SP<CWLOutputResource> outputResourceFrom(wl_client* client); SP<CWLOutputResource> outputResourceFrom(wl_client* client);
WP<CMonitor> monitor; PHLMONITORREF monitor;
// will mark the protocol for removal, will be removed when no. of bound outputs is 0 (or when overwritten by a new global) // will mark the protocol for removal, will be removed when no. of bound outputs is 0 (or when overwritten by a new global)
void remove(); void remove();

View file

@ -72,7 +72,7 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() {
initDRMFormats(); initDRMFormats();
static auto P = g_pHookSystem->hookDynamic("preRender", [&](void* self, SCallbackInfo& info, std::any data) { preRender(std::any_cast<CMonitor*>(data)); }); static auto P = g_pHookSystem->hookDynamic("preRender", [&](void* self, SCallbackInfo& info, std::any data) { preRender(std::any_cast<PHLMONITOR>(data)); });
RASSERT(eglMakeCurrent(wlr_egl_get_display(g_pCompositor->m_sWLREGL), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT), "Couldn't unset current EGL!"); RASSERT(eglMakeCurrent(wlr_egl_get_display(g_pCompositor->m_sWLREGL), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT), "Couldn't unset current EGL!");
@ -329,7 +329,7 @@ GLuint CHyprOpenGLImpl::compileShader(const GLuint& type, std::string src, bool
return shader; return shader;
} }
bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { bool CHyprOpenGLImpl::passRequiresIntrospection(PHLMONITOR pMonitor) {
// passes requiring introspection are the ones that need to render blur. // passes requiring introspection are the ones that need to render blur.
static auto PBLUR = CConfigValue<Hyprlang::INT>("decoration:blur:enabled"); static auto PBLUR = CConfigValue<Hyprlang::INT>("decoration:blur:enabled");
@ -434,7 +434,7 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) {
return false; return false;
} }
void CHyprOpenGLImpl::beginSimple(CMonitor* pMonitor, const CRegion& damage, CRenderbuffer* rb, CFramebuffer* fb) { void CHyprOpenGLImpl::beginSimple(PHLMONITOR pMonitor, const CRegion& damage, CRenderbuffer* rb, CFramebuffer* fb) {
m_RenderData.pMonitor = pMonitor; m_RenderData.pMonitor = pMonitor;
#ifndef GLES2 #ifndef GLES2
@ -488,7 +488,7 @@ void CHyprOpenGLImpl::beginSimple(CMonitor* pMonitor, const CRegion& damage, CRe
m_RenderData.simplePass = true; m_RenderData.simplePass = true;
} }
void CHyprOpenGLImpl::begin(CMonitor* pMonitor, const CRegion& damage_, CFramebuffer* fb, std::optional<CRegion> finalDamage) { void CHyprOpenGLImpl::begin(PHLMONITOR pMonitor, const CRegion& damage_, CFramebuffer* fb, std::optional<CRegion> finalDamage) {
m_RenderData.pMonitor = pMonitor; m_RenderData.pMonitor = pMonitor;
static auto PFORCEINTROSPECTION = CConfigValue<Hyprlang::INT>("opengl:force_introspection"); static auto PFORCEINTROSPECTION = CConfigValue<Hyprlang::INT>("opengl:force_introspection");
@ -634,7 +634,7 @@ void CHyprOpenGLImpl::end() {
} }
// reset our data // reset our data
m_RenderData.pMonitor = nullptr; m_RenderData.pMonitor.reset();
m_RenderData.mouseZoomFactor = 1.f; m_RenderData.mouseZoomFactor = 1.f;
m_RenderData.mouseZoomUseMouse = true; m_RenderData.mouseZoomUseMouse = true;
m_RenderData.forceIntrospection = false; m_RenderData.forceIntrospection = false;
@ -1565,11 +1565,11 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o
return currentRenderToFB; return currentRenderToFB;
} }
void CHyprOpenGLImpl::markBlurDirtyForMonitor(CMonitor* pMonitor) { void CHyprOpenGLImpl::markBlurDirtyForMonitor(PHLMONITOR pMonitor) {
m_mMonitorRenderResources[pMonitor].blurFBDirty = true; m_mMonitorRenderResources[pMonitor].blurFBDirty = true;
} }
void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) { void CHyprOpenGLImpl::preRender(PHLMONITOR pMonitor) {
static auto PBLURNEWOPTIMIZE = CConfigValue<Hyprlang::INT>("decoration:blur:new_optimizations"); static auto PBLURNEWOPTIMIZE = CConfigValue<Hyprlang::INT>("decoration:blur:new_optimizations");
static auto PBLURXRAY = CConfigValue<Hyprlang::INT>("decoration:blur:xray"); static auto PBLURXRAY = CConfigValue<Hyprlang::INT>("decoration:blur:xray");
static auto PBLUR = CConfigValue<Hyprlang::INT>("decoration:blur:enabled"); static auto PBLUR = CConfigValue<Hyprlang::INT>("decoration:blur:enabled");
@ -2306,7 +2306,7 @@ void CHyprOpenGLImpl::renderSplash(cairo_t* const CAIRO, cairo_surface_t* const
cairo_surface_flush(CAIROSURFACE); cairo_surface_flush(CAIROSURFACE);
} }
void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) { void CHyprOpenGLImpl::createBGTextureForMonitor(PHLMONITOR pMonitor) {
RASSERT(m_RenderData.pMonitor, "Tried to createBGTex without begin()!"); RASSERT(m_RenderData.pMonitor, "Tried to createBGTex without begin()!");
static auto PRENDERTEX = CConfigValue<Hyprlang::INT>("misc:disable_hyprland_logo"); static auto PRENDERTEX = CConfigValue<Hyprlang::INT>("misc:disable_hyprland_logo");
@ -2445,7 +2445,7 @@ void CHyprOpenGLImpl::clearWithTex() {
auto TEXIT = m_mMonitorBGFBs.find(m_RenderData.pMonitor); auto TEXIT = m_mMonitorBGFBs.find(m_RenderData.pMonitor);
if (TEXIT == m_mMonitorBGFBs.end()) { if (TEXIT == m_mMonitorBGFBs.end()) {
createBGTextureForMonitor(m_RenderData.pMonitor); createBGTextureForMonitor(m_RenderData.pMonitor.lock());
TEXIT = m_mMonitorBGFBs.find(m_RenderData.pMonitor); TEXIT = m_mMonitorBGFBs.find(m_RenderData.pMonitor);
} }
@ -2457,7 +2457,7 @@ void CHyprOpenGLImpl::clearWithTex() {
} }
} }
void CHyprOpenGLImpl::destroyMonitorResources(CMonitor* pMonitor) { void CHyprOpenGLImpl::destroyMonitorResources(PHLMONITOR pMonitor) {
g_pHyprRenderer->makeEGLCurrent(); g_pHyprRenderer->makeEGLCurrent();
auto RESIT = g_pHyprOpenGL->m_mMonitorRenderResources.find(pMonitor); auto RESIT = g_pHyprOpenGL->m_mMonitorRenderResources.find(pMonitor);
@ -2518,7 +2518,7 @@ void CHyprOpenGLImpl::setRenderModifEnabled(bool enabled) {
m_RenderData.renderModif.enabled = enabled; m_RenderData.renderModif.enabled = enabled;
} }
uint32_t CHyprOpenGLImpl::getPreferredReadFormat(CMonitor* pMonitor) { uint32_t CHyprOpenGLImpl::getPreferredReadFormat(PHLMONITOR pMonitor) {
GLint glf = -1, glt = -1, as = 0; GLint glf = -1, glt = -1, as = 0;
/*glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glf); /*glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glf);
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glt); glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glt);

View file

@ -88,7 +88,7 @@ struct SMonitorRenderData {
}; };
struct SCurrentRenderData { struct SCurrentRenderData {
CMonitor* pMonitor = nullptr; PHLMONITORREF pMonitor;
PHLWORKSPACE pWorkspace = nullptr; PHLWORKSPACE pWorkspace = nullptr;
float projection[9]; float projection[9];
float savedProjection[9]; float savedProjection[9];
@ -125,8 +125,8 @@ class CHyprOpenGLImpl {
public: public:
CHyprOpenGLImpl(); CHyprOpenGLImpl();
void begin(CMonitor*, const CRegion& damage, CFramebuffer* fb = nullptr, std::optional<CRegion> finalDamage = {}); void begin(PHLMONITOR, const CRegion& damage, CFramebuffer* fb = nullptr, std::optional<CRegion> finalDamage = {});
void beginSimple(CMonitor*, const CRegion& damage, CRenderbuffer* rb = nullptr, CFramebuffer* fb = nullptr); void beginSimple(PHLMONITOR, const CRegion& damage, CRenderbuffer* rb = nullptr, CFramebuffer* fb = nullptr);
void end(); void end();
void renderRect(CBox*, const CColor&, int round = 0); void renderRect(CBox*, const CColor&, int round = 0);
@ -161,13 +161,13 @@ class CHyprOpenGLImpl {
void scissor(const pixman_box32*, bool transform = true); void scissor(const pixman_box32*, bool transform = true);
void scissor(const int x, const int y, const int w, const int h, bool transform = true); void scissor(const int x, const int y, const int w, const int h, bool transform = true);
void destroyMonitorResources(CMonitor*); void destroyMonitorResources(PHLMONITOR);
void markBlurDirtyForMonitor(CMonitor*); void markBlurDirtyForMonitor(PHLMONITOR);
void preWindowPass(); void preWindowPass();
bool preBlurQueued(); bool preBlurQueued();
void preRender(CMonitor*); void preRender(PHLMONITOR);
void saveBufferForMirror(CBox*); void saveBufferForMirror(CBox*);
void renderMirrored(); void renderMirrored();
@ -180,7 +180,7 @@ class CHyprOpenGLImpl {
void setDamage(const CRegion& damage, std::optional<CRegion> finalDamage = {}); void setDamage(const CRegion& damage, std::optional<CRegion> finalDamage = {});
uint32_t getPreferredReadFormat(CMonitor* pMonitor); uint32_t getPreferredReadFormat(PHLMONITOR pMonitor);
std::vector<SDRMFormat> getDRMFormats(); std::vector<SDRMFormat> getDRMFormats();
EGLImageKHR createEGLImage(const SDMABUFAttrs& attrs); EGLImageKHR createEGLImage(const SDMABUFAttrs& attrs);
@ -195,8 +195,8 @@ class CHyprOpenGLImpl {
std::map<PHLWINDOWREF, CFramebuffer> m_mWindowFramebuffers; std::map<PHLWINDOWREF, CFramebuffer> m_mWindowFramebuffers;
std::map<PHLLSREF, CFramebuffer> m_mLayerFramebuffers; std::map<PHLLSREF, CFramebuffer> m_mLayerFramebuffers;
std::unordered_map<CMonitor*, SMonitorRenderData> m_mMonitorRenderResources; std::map<PHLMONITORREF, SMonitorRenderData> m_mMonitorRenderResources;
std::unordered_map<CMonitor*, CFramebuffer> m_mMonitorBGFBs; std::map<PHLMONITORREF, CFramebuffer> m_mMonitorBGFBs;
struct { struct {
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES = nullptr; PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES = nullptr;
@ -235,7 +235,7 @@ class CHyprOpenGLImpl {
void logShaderError(const GLuint&, bool program = false); void logShaderError(const GLuint&, bool program = false);
GLuint createProgram(const std::string&, const std::string&, bool dynamic = false); GLuint createProgram(const std::string&, const std::string&, bool dynamic = false);
GLuint compileShader(const GLuint&, std::string, bool dynamic = false); GLuint compileShader(const GLuint&, std::string, bool dynamic = false);
void createBGTextureForMonitor(CMonitor*); void createBGTextureForMonitor(PHLMONITOR);
void initShaders(); void initShaders();
void initDRMFormats(); void initDRMFormats();
std::vector<uint64_t> getModsForFormat(EGLint format); std::vector<uint64_t> getModsForFormat(EGLint format);
@ -250,7 +250,7 @@ class CHyprOpenGLImpl {
void preBlurForCurrentMonitor(); void preBlurForCurrentMonitor();
bool passRequiresIntrospection(CMonitor* pMonitor); bool passRequiresIntrospection(PHLMONITOR pMonitor);
friend class CHyprRenderer; friend class CHyprRenderer;
}; };

View file

@ -232,7 +232,7 @@ static void renderSurface(SP<CWLSurfaceResource> surface, int x, int y, void* da
g_pHyprOpenGL->m_RenderData.useNearestNeighbor = NEARESTNEIGHBORSET; g_pHyprOpenGL->m_RenderData.useNearestNeighbor = NEARESTNEIGHBORSET;
} }
bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow, CMonitor* pMonitor) { bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor) {
if (!pWindow->visibleOnMonitor(pMonitor)) if (!pWindow->visibleOnMonitor(pMonitor))
return false; return false;
@ -321,7 +321,7 @@ bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow) {
return false; return false;
} }
void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time) { void CHyprRenderer::renderWorkspaceWindowsFullscreen(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* time) {
PHLWINDOW pWorkspaceWindow = nullptr; PHLWINDOW pWorkspaceWindow = nullptr;
EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS); EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS);
@ -411,7 +411,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, PHLWORK
} }
} }
void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time) { void CHyprRenderer::renderWorkspaceWindows(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* time) {
PHLWINDOW lastWindow; PHLWINDOW lastWindow;
EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS); EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS);
@ -483,7 +483,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWor
} }
} }
void CHyprRenderer::renderWindow(PHLWINDOW pWindow, CMonitor* pMonitor, timespec* time, bool decorate, eRenderPassMode mode, bool ignorePosition, bool ignoreAllGeometry) { void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespec* time, bool decorate, eRenderPassMode mode, bool ignorePosition, bool ignoreAllGeometry) {
if (pWindow->isHidden()) if (pWindow->isHidden())
return; return;
@ -691,7 +691,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, CMonitor* pMonitor, timespec
g_pHyprOpenGL->m_RenderData.clipBox = CBox(); g_pHyprOpenGL->m_RenderData.clipBox = CBox();
} }
void CHyprRenderer::renderLayer(PHLLS pLayer, CMonitor* pMonitor, timespec* time, bool popups) { void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, timespec* time, bool popups) {
static auto PDIMAROUND = CConfigValue<Hyprlang::FLOAT>("decoration:dim_around"); static auto PDIMAROUND = CConfigValue<Hyprlang::FLOAT>("decoration:dim_around");
if (*PDIMAROUND && pLayer->dimAround && !m_bRenderingSnapshot && !popups) { if (*PDIMAROUND && pLayer->dimAround && !m_bRenderingSnapshot && !popups) {
@ -756,7 +756,7 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, CMonitor* pMonitor, timespec* time
g_pHyprOpenGL->m_RenderData.discardOpacity = DA; g_pHyprOpenGL->m_RenderData.discardOpacity = DA;
} }
void CHyprRenderer::renderIMEPopup(CInputPopup* pPopup, CMonitor* pMonitor, timespec* time) { void CHyprRenderer::renderIMEPopup(CInputPopup* pPopup, PHLMONITOR pMonitor, timespec* time) {
const auto POS = pPopup->globalBox().pos(); const auto POS = pPopup->globalBox().pos();
SRenderData renderdata = {pMonitor, time, POS.x, POS.y}; SRenderData renderdata = {pMonitor, time, POS.x, POS.y};
@ -772,7 +772,7 @@ void CHyprRenderer::renderIMEPopup(CInputPopup* pPopup, CMonitor* pMonitor, time
SURF->breadthfirst([](SP<CWLSurfaceResource> s, const Vector2D& offset, void* data) { renderSurface(s, offset.x, offset.y, data); }, &renderdata); SURF->breadthfirst([](SP<CWLSurfaceResource> s, const Vector2D& offset, void* data) { renderSurface(s, offset.x, offset.y, data); }, &renderdata);
} }
void CHyprRenderer::renderSessionLockSurface(SSessionLockSurface* pSurface, CMonitor* pMonitor, timespec* time) { void CHyprRenderer::renderSessionLockSurface(SSessionLockSurface* pSurface, PHLMONITOR pMonitor, timespec* time) {
SRenderData renderdata = {pMonitor, time, pMonitor->vecPosition.x, pMonitor->vecPosition.y}; SRenderData renderdata = {pMonitor, time, pMonitor->vecPosition.x, pMonitor->vecPosition.y};
renderdata.blur = false; renderdata.blur = false;
@ -784,7 +784,7 @@ void CHyprRenderer::renderSessionLockSurface(SSessionLockSurface* pSurface, CMon
renderdata.surface->breadthfirst([](SP<CWLSurfaceResource> s, const Vector2D& offset, void* data) { renderSurface(s, offset.x, offset.y, data); }, &renderdata); renderdata.surface->breadthfirst([](SP<CWLSurfaceResource> s, const Vector2D& offset, void* data) { renderSurface(s, offset.x, offset.y, data); }, &renderdata);
} }
void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time, const Vector2D& translate, const float& scale) { void CHyprRenderer::renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* time, const Vector2D& translate, const float& scale) {
static auto PDIMSPECIAL = CConfigValue<Hyprlang::FLOAT>("decoration:dim_special"); static auto PDIMSPECIAL = CConfigValue<Hyprlang::FLOAT>("decoration:dim_special");
static auto PBLURSPECIAL = CConfigValue<Hyprlang::INT>("decoration:blur:special"); static auto PBLURSPECIAL = CConfigValue<Hyprlang::INT>("decoration:blur:special");
static auto PBLUR = CConfigValue<Hyprlang::INT>("decoration:blur:enabled"); static auto PBLUR = CConfigValue<Hyprlang::INT>("decoration:blur:enabled");
@ -958,7 +958,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC
g_pHyprOpenGL->m_RenderData.renderModif = {}; g_pHyprOpenGL->m_RenderData.renderModif = {};
} }
void CHyprRenderer::renderLockscreen(CMonitor* pMonitor, timespec* now, const CBox& geometry) { void CHyprRenderer::renderLockscreen(PHLMONITOR pMonitor, timespec* now, const CBox& geometry) {
TRACY_GPU_ZONE("RenderLockscreen"); TRACY_GPU_ZONE("RenderLockscreen");
if (g_pSessionLockManager->isSessionLocked()) { if (g_pSessionLockManager->isSessionLocked()) {
@ -1061,7 +1061,7 @@ void CHyprRenderer::calculateUVForSurface(PHLWINDOW pWindow, SP<CWLSurfaceResour
} }
} }
bool CHyprRenderer::attemptDirectScanout(CMonitor* pMonitor) { bool CHyprRenderer::attemptDirectScanout(PHLMONITOR pMonitor) {
return false; // FIXME: fix when we move to new lib for backend. return false; // FIXME: fix when we move to new lib for backend.
// if (!pMonitor->mirrors.empty() || pMonitor->isMirror() || m_bDirectScanoutBlocked) // if (!pMonitor->mirrors.empty() || pMonitor->isMirror() || m_bDirectScanoutBlocked)
@ -1108,7 +1108,7 @@ bool CHyprRenderer::attemptDirectScanout(CMonitor* pMonitor) {
// return true; // return true;
} }
void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { void CHyprRenderer::renderMonitor(PHLMONITOR pMonitor) {
static std::chrono::high_resolution_clock::time_point renderStart = std::chrono::high_resolution_clock::now(); static std::chrono::high_resolution_clock::time_point renderStart = std::chrono::high_resolution_clock::now();
static std::chrono::high_resolution_clock::time_point renderStartOverlay = std::chrono::high_resolution_clock::now(); static std::chrono::high_resolution_clock::time_point renderStartOverlay = std::chrono::high_resolution_clock::now();
static std::chrono::high_resolution_clock::time_point endRenderOverlay = std::chrono::high_resolution_clock::now(); static std::chrono::high_resolution_clock::time_point endRenderOverlay = std::chrono::high_resolution_clock::now();
@ -1334,13 +1334,13 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
renderLockscreen(pMonitor, &now, renderBox); renderLockscreen(pMonitor, &now, renderBox);
if (pMonitor == g_pCompositor->m_pLastMonitor.get()) { if (pMonitor == g_pCompositor->m_pLastMonitor.lock()) {
g_pHyprNotificationOverlay->draw(pMonitor); g_pHyprNotificationOverlay->draw(pMonitor);
g_pHyprError->draw(); g_pHyprError->draw();
} }
// for drawing the debug overlay // for drawing the debug overlay
if (pMonitor == g_pCompositor->m_vMonitors.front().get() && *PDEBUGOVERLAY == 1) { if (pMonitor == g_pCompositor->m_vMonitors.front() && *PDEBUGOVERLAY == 1) {
renderStartOverlay = std::chrono::high_resolution_clock::now(); renderStartOverlay = std::chrono::high_resolution_clock::now();
g_pDebugOverlay->draw(); g_pDebugOverlay->draw();
endRenderOverlay = std::chrono::high_resolution_clock::now(); endRenderOverlay = std::chrono::high_resolution_clock::now();
@ -1415,7 +1415,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
g_pDebugOverlay->renderData(pMonitor, µs); g_pDebugOverlay->renderData(pMonitor, µs);
if (*PDEBUGOVERLAY == 1) { if (*PDEBUGOVERLAY == 1) {
if (pMonitor == g_pCompositor->m_vMonitors.front().get()) { if (pMonitor == g_pCompositor->m_vMonitors.front()) {
const float µsNoOverlay = µs - std::chrono::duration_cast<std::chrono::nanoseconds>(endRenderOverlay - renderStartOverlay).count() / 1000.f; const float µsNoOverlay = µs - std::chrono::duration_cast<std::chrono::nanoseconds>(endRenderOverlay - renderStartOverlay).count() / 1000.f;
g_pDebugOverlay->renderDataNoOverlay(pMonitor, µsNoOverlay); g_pDebugOverlay->renderDataNoOverlay(pMonitor, µsNoOverlay);
} else { } else {
@ -1424,7 +1424,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
} }
} }
void CHyprRenderer::renderWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const CBox& geometry) { void CHyprRenderer::renderWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const CBox& geometry) {
Vector2D translate = {geometry.x, geometry.y}; Vector2D translate = {geometry.x, geometry.y};
float scale = (float)geometry.width / pMonitor->vecPixelSize.x; float scale = (float)geometry.width / pMonitor->vecPixelSize.x;
@ -1441,7 +1441,7 @@ void CHyprRenderer::renderWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace,
g_pHyprOpenGL->m_RenderData.pWorkspace = nullptr; g_pHyprOpenGL->m_RenderData.pWorkspace = nullptr;
} }
void CHyprRenderer::sendFrameEventsToWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now) { void CHyprRenderer::sendFrameEventsToWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* now) {
for (auto& w : g_pCompositor->m_vWindows) { for (auto& w : g_pCompositor->m_vWindows) {
if (w->isHidden() || !w->m_bIsMapped || w->m_bFadingOut || !w->m_pWLSurface->resource()) if (w->isHidden() || !w->m_bIsMapped || w->m_bFadingOut || !w->m_pWLSurface->resource())
continue; continue;
@ -1550,7 +1550,7 @@ static void applyExclusive(wlr_box& usableArea, uint32_t anchor, int32_t exclusi
} }
} }
void CHyprRenderer::arrangeLayerArray(CMonitor* pMonitor, const std::vector<PHLLSREF>& layerSurfaces, bool exclusiveZone, CBox* usableArea) { void CHyprRenderer::arrangeLayerArray(PHLMONITOR pMonitor, const std::vector<PHLLSREF>& layerSurfaces, bool exclusiveZone, CBox* usableArea) {
CBox full_area = {pMonitor->vecPosition.x, pMonitor->vecPosition.y, pMonitor->vecSize.x, pMonitor->vecSize.y}; CBox full_area = {pMonitor->vecPosition.x, pMonitor->vecPosition.y, pMonitor->vecSize.x, pMonitor->vecSize.y};
for (auto& ls : layerSurfaces) { for (auto& ls : layerSurfaces) {
@ -1729,7 +1729,7 @@ void CHyprRenderer::damageWindow(PHLWINDOW pWindow, bool forceFull) {
windowBox.translate(pWindow->m_vFloatingOffset); windowBox.translate(pWindow->m_vFloatingOffset);
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
if (forceFull || g_pHyprRenderer->shouldRenderWindow(pWindow, m.get())) { // only damage if window is rendered on monitor if (forceFull || g_pHyprRenderer->shouldRenderWindow(pWindow, m)) { // only damage if window is rendered on monitor
CBox fixedDamageBox = {windowBox.x - m->vecPosition.x, windowBox.y - m->vecPosition.y, windowBox.width, windowBox.height}; CBox fixedDamageBox = {windowBox.x - m->vecPosition.x, windowBox.y - m->vecPosition.y, windowBox.width, windowBox.height};
fixedDamageBox.scale(m->scale); fixedDamageBox.scale(m->scale);
m->addDamage(&fixedDamageBox); m->addDamage(&fixedDamageBox);
@ -1745,7 +1745,7 @@ void CHyprRenderer::damageWindow(PHLWINDOW pWindow, bool forceFull) {
Debug::log(LOG, "Damage: Window ({}): xy: {}, {} wh: {}, {}", pWindow->m_szTitle, windowBox.x, windowBox.y, windowBox.width, windowBox.height); Debug::log(LOG, "Damage: Window ({}): xy: {}, {} wh: {}, {}", pWindow->m_szTitle, windowBox.x, windowBox.y, windowBox.width, windowBox.height);
} }
void CHyprRenderer::damageMonitor(CMonitor* pMonitor) { void CHyprRenderer::damageMonitor(PHLMONITOR pMonitor) {
if (g_pCompositor->m_bUnsafeState || pMonitor->isMirror()) if (g_pCompositor->m_bUnsafeState || pMonitor->isMirror())
return; return;
@ -1788,7 +1788,7 @@ void CHyprRenderer::damageRegion(const CRegion& rg) {
} }
} }
void CHyprRenderer::damageMirrorsWith(CMonitor* pMonitor, const CRegion& pRegion) { void CHyprRenderer::damageMirrorsWith(PHLMONITOR pMonitor, const CRegion& pRegion) {
for (auto& mirror : pMonitor->mirrors) { for (auto& mirror : pMonitor->mirrors) {
// transform the damage here, so it won't get clipped by the monitor damage ring // transform the damage here, so it won't get clipped by the monitor damage ring
@ -1809,11 +1809,11 @@ void CHyprRenderer::damageMirrorsWith(CMonitor* pMonitor, const CRegion& pRegion
mirror->addDamage(&transformed); mirror->addDamage(&transformed);
g_pCompositor->scheduleFrameForMonitor(mirror); g_pCompositor->scheduleFrameForMonitor(mirror.lock());
} }
} }
void CHyprRenderer::renderDragIcon(CMonitor* pMonitor, timespec* time) { void CHyprRenderer::renderDragIcon(PHLMONITOR pMonitor, timespec* time) {
PROTO::data->renderDND(pMonitor, time); PROTO::data->renderDND(pMonitor, time);
} }
@ -1828,7 +1828,7 @@ DAMAGETRACKINGMODES CHyprRenderer::damageTrackingModeFromStr(const std::string&
return DAMAGE_TRACKING_INVALID; return DAMAGE_TRACKING_INVALID;
} }
bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorRule, bool force) { bool CHyprRenderer::applyMonitorRule(PHLMONITOR pMonitor, SMonitorRule* pMonitorRule, bool force) {
static auto PDISABLESCALECHECKS = CConfigValue<Hyprlang::INT>("debug:disable_scale_checks"); static auto PDISABLESCALECHECKS = CConfigValue<Hyprlang::INT>("debug:disable_scale_checks");
@ -2315,7 +2315,7 @@ void CHyprRenderer::ensureCursorRenderingMode() {
if (m->output->software_cursor_locks == 0) if (m->output->software_cursor_locks == 0)
continue; continue;
g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? g_pHyprRenderer->damageMonitor(m); // TODO: maybe just damage the cursor area?
} }
setCursorHidden(true); setCursorHidden(true);
@ -2327,7 +2327,7 @@ void CHyprRenderer::ensureCursorRenderingMode() {
if (m->output->software_cursor_locks == 0) if (m->output->software_cursor_locks == 0)
continue; continue;
g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? g_pHyprRenderer->damageMonitor(m); // TODO: maybe just damage the cursor area?
} }
setCursorHidden(false); setCursorHidden(false);
@ -2358,7 +2358,7 @@ bool CHyprRenderer::shouldRenderCursor() {
return !m_bCursorHidden && m_bCursorHasSurface; return !m_bCursorHidden && m_bCursorHasSurface;
} }
std::tuple<float, float, float> CHyprRenderer::getRenderTimes(CMonitor* pMonitor) { std::tuple<float, float, float> CHyprRenderer::getRenderTimes(PHLMONITOR pMonitor) {
const auto POVERLAY = &g_pDebugOverlay->m_mMonitorOverlays[pMonitor]; const auto POVERLAY = &g_pDebugOverlay->m_mMonitorOverlays[pMonitor];
float avgRenderTime = 0; float avgRenderTime = 0;
@ -2463,7 +2463,7 @@ void CHyprRenderer::setOccludedForBackLayers(CRegion& region, PHLWORKSPACE pWork
region.subtract(rg); region.subtract(rg);
} }
bool CHyprRenderer::canSkipBackBufferClear(CMonitor* pMonitor) { bool CHyprRenderer::canSkipBackBufferClear(PHLMONITOR pMonitor) {
for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) { for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) {
if (!ls->layerSurface) if (!ls->layerSurface)
continue; continue;
@ -2489,7 +2489,7 @@ bool CHyprRenderer::canSkipBackBufferClear(CMonitor* pMonitor) {
return false; return false;
} }
void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) { void CHyprRenderer::recheckSolitaryForMonitor(PHLMONITOR pMonitor) {
pMonitor->solitaryClient.reset(); // reset it, if we find one it will be set. pMonitor->solitaryClient.reset(); // reset it, if we find one it will be set.
if (g_pHyprNotificationOverlay->hasAny() || g_pSessionLockManager->isSessionLocked()) if (g_pHyprNotificationOverlay->hasAny() || g_pSessionLockManager->isSessionLocked())
@ -2577,7 +2577,7 @@ void CHyprRenderer::unsetEGL() {
eglMakeCurrent(wlr_egl_get_display(g_pCompositor->m_sWLREGL), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(wlr_egl_get_display(g_pCompositor->m_sWLREGL), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
} }
bool CHyprRenderer::beginRender(CMonitor* pMonitor, CRegion& damage, eRenderMode mode, SP<IWLBuffer> buffer, CFramebuffer* fb, bool simple) { bool CHyprRenderer::beginRender(PHLMONITOR pMonitor, CRegion& damage, eRenderMode mode, SP<IWLBuffer> buffer, CFramebuffer* fb, bool simple) {
makeEGLCurrent(); makeEGLCurrent();
@ -2639,7 +2639,7 @@ void CHyprRenderer::endRender() {
if (m_eRenderMode != RENDER_MODE_TO_BUFFER_READ_ONLY) if (m_eRenderMode != RENDER_MODE_TO_BUFFER_READ_ONLY)
g_pHyprOpenGL->end(); g_pHyprOpenGL->end();
else { else {
g_pHyprOpenGL->m_RenderData.pMonitor = nullptr; g_pHyprOpenGL->m_RenderData.pMonitor.reset();
g_pHyprOpenGL->m_RenderData.mouseZoomFactor = 1.f; g_pHyprOpenGL->m_RenderData.mouseZoomFactor = 1.f;
g_pHyprOpenGL->m_RenderData.mouseZoomUseMouse = true; g_pHyprOpenGL->m_RenderData.mouseZoomUseMouse = true;
} }

View file

@ -43,28 +43,28 @@ class CHyprRenderer {
public: public:
CHyprRenderer(); CHyprRenderer();
void renderMonitor(CMonitor* pMonitor); void renderMonitor(PHLMONITOR pMonitor);
void arrangeLayersForMonitor(const int&); void arrangeLayersForMonitor(const int&);
void damageSurface(SP<CWLSurfaceResource>, double, double, double scale = 1.0); void damageSurface(SP<CWLSurfaceResource>, double, double, double scale = 1.0);
void damageWindow(PHLWINDOW, bool forceFull = false); void damageWindow(PHLWINDOW, bool forceFull = false);
void damageBox(CBox*); void damageBox(CBox*);
void damageBox(const int& x, const int& y, const int& w, const int& h); void damageBox(const int& x, const int& y, const int& w, const int& h);
void damageRegion(const CRegion&); void damageRegion(const CRegion&);
void damageMonitor(CMonitor*); void damageMonitor(PHLMONITOR);
void damageMirrorsWith(CMonitor*, const CRegion&); void damageMirrorsWith(PHLMONITOR, const CRegion&);
bool applyMonitorRule(CMonitor*, SMonitorRule*, bool force = false); bool applyMonitorRule(PHLMONITOR, SMonitorRule*, bool force = false);
bool shouldRenderWindow(PHLWINDOW, CMonitor*); bool shouldRenderWindow(PHLWINDOW, PHLMONITOR);
bool shouldRenderWindow(PHLWINDOW); bool shouldRenderWindow(PHLWINDOW);
void ensureCursorRenderingMode(); void ensureCursorRenderingMode();
bool shouldRenderCursor(); bool shouldRenderCursor();
void setCursorHidden(bool hide); void setCursorHidden(bool hide);
void calculateUVForSurface(PHLWINDOW, SP<CWLSurfaceResource>, bool main = false, const Vector2D& projSize = {}, bool fixMisalignedFSV1 = false); void calculateUVForSurface(PHLWINDOW, SP<CWLSurfaceResource>, bool main = false, const Vector2D& projSize = {}, bool fixMisalignedFSV1 = false);
std::tuple<float, float, float> getRenderTimes(CMonitor* pMonitor); // avg max min std::tuple<float, float, float> getRenderTimes(PHLMONITOR pMonitor); // avg max min
void renderLockscreen(CMonitor* pMonitor, timespec* now, const CBox& geometry); void renderLockscreen(PHLMONITOR pMonitor, timespec* now, const CBox& geometry);
void setOccludedForBackLayers(CRegion& region, PHLWORKSPACE pWorkspace); void setOccludedForBackLayers(CRegion& region, PHLWORKSPACE pWorkspace);
void setOccludedForMainWorkspace(CRegion& region, PHLWORKSPACE pWorkspace); // TODO: merge occlusion methods void setOccludedForMainWorkspace(CRegion& region, PHLWORKSPACE pWorkspace); // TODO: merge occlusion methods
bool canSkipBackBufferClear(CMonitor* pMonitor); bool canSkipBackBufferClear(PHLMONITOR pMonitor);
void recheckSolitaryForMonitor(CMonitor* pMonitor); void recheckSolitaryForMonitor(PHLMONITOR pMonitor);
void setCursorSurface(SP<CWLSurface> surf, int hotspotX, int hotspotY, bool force = false); void setCursorSurface(SP<CWLSurface> surf, int hotspotX, int hotspotY, bool force = false);
void setCursorFromName(const std::string& name, bool force = false); void setCursorFromName(const std::string& name, bool force = false);
void onRenderbufferDestroy(CRenderbuffer* rb); void onRenderbufferDestroy(CRenderbuffer* rb);
@ -75,19 +75,19 @@ class CHyprRenderer {
// if RENDER_MODE_NORMAL, provided damage will be written to. // if RENDER_MODE_NORMAL, provided damage will be written to.
// otherwise, it will be the one used. // otherwise, it will be the one used.
bool beginRender(CMonitor* pMonitor, CRegion& damage, eRenderMode mode = RENDER_MODE_NORMAL, SP<IWLBuffer> buffer = {}, CFramebuffer* fb = nullptr, bool simple = false); bool beginRender(PHLMONITOR pMonitor, CRegion& damage, eRenderMode mode = RENDER_MODE_NORMAL, SP<IWLBuffer> buffer = {}, CFramebuffer* fb = nullptr, bool simple = false);
void endRender(); void endRender();
bool m_bBlockSurfaceFeedback = false; bool m_bBlockSurfaceFeedback = false;
bool m_bRenderingSnapshot = false; bool m_bRenderingSnapshot = false;
PHLWINDOWREF m_pLastScanout; PHLWINDOWREF m_pLastScanout;
CMonitor* m_pMostHzMonitor = nullptr; PHLMONITORREF m_pMostHzMonitor;
bool m_bDirectScanoutBlocked = false; bool m_bDirectScanoutBlocked = false;
DAMAGETRACKINGMODES DAMAGETRACKINGMODES
damageTrackingModeFromStr(const std::string&); damageTrackingModeFromStr(const std::string&);
bool attemptDirectScanout(CMonitor*); bool attemptDirectScanout(PHLMONITOR);
void setWindowScanoutMode(PHLWINDOW); void setWindowScanoutMode(PHLWINDOW);
void initiateManualCrash(); void initiateManualCrash();
@ -106,17 +106,17 @@ class CHyprRenderer {
} m_sLastCursorData; } m_sLastCursorData;
private: private:
void arrangeLayerArray(CMonitor*, const std::vector<PHLLSREF>&, bool, CBox*); void arrangeLayerArray(PHLMONITOR, const std::vector<PHLLSREF>&, bool, CBox*);
void renderWorkspaceWindowsFullscreen(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special) void renderWorkspaceWindowsFullscreen(PHLMONITOR, PHLWORKSPACE, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special)
void renderWorkspaceWindows(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special) void renderWorkspaceWindows(PHLMONITOR, PHLWORKSPACE, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special)
void renderWindow(PHLWINDOW, CMonitor*, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false); void renderWindow(PHLWINDOW, PHLMONITOR, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false);
void renderLayer(PHLLS, CMonitor*, timespec*, bool popups = false); void renderLayer(PHLLS, PHLMONITOR, timespec*, bool popups = false);
void renderSessionLockSurface(SSessionLockSurface*, CMonitor*, timespec*); void renderSessionLockSurface(SSessionLockSurface*, PHLMONITOR, timespec*);
void renderDragIcon(CMonitor*, timespec*); void renderDragIcon(PHLMONITOR, timespec*);
void renderIMEPopup(CInputPopup*, CMonitor*, timespec*); void renderIMEPopup(CInputPopup*, PHLMONITOR, timespec*);
void renderWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const CBox& geometry); void renderWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const CBox& geometry);
void sendFrameEventsToWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now); // sends frame displayed events but doesn't actually render anything void sendFrameEventsToWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* now); // sends frame displayed events but doesn't actually render anything
void renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f); void renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f);
bool m_bCursorHidden = false; bool m_bCursorHidden = false;
bool m_bCursorHasSurface = false; bool m_bCursorHasSurface = false;

View file

@ -45,7 +45,7 @@ CBox CHyprBorderDecoration::assignedBoxGlobal() {
return box.translate(WORKSPACEOFFSET); return box.translate(WORKSPACEOFFSET);
} }
void CHyprBorderDecoration::draw(CMonitor* pMonitor, float a) { void CHyprBorderDecoration::draw(PHLMONITOR pMonitor, float a) {
if (doesntWantBorders()) if (doesntWantBorders())
return; return;
@ -109,7 +109,7 @@ void CHyprBorderDecoration::damageEntire() {
borderRegion.subtract(surfaceBoxShrunkRounding); borderRegion.subtract(surfaceBoxShrunkRounding);
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
if (!g_pHyprRenderer->shouldRenderWindow(m_pWindow.lock(), m.get())) { if (!g_pHyprRenderer->shouldRenderWindow(m_pWindow.lock(), m)) {
const CRegion monitorRegion({m->vecPosition, m->vecSize}); const CRegion monitorRegion({m->vecPosition, m->vecSize});
borderRegion.subtract(monitorRegion); borderRegion.subtract(monitorRegion);
} }

View file

@ -11,7 +11,7 @@ class CHyprBorderDecoration : public IHyprWindowDecoration {
virtual void onPositioningReply(const SDecorationPositioningReply& reply); virtual void onPositioningReply(const SDecorationPositioningReply& reply);
virtual void draw(CMonitor*, float a); virtual void draw(PHLMONITOR, float a);
virtual eDecorationType getDecorationType(); virtual eDecorationType getDecorationType();

View file

@ -67,7 +67,7 @@ void CHyprDropShadowDecoration::damageEntire() {
} }
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
if (!g_pHyprRenderer->shouldRenderWindow(PWINDOW, m.get())) { if (!g_pHyprRenderer->shouldRenderWindow(PWINDOW, m)) {
const CRegion monitorRegion({m->vecPosition, m->vecSize}); const CRegion monitorRegion({m->vecPosition, m->vecSize});
shadowRegion.subtract(monitorRegion); shadowRegion.subtract(monitorRegion);
} }
@ -86,7 +86,7 @@ void CHyprDropShadowDecoration::updateWindow(PHLWINDOW pWindow) {
m_bLastWindowBoxWithDecos = g_pDecorationPositioner->getBoxWithIncludedDecos(pWindow); m_bLastWindowBoxWithDecos = g_pDecorationPositioner->getBoxWithIncludedDecos(pWindow);
} }
void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) { void CHyprDropShadowDecoration::draw(PHLMONITOR pMonitor, float a) {
const auto PWINDOW = m_pWindow.lock(); const auto PWINDOW = m_pWindow.lock();

View file

@ -11,7 +11,7 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration {
virtual void onPositioningReply(const SDecorationPositioningReply& reply); virtual void onPositioningReply(const SDecorationPositioningReply& reply);
virtual void draw(CMonitor*, float a); virtual void draw(PHLMONITOR, float a);
virtual eDecorationType getDecorationType(); virtual eDecorationType getDecorationType();

View file

@ -94,7 +94,7 @@ void CHyprGroupBarDecoration::damageEntire() {
g_pHyprRenderer->damageBox(&box); g_pHyprRenderer->damageBox(&box);
} }
void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) { void CHyprGroupBarDecoration::draw(PHLMONITOR pMonitor, float a) {
// get how many bars we will draw // get how many bars we will draw
int barsToDraw = m_dwGroupMembers.size(); int barsToDraw = m_dwGroupMembers.size();

View file

@ -31,7 +31,7 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration {
virtual void onPositioningReply(const SDecorationPositioningReply& reply); virtual void onPositioningReply(const SDecorationPositioningReply& reply);
virtual void draw(CMonitor*, float a); virtual void draw(PHLMONITOR, float a);
virtual eDecorationType getDecorationType(); virtual eDecorationType getDecorationType();

View file

@ -39,7 +39,7 @@ class IHyprWindowDecoration {
virtual void onPositioningReply(const SDecorationPositioningReply& reply) = 0; virtual void onPositioningReply(const SDecorationPositioningReply& reply) = 0;
virtual void draw(CMonitor*, float a) = 0; virtual void draw(PHLMONITOR, float a) = 0;
virtual eDecorationType getDecorationType() = 0; virtual eDecorationType getDecorationType() = 0;