From d5689bb53935ff1adbbfc9fdf5b1f542ce39efb2 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 26 Oct 2024 02:06:13 +0100 Subject: [PATCH] internal: cleanup CMonitor usage and fix a few ref hogs ref #8221 --- src/Compositor.cpp | 8 +++---- src/Compositor.hpp | 6 ++--- src/config/ConfigManager.cpp | 2 +- src/config/ConfigManager.hpp | 2 +- src/debug/HyprDebugOverlay.hpp | 8 +++---- src/helpers/Monitor.cpp | 8 +++---- src/helpers/Monitor.hpp | 2 +- src/managers/PointerManager.cpp | 16 ++++++------- src/managers/PointerManager.hpp | 22 +++++++++--------- src/protocols/CTMControl.cpp | 2 +- src/protocols/CTMControl.hpp | 2 +- src/protocols/DRMLease.cpp | 6 ++--- src/protocols/DRMLease.hpp | 10 ++++----- src/protocols/LinuxDMABUF.cpp | 20 ++++++++--------- src/protocols/LinuxDMABUF.hpp | 12 +++++----- src/protocols/OutputManagement.cpp | 2 +- src/protocols/OutputManagement.hpp | 2 +- src/protocols/PresentationTime.cpp | 6 ++--- src/protocols/PresentationTime.hpp | 6 ++--- src/protocols/VirtualPointer.cpp | 4 ++-- src/protocols/VirtualPointer.hpp | 12 +++++----- src/protocols/XDGOutput.cpp | 2 +- src/protocols/XDGOutput.hpp | 4 ++-- src/protocols/core/Compositor.cpp | 6 ++--- src/protocols/core/Compositor.hpp | 8 +++---- src/protocols/core/Output.cpp | 4 ++-- src/protocols/core/Output.hpp | 8 +++---- src/render/OpenGL.hpp | 36 +++++++++++++++--------------- src/render/Renderer.cpp | 4 ++-- src/render/Renderer.hpp | 4 ++-- 30 files changed, 116 insertions(+), 118 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 313d57ac..743895aa 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -750,7 +750,7 @@ PHLMONITOR CCompositor::getMonitorFromCursor() { } PHLMONITOR CCompositor::getMonitorFromVector(const Vector2D& point) { - SP mon; + PHLMONITOR mon; for (auto const& m : m_vMonitors) { if (CBox{m->vecPosition, m->vecSize}.containsPoint(point)) { mon = m; @@ -759,8 +759,8 @@ PHLMONITOR CCompositor::getMonitorFromVector(const Vector2D& point) { } if (!mon) { - float bestDistance = 0.f; - SP pBestMon; + float bestDistance = 0.f; + PHLMONITOR pBestMon; for (auto const& m : m_vMonitors) { float dist = vecToRectDistanceSquared(point, m->vecPosition, m->vecPosition + m->vecSize); @@ -3008,7 +3008,7 @@ PHLWINDOW CCompositor::windowForCPointer(CWindow* pWindow) { return {}; } -static void checkDefaultCursorWarp(SP monitor) { +static void checkDefaultCursorWarp(PHLMONITOR monitor) { static auto PCURSORMONITOR = CConfigValue("cursor:default_monitor"); static bool cursorDefaultDone = false; static bool firstLaunch = true; diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 7fbd32e8..208b6ecf 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -59,8 +59,8 @@ class CCompositor { std::string m_szInstancePath = ""; std::string m_szCurrentSplash = "error"; - std::vector> m_vMonitors; - std::vector> m_vRealMonitors; // for all monitors, even those turned off + std::vector m_vMonitors; + std::vector m_vRealMonitors; // for all monitors, even those turned off std::vector m_vWindows; std::vector m_vLayers; std::vector m_vWorkspaces; @@ -80,7 +80,7 @@ class CCompositor { WP m_pLastFocus; PHLWINDOWREF m_pLastWindow; - WP m_pLastMonitor; + PHLMONITORREF m_pLastMonitor; std::vector m_vWindowFocusHistory; // first element is the most recently focused. diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 8237fd44..e2dc4b0f 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1087,7 +1087,7 @@ std::string CConfigManager::getDeviceString(const std::string& dev, const std::s return VAL; } -SMonitorRule CConfigManager::getMonitorRuleFor(const SP PMONITOR) { +SMonitorRule CConfigManager::getMonitorRuleFor(const PHLMONITOR PMONITOR) { auto applyWlrOutputConfig = [PMONITOR](SMonitorRule rule) -> SMonitorRule { const auto CONFIG = PROTO::outputManagement->getOutputStateFor(PMONITOR); diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index e9ed2d64..cf053daa 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -169,7 +169,7 @@ class CConfigManager { static std::string getMainConfigPath(); const std::string getConfigString(); - SMonitorRule getMonitorRuleFor(const SP); + SMonitorRule getMonitorRuleFor(const PHLMONITOR); SWorkspaceRule getWorkspaceRuleFor(PHLWORKSPACE workspace); std::string getDefaultWorkspaceFor(const std::string&); diff --git a/src/debug/HyprDebugOverlay.hpp b/src/debug/HyprDebugOverlay.hpp index 19b9120a..89d1d606 100644 --- a/src/debug/HyprDebugOverlay.hpp +++ b/src/debug/HyprDebugOverlay.hpp @@ -38,12 +38,12 @@ class CHyprDebugOverlay { void frameData(PHLMONITOR); private: - std::map m_mMonitorOverlays; + std::map m_mMonitorOverlays; - cairo_surface_t* m_pCairoSurface = nullptr; - cairo_t* m_pCairo = nullptr; + cairo_surface_t* m_pCairoSurface = nullptr; + cairo_t* m_pCairo = nullptr; - SP m_pTexture; + SP m_pTexture; friend class CHyprMonitorDebugOverlay; friend class CHyprRenderer; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index d8889585..41290b7d 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -71,7 +71,7 @@ void CMonitor::onConnect(bool noRule) { Debug::log(LOG, "Removing monitor {} from realMonitors", szName); - std::erase_if(g_pCompositor->m_vRealMonitors, [&](SP& el) { return el.get() == this; }); + std::erase_if(g_pCompositor->m_vRealMonitors, [&](PHLMONITOR& el) { return el.get() == this; }); }); listeners.state = output->events.state.registerListener([this](std::any d) { @@ -149,7 +149,7 @@ void CMonitor::onConnect(bool noRule) { return; } - SP* thisWrapper = nullptr; + PHLMONITOR* thisWrapper = nullptr; // find the wrap for (auto& m : g_pCompositor->m_vRealMonitors) { @@ -356,7 +356,7 @@ void CMonitor::onDisconnect(bool destroy) { g_pHyprRenderer->m_pMostHzMonitor = pMonitorMostHz; } - std::erase_if(g_pCompositor->m_vMonitors, [&](SP& 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) { @@ -509,7 +509,7 @@ void CMonitor::setMirror(const std::string& mirrorOf) { // push to mvmonitors - SP* thisWrapper = nullptr; + PHLMONITOR* thisWrapper = nullptr; // find the wrap for (auto& m : g_pCompositor->m_vRealMonitors) { diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index f3d6d647..dce44b4a 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -125,7 +125,7 @@ class CMonitor { SP outTimeline; uint64_t commitSeq = 0; - WP self; + PHLMONITORREF self; // mirroring PHLMONITORREF pMirrorOf; diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index ae90349b..0d6e0206 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -69,7 +69,7 @@ void CPointerManager::unlockSoftwareForMonitor(PHLMONITOR mon) { updateCursorBackend(); } -bool CPointerManager::softwareLockedFor(SP mon) { +bool CPointerManager::softwareLockedFor(PHLMONITOR mon) { auto state = stateFor(mon); return state->softwareLocks > 0 || state->hardwareFailed; } @@ -82,7 +82,7 @@ bool CPointerManager::hasCursor() { return currentCursorImage.pBuffer || currentCursorImage.surface; } -SP CPointerManager::stateFor(SP mon) { +SP CPointerManager::stateFor(PHLMONITOR mon) { auto it = std::find_if(monitorStates.begin(), monitorStates.end(), [mon](const auto& other) { return other->monitor == mon; }); if (it == monitorStates.end()) return monitorStates.emplace_back(makeShared(mon)); @@ -503,7 +503,7 @@ SP CPointerManager::renderHWCursorBuffer(SP pMonitor, timespec* now, CRegion& damage, std::optional overridePos) { +void CPointerManager::renderSoftwareCursorsFor(PHLMONITOR pMonitor, timespec* now, CRegion& damage, std::optional overridePos) { if (!hasCursor()) return; @@ -538,7 +538,7 @@ void CPointerManager::renderSoftwareCursorsFor(SP pMonitor, timespec* currentCursorImage.surface->resource()->frame(now); } -Vector2D CPointerManager::getCursorPosForMonitor(SP pMonitor) { +Vector2D CPointerManager::getCursorPosForMonitor(PHLMONITOR pMonitor) { return CBox{pointerPos - pMonitor->vecPosition, {0, 0}} .transform(wlTransformToHyprutils(invertTransform(pMonitor->transform)), pMonitor->vecTransformedSize.x / pMonitor->scale, pMonitor->vecTransformedSize.y / pMonitor->scale) @@ -546,7 +546,7 @@ Vector2D CPointerManager::getCursorPosForMonitor(SP pMonitor) { pMonitor->scale; } -Vector2D CPointerManager::transformedHotspot(SP pMonitor) { +Vector2D CPointerManager::transformedHotspot(PHLMONITOR pMonitor) { if (!pMonitor->cursorSwapchain) return {}; // doesn't matter, we have no hw cursor, and this is only for hw cursors @@ -556,7 +556,7 @@ Vector2D CPointerManager::transformedHotspot(SP pMonitor) { .pos(); } -CBox CPointerManager::getCursorBoxLogicalForMonitor(SP pMonitor) { +CBox CPointerManager::getCursorBoxLogicalForMonitor(PHLMONITOR pMonitor) { return getCursorBoxGlobal().translate(-pMonitor->vecPosition); } @@ -678,7 +678,7 @@ void CPointerManager::move(const Vector2D& deltaLogical) { void CPointerManager::warpAbsolute(Vector2D abs, SP dev) { - SP currentMonitor = g_pCompositor->m_pLastMonitor.lock(); + PHLMONITOR currentMonitor = g_pCompositor->m_pLastMonitor.lock(); if (!currentMonitor || !dev) return; @@ -1055,7 +1055,7 @@ void CPointerManager::detachTablet(SP tablet) { std::erase_if(tabletListeners, [tablet](const auto& e) { return e->tablet.expired() || e->tablet == tablet; }); } -void CPointerManager::damageCursor(SP pMonitor) { +void CPointerManager::damageCursor(PHLMONITOR pMonitor) { for (auto const& mw : monitorStates) { if (mw->monitor != pMonitor) continue; diff --git a/src/managers/PointerManager.hpp b/src/managers/PointerManager.hpp index aef2490d..a0cd0fff 100644 --- a/src/managers/PointerManager.hpp +++ b/src/managers/PointerManager.hpp @@ -43,18 +43,18 @@ class CPointerManager { void setCursorSurface(SP buf, const Vector2D& hotspot); void resetCursorImage(bool apply = true); - void lockSoftwareForMonitor(SP pMonitor); - void unlockSoftwareForMonitor(SP pMonitor); + void lockSoftwareForMonitor(PHLMONITOR pMonitor); + void unlockSoftwareForMonitor(PHLMONITOR pMonitor); void lockSoftwareAll(); void unlockSoftwareAll(); - bool softwareLockedFor(SP pMonitor); + bool softwareLockedFor(PHLMONITOR pMonitor); - void renderSoftwareCursorsFor(SP pMonitor, timespec* now, CRegion& damage /* logical */, std::optional overridePos = {} /* monitor-local */); + void renderSoftwareCursorsFor(PHLMONITOR pMonitor, timespec* now, CRegion& damage /* logical */, std::optional overridePos = {} /* monitor-local */); // this is needed e.g. during screensharing where // the software cursors aren't locked during the cursor move, but they // are rendered later. - void damageCursor(SP pMonitor); + void damageCursor(PHLMONITOR pMonitor); // Vector2D position(); @@ -78,13 +78,13 @@ class CPointerManager { Vector2D closestValid(const Vector2D& pos); // returns the thing in device coordinates. Is NOT offset by the hotspot, relies on set_cursor with hotspot. - Vector2D getCursorPosForMonitor(SP pMonitor); + Vector2D getCursorPosForMonitor(PHLMONITOR pMonitor); // returns the thing in logical coordinates of the monitor - CBox getCursorBoxLogicalForMonitor(SP pMonitor); + CBox getCursorBoxLogicalForMonitor(PHLMONITOR pMonitor); // returns the thing in global coords CBox getCursorBoxGlobal(); - Vector2D transformedHotspot(SP pMonitor); + Vector2D transformedHotspot(PHLMONITOR pMonitor); SP getCurrentCursorTexture(); @@ -160,10 +160,10 @@ class CPointerManager { Vector2D storedUnaccel = {0, 0}; struct SMonitorPointerState { - SMonitorPointerState(SP m) : monitor(m) {} + SMonitorPointerState(PHLMONITOR m) : monitor(m) {} ~SMonitorPointerState() {} - WP monitor; + PHLMONITORREF monitor; int softwareLocks = 0; bool hardwareFailed = false; @@ -176,7 +176,7 @@ class CPointerManager { }; std::vector> monitorStates; - SP stateFor(SP mon); + SP stateFor(PHLMONITOR mon); bool attemptHardwareCursor(SP state); SP renderHWCursorBuffer(SP state, SP texture); bool setHWCursorBuffer(SP state, SP buf); diff --git a/src/protocols/CTMControl.cpp b/src/protocols/CTMControl.cpp index f2a54c6f..cddad830 100644 --- a/src/protocols/CTMControl.cpp +++ b/src/protocols/CTMControl.cpp @@ -81,6 +81,6 @@ void CHyprlandCTMControlProtocol::destroyResource(CHyprlandCTMControlResource* r std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == res; }); } -void CHyprlandCTMControlProtocol::setCTM(SP monitor, const Mat3x3& ctm) { +void CHyprlandCTMControlProtocol::setCTM(PHLMONITOR monitor, const Mat3x3& ctm) { monitor->setCTM(ctm); } diff --git a/src/protocols/CTMControl.hpp b/src/protocols/CTMControl.hpp index 08f1b0e8..70bc79bc 100644 --- a/src/protocols/CTMControl.hpp +++ b/src/protocols/CTMControl.hpp @@ -31,7 +31,7 @@ class CHyprlandCTMControlProtocol : public IWaylandProtocol { private: void destroyResource(CHyprlandCTMControlResource* resource); - void setCTM(SP monitor, const Mat3x3& ctm); + void setCTM(PHLMONITOR monitor, const Mat3x3& ctm); // std::vector> m_vManagers; diff --git a/src/protocols/DRMLease.cpp b/src/protocols/DRMLease.cpp index d0114ce7..be5a6985 100644 --- a/src/protocols/DRMLease.cpp +++ b/src/protocols/DRMLease.cpp @@ -129,7 +129,7 @@ SP CDRMLeaseConnectorResource::fromResource(wl_resou return data ? data->self.lock() : nullptr; } -CDRMLeaseConnectorResource::CDRMLeaseConnectorResource(SP resource_, SP monitor_) : monitor(monitor_), resource(resource_) { +CDRMLeaseConnectorResource::CDRMLeaseConnectorResource(SP resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) { if (!good()) return; @@ -203,7 +203,7 @@ bool CDRMLeaseDeviceResource::good() { return resource->resource(); } -void CDRMLeaseDeviceResource::sendConnector(SP monitor) { +void CDRMLeaseDeviceResource::sendConnector(PHLMONITOR monitor) { if (std::find_if(connectorsSent.begin(), connectorsSent.end(), [monitor](const auto& e) { return e && !e->dead && e->monitor == monitor; }) != connectorsSent.end()) return; @@ -289,7 +289,7 @@ void CDRMLeaseProtocol::destroyResource(CDRMLeaseResource* resource) { std::erase_if(m_vLeases, [resource](const auto& e) { return e.get() == resource; }); } -void CDRMLeaseProtocol::offer(SP monitor) { +void CDRMLeaseProtocol::offer(PHLMONITOR monitor) { std::erase_if(primaryDevice->offeredOutputs, [](const auto& e) { return e.expired(); }); if (std::find(primaryDevice->offeredOutputs.begin(), primaryDevice->offeredOutputs.end(), monitor) != primaryDevice->offeredOutputs.end()) return; diff --git a/src/protocols/DRMLease.hpp b/src/protocols/DRMLease.hpp index 3671cfce..37de40e3 100644 --- a/src/protocols/DRMLease.hpp +++ b/src/protocols/DRMLease.hpp @@ -56,7 +56,7 @@ class CDRMLeaseRequestResource { class CDRMLeaseConnectorResource { public: - CDRMLeaseConnectorResource(SP resource_, SP monitor_); + CDRMLeaseConnectorResource(SP resource_, PHLMONITOR monitor_); static SP fromResource(wl_resource*); bool good(); @@ -64,7 +64,7 @@ class CDRMLeaseConnectorResource { WP self; WP parent; - WP monitor; + PHLMONITORREF monitor; bool dead = false; private: @@ -82,7 +82,7 @@ class CDRMLeaseDeviceResource { CDRMLeaseDeviceResource(SP resource_); bool good(); - void sendConnector(SP monitor); + void sendConnector(PHLMONITOR monitor); std::vector> connectorsSent; @@ -102,7 +102,7 @@ class CDRMLeaseDevice { bool success = false; SP backend; - std::vector> offeredOutputs; + std::vector offeredOutputs; }; class CDRMLeaseProtocol : public IWaylandProtocol { @@ -111,7 +111,7 @@ class CDRMLeaseProtocol : public IWaylandProtocol { virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); - void offer(SP monitor); + void offer(PHLMONITOR monitor); private: void destroyResource(CDRMLeaseDeviceResource* resource); diff --git a/src/protocols/LinuxDMABUF.cpp b/src/protocols/LinuxDMABUF.cpp index 8e26c74f..e81d7e01 100644 --- a/src/protocols/LinuxDMABUF.cpp +++ b/src/protocols/LinuxDMABUF.cpp @@ -21,7 +21,7 @@ static std::optional devIDFromFD(int fd) { return stat.st_rdev; } -CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vector, SDMABUFTranche>> tranches_) : +CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vector> tranches_) : rendererTranche(_rendererTranche), monitorTranches(tranches_) { std::vector formatsVec; @@ -436,7 +436,7 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const .formats = g_pHyprOpenGL->getDRMFormats(), }; - std::vector, SDMABUFTranche>> tches; + std::vector> tches; if (g_pCompositor->m_pAqBackend->hasSession()) { // this assumes there's only 1 device used for both scanout and rendering @@ -453,20 +453,18 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const static auto monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) { auto pMonitor = std::any_cast(param); - auto mon = pMonitor->self.lock(); auto tranche = SDMABUFTranche{ .device = mainDevice, .flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT, - .formats = mon->output->getRenderFormats(), + .formats = pMonitor->output->getRenderFormats(), }; - formatTable->monitorTranches.push_back(std::make_pair<>(mon, tranche)); + formatTable->monitorTranches.push_back(std::make_pair<>(pMonitor, tranche)); resetFormatTable(); }); static auto monitorRemoved = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) { auto pMonitor = std::any_cast(param); - auto mon = pMonitor->self.lock(); - std::erase_if(formatTable->monitorTranches, [mon](std::pair, SDMABUFTranche> pair) { return pair.first == mon; }); + std::erase_if(formatTable->monitorTranches, [pMonitor](std::pair pair) { return pair.first == pMonitor; }); resetFormatTable(); }); } @@ -508,8 +506,8 @@ void CLinuxDMABufV1Protocol::resetFormatTable() { for (auto const& feedback : m_vFeedbacks) { feedback->resource->sendFormatTable(newFormatTable->tableFD, newFormatTable->tableSize); if (feedback->lastFeedbackWasScanout) { - SP mon; - auto HLSurface = CWLSurface::fromResource(feedback->surface); + PHLMONITOR mon; + auto HLSurface = CWLSurface::fromResource(feedback->surface); if (auto w = HLSurface->getWindow(); w) if (auto m = g_pCompositor->getMonitorFromID(w->m_iMonitorID); m) mon = m->self.lock(); @@ -560,7 +558,7 @@ void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABuffer* resource) { std::erase_if(m_vBuffers, [&](const auto& other) { return other.get() == resource; }); } -void CLinuxDMABufV1Protocol::updateScanoutTranche(SP surface, SP pMonitor) { +void CLinuxDMABufV1Protocol::updateScanoutTranche(SP surface, PHLMONITOR pMonitor) { SP feedbackResource; for (auto const& f : m_vFeedbacks) { if (f->surface != surface) @@ -582,7 +580,7 @@ void CLinuxDMABufV1Protocol::updateScanoutTranche(SP surface } const auto& monitorTranchePair = std::find_if(formatTable->monitorTranches.begin(), formatTable->monitorTranches.end(), - [pMonitor](std::pair, SDMABUFTranche> pair) { return pair.first == pMonitor; }); + [pMonitor](std::pair pair) { return pair.first == pMonitor; }); if (monitorTranchePair == formatTable->monitorTranches.end()) { LOGM(LOG, "updateScanoutTranche: monitor has no tranche"); diff --git a/src/protocols/LinuxDMABUF.hpp b/src/protocols/LinuxDMABUF.hpp index 0e25cdc6..e4941a6d 100644 --- a/src/protocols/LinuxDMABUF.hpp +++ b/src/protocols/LinuxDMABUF.hpp @@ -48,13 +48,13 @@ struct SDMABUFTranche { class CDMABUFFormatTable { public: - CDMABUFFormatTable(SDMABUFTranche rendererTranche, std::vector, SDMABUFTranche>> tranches); + CDMABUFFormatTable(SDMABUFTranche rendererTranche, std::vector> tranches); ~CDMABUFFormatTable(); - int tableFD = -1; - size_t tableSize = 0; - SDMABUFTranche rendererTranche; - std::vector, SDMABUFTranche>> monitorTranches; + int tableFD = -1; + size_t tableSize = 0; + SDMABUFTranche rendererTranche; + std::vector> monitorTranches; }; class CLinuxDMABBUFParamsResource { @@ -111,7 +111,7 @@ class CLinuxDMABufV1Protocol : public IWaylandProtocol { ~CLinuxDMABufV1Protocol(); virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); - void updateScanoutTranche(SP surface, SP pMonitor); + void updateScanoutTranche(SP surface, PHLMONITOR pMonitor); private: void destroyResource(CLinuxDMABUFResource* resource); diff --git a/src/protocols/OutputManagement.cpp b/src/protocols/OutputManagement.cpp index 77cedd41..0c6a3348 100644 --- a/src/protocols/OutputManagement.cpp +++ b/src/protocols/OutputManagement.cpp @@ -633,7 +633,7 @@ SP COutputManagementProtocol::modeFromResource(wl_resource* r) { return nullptr; } -SP COutputManagementProtocol::getOutputStateFor(SP pMonitor) { +SP COutputManagementProtocol::getOutputStateFor(PHLMONITOR pMonitor) { for (auto const& m : m_vManagers) { if (!m->monitorStates.contains(pMonitor->szName)) continue; diff --git a/src/protocols/OutputManagement.hpp b/src/protocols/OutputManagement.hpp index 6deab017..b9e7ce98 100644 --- a/src/protocols/OutputManagement.hpp +++ b/src/protocols/OutputManagement.hpp @@ -153,7 +153,7 @@ class COutputManagementProtocol : public IWaylandProtocol { virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); // doesn't have to return one - SP getOutputStateFor(SP pMonitor); + SP getOutputStateFor(PHLMONITOR pMonitor); private: void destroyResource(COutputManager* resource); diff --git a/src/protocols/PresentationTime.cpp b/src/protocols/PresentationTime.cpp index b66694bf..411036c3 100644 --- a/src/protocols/PresentationTime.cpp +++ b/src/protocols/PresentationTime.cpp @@ -14,7 +14,7 @@ void CQueuedPresentationData::setPresentationType(bool zeroCopy_) { zeroCopy = zeroCopy_; } -void CQueuedPresentationData::attachMonitor(SP pMonitor_) { +void CQueuedPresentationData::attachMonitor(PHLMONITOR pMonitor_) { pMonitor = pMonitor_; } @@ -73,7 +73,7 @@ void CPresentationFeedback::sendQueued(SP data, timespe 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) { - const auto PMONITOR = std::any_cast(param); + const auto PMONITOR = PHLMONITORREF{std::any_cast(param)}; std::erase_if(m_vQueue, [PMONITOR](const auto& other) { return !other->surface || other->pMonitor == PMONITOR; }); }); } @@ -107,7 +107,7 @@ void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* su } } -void CPresentationProtocol::onPresented(SP 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) { timespec now; timespec* presentedAt = when; if (!presentedAt) { diff --git a/src/protocols/PresentationTime.hpp b/src/protocols/PresentationTime.hpp index 421bb838..d9b45448 100644 --- a/src/protocols/PresentationTime.hpp +++ b/src/protocols/PresentationTime.hpp @@ -14,7 +14,7 @@ class CQueuedPresentationData { CQueuedPresentationData(SP surf); void setPresentationType(bool zeroCopy); - void attachMonitor(SP pMonitor); + void attachMonitor(PHLMONITOR pMonitor); void presented(); void discarded(); @@ -24,7 +24,7 @@ class CQueuedPresentationData { private: bool wasPresented = false; bool zeroCopy = false; - WP pMonitor; + PHLMONITORREF pMonitor; WP surface; friend class CPresentationFeedback; @@ -53,7 +53,7 @@ class CPresentationProtocol : public IWaylandProtocol { virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); - void onPresented(SP 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 data); private: diff --git a/src/protocols/VirtualPointer.cpp b/src/protocols/VirtualPointer.cpp index eb92a640..4c5aa13a 100644 --- a/src/protocols/VirtualPointer.cpp +++ b/src/protocols/VirtualPointer.cpp @@ -1,7 +1,7 @@ #include "VirtualPointer.hpp" #include "core/Output.hpp" -CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP resource_, WP boundOutput_) : boundOutput(boundOutput_), resource(resource_) { +CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP resource_, PHLMONITORREF boundOutput_) : boundOutput(boundOutput_), resource(resource_) { if (!good()) return; @@ -134,7 +134,7 @@ void CVirtualPointerProtocol::destroyResource(CVirtualPointerV1Resource* pointer std::erase_if(m_vPointers, [&](const auto& other) { return other.get() == pointer; }); } -void CVirtualPointerProtocol::onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, WP output) { +void CVirtualPointerProtocol::onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, PHLMONITORREF output) { const auto RESOURCE = m_vPointers.emplace_back(makeShared(makeShared(pMgr->client(), pMgr->version(), id), output)); diff --git a/src/protocols/VirtualPointer.hpp b/src/protocols/VirtualPointer.hpp index 7ee450dc..68fe124e 100644 --- a/src/protocols/VirtualPointer.hpp +++ b/src/protocols/VirtualPointer.hpp @@ -12,7 +12,7 @@ class CVirtualPointerV1Resource { public: - CVirtualPointerV1Resource(SP resource_, WP boundOutput_); + CVirtualPointerV1Resource(SP resource_, PHLMONITORREF boundOutput_); ~CVirtualPointerV1Resource(); struct { @@ -35,12 +35,12 @@ class CVirtualPointerV1Resource { CSignal holdEnd; } events; - bool good(); - wl_client* client(); + bool good(); + wl_client* client(); - std::string name; + std::string name; - WP boundOutput; + PHLMONITORREF boundOutput; private: SP resource; @@ -63,7 +63,7 @@ class CVirtualPointerProtocol : public IWaylandProtocol { private: void onManagerResourceDestroy(wl_resource* res); void destroyResource(CVirtualPointerV1Resource* pointer); - void onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, WP output); + void onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, PHLMONITORREF output); // std::vector> m_vManagers; diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp index 0598e713..deb87829 100644 --- a/src/protocols/XDGOutput.cpp +++ b/src/protocols/XDGOutput.cpp @@ -95,7 +95,7 @@ void CXDGOutputProtocol::updateAllOutputs() { // -CXDGOutput::CXDGOutput(SP resource_, SP monitor_) : monitor(monitor_), resource(resource_) { +CXDGOutput::CXDGOutput(SP resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) { if (!resource->resource()) return; diff --git a/src/protocols/XDGOutput.hpp b/src/protocols/XDGOutput.hpp index 520f3aaa..6a5be284 100644 --- a/src/protocols/XDGOutput.hpp +++ b/src/protocols/XDGOutput.hpp @@ -10,12 +10,12 @@ class CWLOutputProtocol; class CXDGOutput { public: - CXDGOutput(SP resource, SP monitor_); + CXDGOutput(SP resource, PHLMONITOR monitor_); void sendDetails(); private: - WP monitor; + PHLMONITORREF monitor; SP resource; WP outputProto; diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp index 3d4b63c1..9a2e00a9 100644 --- a/src/protocols/core/Compositor.cpp +++ b/src/protocols/core/Compositor.cpp @@ -182,7 +182,7 @@ wl_client* CWLSurfaceResource::client() { return pClient; } -void CWLSurfaceResource::enter(SP monitor) { +void CWLSurfaceResource::enter(PHLMONITOR monitor) { if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) != enteredOutputs.end()) return; @@ -209,7 +209,7 @@ void CWLSurfaceResource::enter(SP monitor) { resource->sendEnter(output->getResource().get()); } -void CWLSurfaceResource::leave(SP monitor) { +void CWLSurfaceResource::leave(PHLMONITOR monitor) { if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end()) return; @@ -509,7 +509,7 @@ void CWLSurfaceResource::updateCursorShm() { memcpy(shmData.data(), pixelData, bufLen); } -void CWLSurfaceResource::presentFeedback(timespec* when, SP pMonitor) { +void CWLSurfaceResource::presentFeedback(timespec* when, PHLMONITOR pMonitor) { frame(when); auto FEEDBACK = makeShared(self.lock()); FEEDBACK->attachMonitor(pMonitor); diff --git a/src/protocols/core/Compositor.hpp b/src/protocols/core/Compositor.hpp index b3c067c9..fbffd966 100644 --- a/src/protocols/core/Compositor.hpp +++ b/src/protocols/core/Compositor.hpp @@ -60,8 +60,8 @@ class CWLSurfaceResource { bool good(); wl_client* client(); - void enter(SP monitor); - void leave(SP monitor); + void enter(PHLMONITOR monitor); + void leave(PHLMONITOR monitor); void sendPreferredTransform(wl_output_transform t); void sendPreferredScale(int32_t scale); void frame(timespec* now); @@ -115,7 +115,7 @@ class CWLSurfaceResource { std::vector> callbacks; WP self; WP hlSurface; - std::vector> enteredOutputs; + std::vector enteredOutputs; bool mapped = false; std::vector> subsurfaces; SP role; @@ -124,7 +124,7 @@ class CWLSurfaceResource { void breadthfirst(std::function, const Vector2D&, void*)> fn, void* data); CRegion accumulateCurrentBufferDamage(); - void presentFeedback(timespec* when, SP pMonitor); + void presentFeedback(timespec* when, PHLMONITOR pMonitor); void lockPendingState(); void unlockPendingState(); diff --git a/src/protocols/core/Output.cpp b/src/protocols/core/Output.cpp index e9f35abc..edeeb584 100644 --- a/src/protocols/core/Output.cpp +++ b/src/protocols/core/Output.cpp @@ -3,7 +3,7 @@ #include "../../Compositor.hpp" #include "../../helpers/Monitor.hpp" -CWLOutputResource::CWLOutputResource(SP resource_, SP pMonitor) : monitor(pMonitor), resource(resource_) { +CWLOutputResource::CWLOutputResource(SP resource_, PHLMONITOR pMonitor) : monitor(pMonitor), resource(resource_) { if (!good()) return; @@ -83,7 +83,7 @@ void CWLOutputResource::updateState() { resource->sendDone(); } -CWLOutputProtocol::CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, SP 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) { listeners.modeChanged = monitor->events.modeChanged.registerListener([this](std::any d) { diff --git a/src/protocols/core/Output.hpp b/src/protocols/core/Output.hpp index 49c32ec1..a4c81d72 100644 --- a/src/protocols/core/Output.hpp +++ b/src/protocols/core/Output.hpp @@ -12,7 +12,7 @@ class CWLOutputProtocol; class CWLOutputResource { public: - CWLOutputResource(SP resource_, SP pMonitor); + CWLOutputResource(SP resource_, PHLMONITOR pMonitor); static SP fromResource(wl_resource*); bool good(); @@ -20,7 +20,7 @@ class CWLOutputResource { SP getResource(); void updateState(); - WP monitor; + PHLMONITORREF monitor; WP owner; WP self; @@ -33,14 +33,14 @@ class CWLOutputResource { class CWLOutputProtocol : public IWaylandProtocol { public: - CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, SP 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); SP outputResourceFrom(wl_client* client); void sendDone(); - WP monitor; + PHLMONITORREF monitor; WP self; // will mark the protocol for removal, will be removed when no. of bound outputs is 0 (or when overwritten by a new global) diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 04f69d49..115dcac7 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -206,30 +206,30 @@ class CHyprOpenGLImpl { void setDamage(const CRegion& damage, std::optional finalDamage = {}); uint32_t getPreferredReadFormat(PHLMONITOR pMonitor); - std::vector getDRMFormats(); - EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs); - SP createEGLSync(int fenceFD); - bool waitForTimelinePoint(SP timeline, uint64_t point); + std::vector getDRMFormats(); + EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs); + SP createEGLSync(int fenceFD); + bool waitForTimelinePoint(SP timeline, uint64_t point); - SCurrentRenderData m_RenderData; + SCurrentRenderData m_RenderData; - GLint m_iCurrentOutputFb = 0; + GLint m_iCurrentOutputFb = 0; - int m_iGBMFD = -1; - gbm_device* m_pGbmDevice = nullptr; - EGLContext m_pEglContext = nullptr; - EGLDisplay m_pEglDisplay = nullptr; - EGLDeviceEXT m_pEglDevice = nullptr; + int m_iGBMFD = -1; + gbm_device* m_pGbmDevice = nullptr; + EGLContext m_pEglContext = nullptr; + EGLDisplay m_pEglDisplay = nullptr; + EGLDeviceEXT m_pEglDevice = nullptr; - bool m_bReloadScreenShader = true; // at launch it can be set + bool m_bReloadScreenShader = true; // at launch it can be set - PHLWINDOWREF m_pCurrentWindow; // hack to get the current rendered window - PHLLS m_pCurrentLayer; // hack to get the current rendered layer + PHLWINDOWREF m_pCurrentWindow; // hack to get the current rendered window + PHLLS m_pCurrentLayer; // hack to get the current rendered layer - std::map m_mWindowFramebuffers; - std::map m_mLayerFramebuffers; - std::unordered_map m_mMonitorRenderResources; - std::unordered_map m_mMonitorBGFBs; + std::map m_mWindowFramebuffers; + std::map m_mLayerFramebuffers; + std::map m_mMonitorRenderResources; + std::map m_mMonitorBGFBs; struct { PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES = nullptr; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 5df0c070..c69167c8 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1085,7 +1085,7 @@ void CHyprRenderer::renderSessionLockMissing(PHLMONITOR pMonitor) { g_pSessionLockManager->onLockscreenRenderedOnMonitor(pMonitor->ID); } -void CHyprRenderer::calculateUVForSurface(PHLWINDOW pWindow, SP pSurface, SP pMonitor, bool main, const Vector2D& projSize, +void CHyprRenderer::calculateUVForSurface(PHLWINDOW pWindow, SP pSurface, PHLMONITOR pMonitor, bool main, const Vector2D& projSize, const Vector2D& projSizeUnscaled, bool fixMisalignedFSV1) { if (!pWindow || !pWindow->m_bIsX11) { Vector2D uvTL; @@ -1603,7 +1603,7 @@ void CHyprRenderer::sendFrameEventsToWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE } } -void CHyprRenderer::setSurfaceScanoutMode(SP surface, SP monitor) { +void CHyprRenderer::setSurfaceScanoutMode(SP surface, PHLMONITOR monitor) { if (!PROTO::linuxDma) return; diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 41f40b5a..4524008b 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -64,7 +64,7 @@ class CHyprRenderer { void ensureCursorRenderingMode(); bool shouldRenderCursor(); void setCursorHidden(bool hide); - void calculateUVForSurface(PHLWINDOW, SP, SP pMonitor, bool main = false, const Vector2D& projSize = {}, const Vector2D& projSizeUnscaled = {}, + void calculateUVForSurface(PHLWINDOW, SP, PHLMONITOR pMonitor, bool main = false, const Vector2D& projSize = {}, const Vector2D& projSizeUnscaled = {}, bool fixMisalignedFSV1 = false); std::tuple getRenderTimes(PHLMONITOR pMonitor); // avg max min void renderLockscreen(PHLMONITOR pMonitor, timespec* now, const CBox& geometry); @@ -95,7 +95,7 @@ class CHyprRenderer { DAMAGETRACKINGMODES damageTrackingModeFromStr(const std::string&); - void setSurfaceScanoutMode(SP surface, SP monitor); // nullptr monitor resets + void setSurfaceScanoutMode(SP surface, PHLMONITOR monitor); // nullptr monitor resets void initiateManualCrash(); bool m_bCrashingInProgress = false;