internal: Move CMonitor to SP (#8178)

* move monitors to sp

* XD
This commit is contained in:
Vaxry 2024-10-19 23:03:29 +01:00 committed by GitHub
parent ce3ba798df
commit f044e4c951
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 424 additions and 446 deletions

View file

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

View file

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

View file

@ -271,11 +271,11 @@ void updateRelativeCursorCoords() {
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)
return false;
const auto LASTMONITOR = g_pCompositor->m_pLastMonitor.get();
const auto LASTMONITOR = g_pCompositor->m_pLastMonitor.lock();
if (!LASTMONITOR)
return false;
if (LASTMONITOR == monitor) {
@ -1096,7 +1096,7 @@ SDispatchResult CKeybindManager::changeworkspace(std::string args) {
static auto PALLOWWORKSPACECYCLES = CConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles");
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)
return {.success = false, .error = "Last monitor not found"};
@ -1260,7 +1260,7 @@ SDispatchResult CKeybindManager::moveActiveToWorkspace(std::string args) {
}
auto pWorkspace = g_pCompositor->getWorkspaceByID(WORKSPACEID);
CMonitor* pMonitor = nullptr;
PHLMONITOR pMonitor = nullptr;
const auto POLDWS = PWINDOW->m_pWorkspace;
static auto PALLOWWORKSPACECYCLES = CConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles");
@ -1795,7 +1795,7 @@ SDispatchResult CKeybindManager::exitHyprland(std::string argz) {
}
SDispatchResult CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) {
CMonitor* PMONITOR = g_pCompositor->getMonitorFromString(args);
PHLMONITOR PMONITOR = g_pCompositor->getMonitorFromString(args);
if (!PMONITOR) {
Debug::log(ERR, "Ignoring moveCurrentWorkspaceToMonitor: monitor doesnt exist");
@ -1854,7 +1854,7 @@ SDispatchResult CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args
return {.success = false, .error = "focusWorkspaceOnCurrentMonitor invalid workspace!"};
}
const auto PCURRMONITOR = g_pCompositor->m_pLastMonitor.get();
const auto PCURRMONITOR = g_pCompositor->m_pLastMonitor.lock();
if (!PCURRMONITOR) {
Debug::log(ERR, "focusWorkspaceOnCurrentMonitor monitor doesn't exist!");
@ -1944,7 +1944,7 @@ SDispatchResult CKeybindManager::forceRendererReload(std::string args) {
continue;
auto rule = g_pConfigManager->getMonitorRuleFor(m);
if (!g_pHyprRenderer->applyMonitorRule(m.get(), &rule, true)) {
if (!g_pHyprRenderer->applyMonitorRule(m, &rule, true)) {
overAgain = true;
break;
}
@ -2427,7 +2427,7 @@ SDispatchResult CKeybindManager::dpms(std::string arg) {
}
if (enable)
g_pHyprRenderer->damageMonitor(m.get());
g_pHyprRenderer->damageMonitor(m);
m->events.dpmsChanged.emit();
}

View file

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

View file

@ -14,7 +14,7 @@
CPointerManager::CPointerManager() {
hooks.monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any data) {
auto PMONITOR = std::any_cast<CMonitor*>(data)->self.lock();
auto PMONITOR = std::any_cast<PHLMONITOR>(data);
onMonitorLayoutChange();
@ -29,7 +29,7 @@ CPointerManager::CPointerManager() {
});
hooks.monitorPreRender = g_pHookSystem->hookDynamic("preMonitorCommit", [this](void* self, SCallbackInfo& info, std::any data) {
auto state = stateFor(std::any_cast<CMonitor*>(data)->self.lock());
auto state = stateFor(std::any_cast<PHLMONITOR>(data));
if (!state)
return;
@ -51,16 +51,7 @@ void CPointerManager::unlockSoftwareAll() {
updateCursorBackend();
}
void CPointerManager::lockSoftwareForMonitor(CMonitor* Monitor) {
for (auto const& m : g_pCompositor->m_vMonitors) {
if (m->ID == Monitor->ID) {
lockSoftwareForMonitor(m);
return;
}
}
}
void CPointerManager::lockSoftwareForMonitor(SP<CMonitor> mon) {
void CPointerManager::lockSoftwareForMonitor(PHLMONITOR mon) {
auto state = stateFor(mon);
state->softwareLocks++;
@ -68,16 +59,7 @@ void CPointerManager::lockSoftwareForMonitor(SP<CMonitor> mon) {
updateCursorBackend();
}
void CPointerManager::unlockSoftwareForMonitor(CMonitor* Monitor) {
for (auto const& m : g_pCompositor->m_vMonitors) {
if (m->ID == Monitor->ID) {
unlockSoftwareForMonitor(m);
return;
}
}
}
void CPointerManager::unlockSoftwareForMonitor(SP<CMonitor> mon) {
void CPointerManager::unlockSoftwareForMonitor(PHLMONITOR mon) {
auto state = stateFor(mon);
state->softwareLocks--;
if (state->softwareLocks < 0)
@ -387,7 +369,7 @@ bool CPointerManager::setHWCursorBuffer(SP<SMonitorPointerState> state, SP<Aquam
state->cursorFrontBuffer = buf;
if (!state->monitor->shouldSkipScheduleFrameOnMouseEvent())
g_pCompositor->scheduleFrameForMonitor(state->monitor.get(), Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_SHAPE);
g_pCompositor->scheduleFrameForMonitor(state->monitor.lock(), Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_SHAPE);
return true;
}
@ -446,7 +428,7 @@ SP<Aquamarine::IBuffer> CPointerManager::renderHWCursorBuffer(SP<CPointerManager
CRegion damage = {0, 0, INT16_MAX, INT16_MAX};
g_pHyprRenderer->makeEGLCurrent();
g_pHyprOpenGL->m_RenderData.pMonitor = state->monitor.get();
g_pHyprOpenGL->m_RenderData.pMonitor = state->monitor;
auto RBO = g_pHyprRenderer->getOrCreateRenderbuffer(buf, state->monitor->cursorSwapchain->currentOptions().format);
if (!RBO) {
@ -503,7 +485,7 @@ SP<Aquamarine::IBuffer> CPointerManager::renderHWCursorBuffer(SP<CPointerManager
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});
CBox xbox = {{}, Vector2D{currentCursorImage.size / currentCursorImage.scale * state->monitor->scale}.round()};
@ -514,7 +496,7 @@ SP<Aquamarine::IBuffer> CPointerManager::renderHWCursorBuffer(SP<CPointerManager
g_pHyprOpenGL->end();
glFlush();
g_pHyprOpenGL->m_RenderData.pMonitor = nullptr;
g_pHyprOpenGL->m_RenderData.pMonitor.reset();
g_pHyprRenderer->onRenderbufferDestroy(RBO.get());

View file

@ -45,8 +45,6 @@ class CPointerManager {
void lockSoftwareForMonitor(SP<CMonitor> pMonitor);
void unlockSoftwareForMonitor(SP<CMonitor> pMonitor);
void lockSoftwareForMonitor(CMonitor* pMonitor);
void unlockSoftwareForMonitor(CMonitor* pMonitor);
void lockSoftwareAll();
void unlockSoftwareAll();
bool softwareLockedFor(SP<CMonitor> pMonitor);

View file

@ -62,7 +62,7 @@
#include <aquamarine/buffer/Buffer.hpp>
#include <aquamarine/backend/Backend.hpp>
void CProtocolManager::onMonitorModeChange(CMonitor* pMonitor) {
void CProtocolManager::onMonitorModeChange(PHLMONITOR pMonitor) {
const bool ISMIRROR = pMonitor->isMirror();
// onModeChanged we check if the current mirror status matches the global.
@ -84,7 +84,7 @@ CProtocolManager::CProtocolManager() {
// Outputs are a bit dumb, we have to agree.
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
// this event is emitted iirc.
@ -103,7 +103,7 @@ CProtocolManager::CProtocolManager() {
});
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))
return;
PROTO::outputs.at(M->szName)->remove();

View file

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

View file

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

View file

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

View file

@ -172,7 +172,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
m_vLastCursorPosFloored = MOUSECOORDSFLOORED;
const auto PMONITOR = isLocked() && g_pCompositor->m_pLastMonitor ? g_pCompositor->m_pLastMonitor.get() : g_pCompositor->getMonitorFromCursor();
const auto PMONITOR = isLocked() && g_pCompositor->m_pLastMonitor ? g_pCompositor->m_pLastMonitor.lock() : g_pCompositor->getMonitorFromCursor();
// this can happen if there are no displays hooked up to Hyprland
if (PMONITOR == nullptr)
@ -212,7 +212,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
Debug::log(ERR, "BUG THIS: Null SURF/CONSTRAINT in mouse refocus. Ignoring constraints. {:x} {:x}", (uintptr_t)SURF.get(), (uintptr_t)CONSTRAINT.get());
}
if (PMONITOR != g_pCompositor->m_pLastMonitor.get() && (*PMOUSEFOCUSMON || refocus) && m_pForcedFocus.expired())
if (PMONITOR != g_pCompositor->m_pLastMonitor && (*PMOUSEFOCUSMON || refocus) && m_pForcedFocus.expired())
g_pCompositor->setActiveMonitor(PMONITOR);
if (g_pSessionLockManager->isSessionLocked()) {
@ -370,7 +370,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &surfaceCoords, &pFoundLayerSurface);
if (g_pPointerManager->softwareLockedFor(PMONITOR->self.lock()) > 0 && !skipFrameSchedule)
g_pCompositor->scheduleFrameForMonitor(g_pCompositor->m_pLastMonitor.get(), Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_MOVE);
g_pCompositor->scheduleFrameForMonitor(g_pCompositor->m_pLastMonitor.lock(), Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_MOVE);
// grabs
if (g_pSeatManager->seatGrab && !g_pSeatManager->seatGrab->accepts(foundSurface)) {
@ -720,7 +720,7 @@ void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e) {
// notify app if we didnt handle it
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 && PMON)
g_pCompositor->setActiveMonitor(PMON);
if (g_pSeatManager->seatGrab && e.state == WL_POINTER_BUTTON_STATE_PRESSED) {
@ -1359,7 +1359,7 @@ void CInputManager::refocus() {
mouseMoveUnified(0, true);
}
void CInputManager::refocusLastWindow(CMonitor* pMonitor) {
void CInputManager::refocusLastWindow(PHLMONITOR pMonitor) {
if (!pMonitor) {
refocus();
return;

View file

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

View file

@ -100,11 +100,11 @@ void CInputPopup::updateBox() {
cursorBoxParent = {0, 0, (int)parentBox.w, (int)parentBox.h};
}
Vector2D currentPopupSize = surface->getViewporterCorrectedSize() / surface->resource()->current.scale;
Vector2D currentPopupSize = surface->getViewporterCorrectedSize() / surface->resource()->current.scale;
CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle());
PHLMONITOR pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle());
Vector2D popupOffset(0, 0);
Vector2D popupOffset(0, 0);
if (parentBox.y + cursorBoxParent.y + cursorBoxParent.height + currentPopupSize.y > pMonitor->vecPosition.y + pMonitor->vecSize.y)
popupOffset.y -= currentPopupSize.y;

View file

@ -33,7 +33,7 @@ void CInputManager::beginWorkspaceSwipe() {
m_sActiveSwipe.pWorkspaceBegin = PWORKSPACE;
m_sActiveSwipe.delta = 0;
m_sActiveSwipe.pMonitor = g_pCompositor->m_pLastMonitor.get();
m_sActiveSwipe.pMonitor = g_pCompositor->m_pLastMonitor;
m_sActiveSwipe.avgSpeed = 0;
m_sActiveSwipe.speedPoints = 0;
@ -179,7 +179,7 @@ void CInputManager::endWorkspaceSwipe() {
}
m_sActiveSwipe.pWorkspaceBegin->rememberPrevWorkspace(pSwitchedTo);
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor);
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor.lock());
if (PWORKSPACEL)
PWORKSPACEL->m_bForceRendering = false;
@ -264,7 +264,7 @@ void CInputManager::updateWorkspaceSwipe(double delta) {
if (workspaceIDLeft > m_sActiveSwipe.pWorkspaceBegin->m_iID || !PWORKSPACE) {
if (*PSWIPENEW) {
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor);
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor.lock());
if (VERTANIMS)
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0.0, ((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * YDISTANCE));
@ -304,7 +304,7 @@ void CInputManager::updateWorkspaceSwipe(double delta) {
if (workspaceIDRight < m_sActiveSwipe.pWorkspaceBegin->m_iID || !PWORKSPACE) {
if (*PSWIPENEW) {
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor);
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor.lock());
if (VERTANIMS)
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0.0, ((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * YDISTANCE));
@ -341,7 +341,7 @@ void CInputManager::updateWorkspaceSwipe(double delta) {
g_pCompositor->updateWorkspaceWindowDecos(workspaceIDRight);
}
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor);
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor.lock());
g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID);

View file

@ -18,7 +18,7 @@ void CInputManager::onTouchDown(ITouch::SDownEvent e) {
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);