From bca7804bb6e1bf5ce5a99b9ae4806be25e36993c Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 27 Apr 2024 12:43:12 +0100 Subject: internal: Window storage rework - part 1 (#5762) * Window storage rework - part 1 * format * remove useless include * fix pch * format * fix crash in dwindle * fix vram leak * prefer .expired() for bool checks --- src/managers/AnimationManager.cpp | 22 ++-- src/managers/AnimationManager.hpp | 6 +- src/managers/KeybindManager.cpp | 214 ++++++++++++++++++----------------- src/managers/KeybindManager.hpp | 6 +- src/managers/XWaylandManager.cpp | 36 +++--- src/managers/XWaylandManager.hpp | 31 ++--- src/managers/input/IdleInhibitor.cpp | 8 +- src/managers/input/InputManager.cpp | 49 ++++---- src/managers/input/InputManager.hpp | 18 +-- src/managers/input/Tablets.cpp | 2 +- src/managers/input/Touch.cpp | 19 ++-- 11 files changed, 210 insertions(+), 201 deletions(-) (limited to 'src/managers') diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index f017a9e8..54bdc524 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -80,7 +80,7 @@ void CAnimationManager::tick() { const float SPENT = av->getPercent(); // window stuff - const auto PWINDOW = (CWindow*)av->m_pWindow; + PHLWINDOW PWINDOW = av->m_pWindow.lock(); PHLWORKSPACE PWORKSPACE = av->m_pWorkspace.lock(); const auto PLAYER = (SLayerSurface*)av->m_pLayer; CMonitor* PMONITOR = nullptr; @@ -121,19 +121,19 @@ void CAnimationManager::tick() { const CBox windowBoxNoOffset = w->getFullWindowBoundingBox(); const CBox monitorBox = {PMONITOR->vecPosition, PMONITOR->vecSize}; if (windowBoxNoOffset.intersection(monitorBox) != windowBoxNoOffset) // on edges between multiple monitors - g_pHyprRenderer->damageWindow(w.get(), true); + g_pHyprRenderer->damageWindow(w, true); } if (PWORKSPACE->m_bIsSpecialWorkspace) - g_pHyprRenderer->damageWindow(w.get(), true); // hack for special too because it can cross multiple monitors + g_pHyprRenderer->damageWindow(w, true); // hack for special too because it can cross multiple monitors } // damage any workspace window that is on any monitor for (auto& w : g_pCompositor->m_vWindows) { - if (!g_pCompositor->windowValidMapped(w.get()) || w->m_pWorkspace != PWORKSPACE || w->m_bPinned) + if (!validMapped(w) || w->m_pWorkspace != PWORKSPACE || w->m_bPinned) continue; - g_pHyprRenderer->damageWindow(w.get()); + g_pHyprRenderer->damageWindow(w); } } else if (PLAYER) { // "some fucking layers miss 1 pixel???" -- vaxry @@ -192,7 +192,7 @@ void CAnimationManager::tick() { default: UNREACHABLE(); } // set size and pos if valid, but only if damage policy entire (dont if border for example) - if (g_pCompositor->windowValidMapped(PWINDOW) && av->m_eDamagePolicy == AVARDAMAGE_ENTIRE && PWINDOW->m_iX11Type != 2) + if (validMapped(PWINDOW) && av->m_eDamagePolicy == AVARDAMAGE_ENTIRE && PWINDOW->m_iX11Type != 2) g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); // check if we did not finish animating. If so, trigger onAnimationEnd. @@ -213,14 +213,14 @@ void CAnimationManager::tick() { g_pHyprRenderer->damageWindow(PWINDOW); } else if (PWORKSPACE) { for (auto& w : g_pCompositor->m_vWindows) { - if (!g_pCompositor->windowValidMapped(w.get()) || w->m_pWorkspace != PWORKSPACE) + if (!validMapped(w) || w->m_pWorkspace != PWORKSPACE) continue; w->updateWindowDecos(); // damage any workspace window that is on any monitor if (!w->m_bPinned) - g_pHyprRenderer->damageWindow(w.get()); + g_pHyprRenderer->damageWindow(w); } } else if (PLAYER) { if (PLAYER->layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND || PLAYER->layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM) @@ -304,7 +304,7 @@ bool CAnimationManager::bezierExists(const std::string& bezier) { // // -void CAnimationManager::animationPopin(CWindow* pWindow, bool close, float minPerc) { +void CAnimationManager::animationPopin(PHLWINDOW pWindow, bool close, float minPerc) { const auto GOALPOS = pWindow->m_vRealPosition.goal(); const auto GOALSIZE = pWindow->m_vRealSize.goal(); @@ -317,7 +317,7 @@ void CAnimationManager::animationPopin(CWindow* pWindow, bool close, float minPe } } -void CAnimationManager::animationSlide(CWindow* pWindow, std::string force, bool close) { +void CAnimationManager::animationSlide(PHLWINDOW pWindow, std::string force, bool close) { pWindow->m_vRealSize.warp(false); // size we preserve in slide const auto GOALPOS = pWindow->m_vRealPosition.goal(); @@ -381,7 +381,7 @@ void CAnimationManager::animationSlide(CWindow* pWindow, std::string force, bool pWindow->m_vRealPosition = posOffset; } -void CAnimationManager::onWindowPostCreateClose(CWindow* pWindow, bool close) { +void CAnimationManager::onWindowPostCreateClose(PHLWINDOW pWindow, bool close) { if (!close) { pWindow->m_vRealPosition.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("windowsIn"); pWindow->m_vRealSize.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("windowsIn"); diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index 23729502..5d4d0e1c 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -21,7 +21,7 @@ class CAnimationManager { void addBezierWithName(std::string, const Vector2D&, const Vector2D&); void removeAllBeziers(); - void onWindowPostCreateClose(CWindow*, bool close = false); + void onWindowPostCreateClose(PHLWINDOW, bool close = false); bool bezierExists(const std::string&); CBezierCurve* getBezier(const std::string&); @@ -50,8 +50,8 @@ class CAnimationManager { bool m_bTickScheduled = false; // Anim stuff - void animationPopin(CWindow*, bool close = false, float minPerc = 0.f); - void animationSlide(CWindow*, std::string force = "", bool close = false); + void animationPopin(PHLWINDOW, bool close = false, float minPerc = 0.f); + void animationSlide(PHLWINDOW, std::string force = "", bool close = false); }; inline std::unique_ptr g_pAnimationManager; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 402c567f..996424cc 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -35,7 +35,7 @@ static std::vector> getHyprlandLaunchEnv() { result.push_back(std::make_pair<>( "HL_INITIAL_WORKSPACE_TOKEN", g_pTokenManager->registerNewToken( - SInitialWorkspaceToken{nullptr, PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace->getConfigName() : PMONITOR->activeWorkspace->getConfigName()}, + SInitialWorkspaceToken{{}, PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace->getConfigName() : PMONITOR->activeWorkspace->getConfigName()}, std::chrono::months(1337)))); return result; @@ -225,13 +225,13 @@ bool CKeybindManager::ensureMouseBindState() { if (!m_bIsMouseBindActive) return false; - if (g_pInputManager->currentlyDraggedWindow) { - CWindow* lastDraggedWindow = g_pInputManager->currentlyDraggedWindow; + if (!g_pInputManager->currentlyDraggedWindow.expired()) { + PHLWINDOW lastDraggedWindow = g_pInputManager->currentlyDraggedWindow.lock(); m_bIsMouseBindActive = false; g_pLayoutManager->getCurrentLayout()->onEndDragWindow(); - g_pInputManager->currentlyDraggedWindow = nullptr; - g_pInputManager->dragMode = MBIND_INVALID; + g_pInputManager->currentlyDraggedWindow.reset(); + g_pInputManager->dragMode = MBIND_INVALID; g_pCompositor->updateWorkspaceWindows(lastDraggedWindow->workspaceID()); g_pCompositor->updateWorkspaceSpecialRenderData(lastDraggedWindow->workspaceID()); @@ -271,7 +271,7 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) { g_pInputManager->m_pForcedFocus = PNEWWINDOW; g_pInputManager->simulateMouseMovement(); - g_pInputManager->m_pForcedFocus = nullptr; + g_pInputManager->m_pForcedFocus.reset(); } else { g_pCompositor->focusWindow(nullptr); g_pCompositor->warpCursorTo(monitor->middle()); @@ -281,8 +281,8 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) { return true; } -void CKeybindManager::switchToWindow(CWindow* PWINDOWTOCHANGETO) { - const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; +void CKeybindManager::switchToWindow(PHLWINDOW PWINDOWTOCHANGETO) { + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); if (PWINDOWTOCHANGETO == PLASTWINDOW || !PWINDOWTOCHANGETO) return; @@ -307,7 +307,7 @@ void CKeybindManager::switchToWindow(CWindow* PWINDOWTOCHANGETO) { g_pInputManager->m_pForcedFocus = PWINDOWTOCHANGETO; g_pInputManager->simulateMouseMovement(); - g_pInputManager->m_pForcedFocus = nullptr; + g_pInputManager->m_pForcedFocus.reset(); if (PLASTWINDOW && PLASTWINDOW->m_iMonitorID != PWINDOWTOCHANGETO->m_iMonitorID) { // event @@ -851,7 +851,7 @@ uint64_t CKeybindManager::spawnRaw(std::string args) { } void CKeybindManager::killActive(std::string args) { - g_pCompositor->closeWindow(g_pCompositor->m_pLastWindow); + g_pCompositor->closeWindow(g_pCompositor->m_pLastWindow.lock()); } void CKeybindManager::kill(std::string args) { @@ -870,12 +870,12 @@ void CKeybindManager::clearKeybinds() { } static void toggleActiveFloatingCore(std::string args, std::optional floatState) { - CWindow* PWINDOW = nullptr; + PHLWINDOW PWINDOW = nullptr; if (args != "active" && args.length() > 1) PWINDOW = g_pCompositor->getWindowByRegex(args); else - PWINDOW = g_pCompositor->m_pLastWindow; + PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) return; @@ -884,18 +884,18 @@ static void toggleActiveFloatingCore(std::string args, std::optional float return; // remove drag status - g_pInputManager->currentlyDraggedWindow = nullptr; + g_pInputManager->currentlyDraggedWindow.reset(); - if (PWINDOW->m_sGroupData.pNextWindow && PWINDOW->m_sGroupData.pNextWindow != PWINDOW) { + if (PWINDOW->m_sGroupData.pNextWindow.lock() && PWINDOW->m_sGroupData.pNextWindow.lock() != PWINDOW) { const auto PCURRENT = PWINDOW->getGroupCurrent(); PCURRENT->m_bIsFloating = !PCURRENT->m_bIsFloating; g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(PCURRENT); - CWindow* curr = PCURRENT->m_sGroupData.pNextWindow; + PHLWINDOW curr = PCURRENT->m_sGroupData.pNextWindow.lock(); while (curr != PCURRENT) { curr->m_bIsFloating = PCURRENT->m_bIsFloating; - curr = curr->m_sGroupData.pNextWindow; + curr = curr->m_sGroupData.pNextWindow.lock(); } } else { PWINDOW->m_bIsFloating = !PWINDOW->m_bIsFloating; @@ -921,7 +921,7 @@ void CKeybindManager::setActiveTiled(std::string args) { } void CKeybindManager::centerWindow(std::string args) { - const auto PWINDOW = g_pCompositor->m_pLastWindow; + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW || !PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen) return; @@ -937,7 +937,7 @@ void CKeybindManager::centerWindow(std::string args) { } void CKeybindManager::toggleActivePseudo(std::string args) { - const auto ACTIVEWINDOW = g_pCompositor->m_pLastWindow; + const auto ACTIVEWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!ACTIVEWINDOW) return; @@ -1046,7 +1046,7 @@ void CKeybindManager::changeworkspace(std::string args) { } void CKeybindManager::fullscreenActive(std::string args) { - const auto PWINDOW = g_pCompositor->m_pLastWindow; + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) return; @@ -1059,13 +1059,13 @@ void CKeybindManager::fullscreenActive(std::string args) { void CKeybindManager::moveActiveToWorkspace(std::string args) { - CWindow* PWINDOW = nullptr; + PHLWINDOW PWINDOW = nullptr; if (args.contains(',')) { PWINDOW = g_pCompositor->getWindowByRegex(args.substr(args.find_last_of(',') + 1)); args = args.substr(0, args.find_last_of(',')); } else { - PWINDOW = g_pCompositor->m_pLastWindow; + PWINDOW = g_pCompositor->m_pLastWindow.lock(); } if (!PWINDOW) @@ -1119,7 +1119,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { } void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { - CWindow* PWINDOW = nullptr; + PHLWINDOW PWINDOW = nullptr; const auto ORIGINALARGS = args; @@ -1127,7 +1127,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { PWINDOW = g_pCompositor->getWindowByRegex(args.substr(args.find_last_of(',') + 1)); args = args.substr(0, args.find_last_of(',')); } else { - PWINDOW = g_pCompositor->m_pLastWindow; + PWINDOW = g_pCompositor->m_pLastWindow.lock(); } if (!PWINDOW) @@ -1157,7 +1157,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, pWorkspace); } - if (PWINDOW == g_pCompositor->m_pLastWindow) { + if (PWINDOW == g_pCompositor->m_pLastWindow.lock()) { if (const auto PATCOORDS = g_pCompositor->vectorToWindowUnified(OLDMIDDLE, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING, PWINDOW); PATCOORDS) g_pCompositor->focusWindow(PATCOORDS); else @@ -1174,7 +1174,7 @@ void CKeybindManager::moveFocusTo(std::string args) { return; } - const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PLASTWINDOW) { tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(arg)); return; @@ -1208,8 +1208,8 @@ void CKeybindManager::moveFocusTo(std::string args) { void CKeybindManager::focusUrgentOrLast(std::string args) { const auto PWINDOWURGENT = g_pCompositor->getUrgentWindow(); - const auto PWINDOWPREV = g_pCompositor->m_pLastWindow ? (g_pCompositor->m_vWindowFocusHistory.size() < 2 ? nullptr : g_pCompositor->m_vWindowFocusHistory[1]) : - (g_pCompositor->m_vWindowFocusHistory.empty() ? nullptr : g_pCompositor->m_vWindowFocusHistory[0]); + const auto PWINDOWPREV = g_pCompositor->m_pLastWindow.lock() ? (g_pCompositor->m_vWindowFocusHistory.size() < 2 ? nullptr : g_pCompositor->m_vWindowFocusHistory[1].lock()) : + (g_pCompositor->m_vWindowFocusHistory.empty() ? nullptr : g_pCompositor->m_vWindowFocusHistory[0].lock()); if (!PWINDOWURGENT && !PWINDOWPREV) return; @@ -1218,8 +1218,8 @@ void CKeybindManager::focusUrgentOrLast(std::string args) { } void CKeybindManager::focusCurrentOrLast(std::string args) { - const auto PWINDOWPREV = g_pCompositor->m_pLastWindow ? (g_pCompositor->m_vWindowFocusHistory.size() < 2 ? nullptr : g_pCompositor->m_vWindowFocusHistory[1]) : - (g_pCompositor->m_vWindowFocusHistory.empty() ? nullptr : g_pCompositor->m_vWindowFocusHistory[0]); + const auto PWINDOWPREV = g_pCompositor->m_pLastWindow.lock() ? (g_pCompositor->m_vWindowFocusHistory.size() < 2 ? nullptr : g_pCompositor->m_vWindowFocusHistory[1].lock()) : + (g_pCompositor->m_vWindowFocusHistory.empty() ? nullptr : g_pCompositor->m_vWindowFocusHistory[0].lock()); if (!PWINDOWPREV) return; @@ -1236,7 +1236,7 @@ void CKeybindManager::swapActive(std::string args) { } Debug::log(LOG, "Swapping active window in direction {}", arg); - const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PLASTWINDOW || PLASTWINDOW->m_bIsFullscreen) return; @@ -1270,7 +1270,7 @@ void CKeybindManager::moveActiveTo(std::string args) { return; } - const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PLASTWINDOW || PLASTWINDOW->m_bIsFullscreen) return; @@ -1315,29 +1315,29 @@ void CKeybindManager::moveActiveTo(std::string args) { } void CKeybindManager::toggleGroup(std::string args) { - const auto PWINDOW = g_pCompositor->m_pLastWindow; + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) return; g_pCompositor->setWindowFullscreen(PWINDOW, false, FULLSCREEN_FULL); - if (!PWINDOW->m_sGroupData.pNextWindow) + if (PWINDOW->m_sGroupData.pNextWindow.expired()) PWINDOW->createGroup(); else PWINDOW->destroyGroup(); } void CKeybindManager::changeGroupActive(std::string args) { - const auto PWINDOW = g_pCompositor->m_pLastWindow; + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) return; - if (!PWINDOW->m_sGroupData.pNextWindow) + if (PWINDOW->m_sGroupData.pNextWindow.expired()) return; - if (PWINDOW->m_sGroupData.pNextWindow == PWINDOW) + if (PWINDOW->m_sGroupData.pNextWindow.lock() == PWINDOW) return; if (isNumber(args, false)) { @@ -1353,7 +1353,7 @@ void CKeybindManager::changeGroupActive(std::string args) { } if (args != "b" && args != "prev") { - PWINDOW->setGroupCurrent(PWINDOW->m_sGroupData.pNextWindow); + PWINDOW->setGroupCurrent(PWINDOW->m_sGroupData.pNextWindow.lock()); } else { PWINDOW->setGroupCurrent(PWINDOW->getGroupPrevious()); } @@ -1361,7 +1361,7 @@ void CKeybindManager::changeGroupActive(std::string args) { void CKeybindManager::toggleSplit(std::string args) { SLayoutMessageHeader header; - header.pWindow = g_pCompositor->m_pLastWindow; + header.pWindow = g_pCompositor->m_pLastWindow.lock(); if (!header.pWindow) return; @@ -1376,7 +1376,7 @@ void CKeybindManager::toggleSplit(std::string args) { void CKeybindManager::swapSplit(std::string args) { SLayoutMessageHeader header; - header.pWindow = g_pCompositor->m_pLastWindow; + header.pWindow = g_pCompositor->m_pLastWindow.lock(); if (!header.pWindow) return; @@ -1404,7 +1404,7 @@ void CKeybindManager::alterSplitRatio(std::string args) { return; } - const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PLASTWINDOW) return; @@ -1430,7 +1430,7 @@ void CKeybindManager::moveCursorToCorner(std::string arg) { return; } - const auto PWINDOW = g_pCompositor->m_pLastWindow; + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) return; @@ -1509,9 +1509,9 @@ void CKeybindManager::workspaceOpt(std::string args) { // apply // we make a copy because changeWindowFloatingMode might invalidate the iterator - std::deque ptrs; + std::deque ptrs; for (auto& w : g_pCompositor->m_vWindows) - ptrs.push_back(w.get()); + ptrs.push_back(w); for (auto& w : ptrs) { if (!w->m_bIsMapped || w->m_pWorkspace != PWORKSPACE || w->isHidden()) @@ -1719,27 +1719,31 @@ void CKeybindManager::forceRendererReload(std::string args) { } void CKeybindManager::resizeActive(std::string args) { - if (!g_pCompositor->m_pLastWindow || g_pCompositor->m_pLastWindow->m_bIsFullscreen) + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); + + if (!PLASTWINDOW || PLASTWINDOW->m_bIsFullscreen) return; - const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealSize.goal()); + const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(args, PLASTWINDOW->m_vRealSize.goal()); if (SIZ.x < 1 || SIZ.y < 1) return; - g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - g_pCompositor->m_pLastWindow->m_vRealSize.goal()); + g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - PLASTWINDOW->m_vRealSize.goal()); - if (g_pCompositor->m_pLastWindow->m_vRealSize.goal().x > 1 && g_pCompositor->m_pLastWindow->m_vRealSize.goal().y > 1) - g_pCompositor->m_pLastWindow->setHidden(false); + if (PLASTWINDOW->m_vRealSize.goal().x > 1 && PLASTWINDOW->m_vRealSize.goal().y > 1) + PLASTWINDOW->setHidden(false); } void CKeybindManager::moveActive(std::string args) { - if (!g_pCompositor->m_pLastWindow || g_pCompositor->m_pLastWindow->m_bIsFullscreen) + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); + + if (!PLASTWINDOW || PLASTWINDOW->m_bIsFullscreen) return; - const auto POS = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealPosition.goal()); + const auto POS = g_pCompositor->parseWindowVectorArgsRelative(args, PLASTWINDOW->m_vRealPosition.goal()); - g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - g_pCompositor->m_pLastWindow->m_vRealPosition.goal()); + g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - PLASTWINDOW->m_vRealPosition.goal()); } void CKeybindManager::moveWindow(std::string args) { @@ -1790,7 +1794,7 @@ void CKeybindManager::resizeWindow(std::string args) { void CKeybindManager::circleNext(std::string arg) { - if (!g_pCompositor->m_pLastWindow) { + if (g_pCompositor->m_pLastWindow.expired()) { // if we have a clear focus, find the first window and get the next focusable. if (g_pCompositor->getWindowsOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspaceID()) > 0) { const auto PWINDOW = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspaceID()); @@ -1810,9 +1814,9 @@ void CKeybindManager::circleNext(std::string arg) { floatStatus = true; if (args.contains("prev") || args.contains("p") || args.contains("last") || args.contains("l")) - switchToWindow(g_pCompositor->getPrevWindowOnWorkspace(g_pCompositor->m_pLastWindow, true, floatStatus)); + switchToWindow(g_pCompositor->getPrevWindowOnWorkspace(g_pCompositor->m_pLastWindow.lock(), true, floatStatus)); else - switchToWindow(g_pCompositor->getNextWindowOnWorkspace(g_pCompositor->m_pLastWindow, true, floatStatus)); + switchToWindow(g_pCompositor->getNextWindowOnWorkspace(g_pCompositor->m_pLastWindow.lock(), true, floatStatus)); } void CKeybindManager::focusWindow(std::string regexp) { @@ -1902,7 +1906,7 @@ void CKeybindManager::pass(std::string regexp) { return; } - const auto XWTOXW = PWINDOW->m_bIsX11 && g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsX11; + const auto XWTOXW = PWINDOW->m_bIsX11 && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock()->m_bIsX11; const auto SL = Vector2D(g_pCompositor->m_sSeat.seat->pointer_state.sx, g_pCompositor->m_sSeat.seat->pointer_state.sy); uint32_t keycodes[32] = {0}; @@ -1961,12 +1965,12 @@ void CKeybindManager::pass(std::string regexp) { } void CKeybindManager::layoutmsg(std::string msg) { - SLayoutMessageHeader hd = {g_pCompositor->m_pLastWindow}; + SLayoutMessageHeader hd = {g_pCompositor->m_pLastWindow.lock()}; g_pLayoutManager->getCurrentLayout()->layoutMessage(hd, msg); } void CKeybindManager::toggleOpaque(std::string unused) { - const auto PWINDOW = g_pCompositor->m_pLastWindow; + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) return; @@ -2009,16 +2013,16 @@ void CKeybindManager::dpms(std::string arg) { void CKeybindManager::swapnext(std::string arg) { - CWindow* toSwap = nullptr; + PHLWINDOW toSwap = nullptr; - if (!g_pCompositor->m_pLastWindow) + if (g_pCompositor->m_pLastWindow.expired()) return; - const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); - const auto PLASTCYCLED = g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow->m_pLastCycledWindow) && - g_pCompositor->m_pLastWindow->m_pLastCycledWindow->m_pWorkspace == PLASTWINDOW->m_pWorkspace ? - g_pCompositor->m_pLastWindow->m_pLastCycledWindow : + const auto PLASTCYCLED = validMapped(g_pCompositor->m_pLastWindow.lock()->m_pLastCycledWindow) && + g_pCompositor->m_pLastWindow.lock()->m_pLastCycledWindow.lock()->m_pWorkspace == PLASTWINDOW->m_pWorkspace ? + g_pCompositor->m_pLastWindow.lock()->m_pLastCycledWindow.lock() : nullptr; if (arg == "last" || arg == "l" || arg == "prev" || arg == "p") @@ -2056,12 +2060,12 @@ void CKeybindManager::swapActiveWorkspaces(std::string args) { void CKeybindManager::pinActive(std::string args) { - CWindow* PWINDOW = nullptr; + PHLWINDOW PWINDOW = nullptr; if (args != "active" && args.length() > 1) PWINDOW = g_pCompositor->getWindowByRegex(args); else - PWINDOW = g_pCompositor->m_pLastWindow; + PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) { Debug::log(ERR, "pin: window not found"); @@ -2081,7 +2085,7 @@ void CKeybindManager::pinActive(std::string args) { PWORKSPACE->m_pLastFocusedWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS); - g_pEventManager->postEvent(SHyprIPCEvent{"pin", std::format("{:x},{}", (uintptr_t)PWINDOW, (int)PWINDOW->m_bPinned)}); + g_pEventManager->postEvent(SHyprIPCEvent{"pin", std::format("{:x},{}", (uintptr_t)PWINDOW.get(), (int)PWINDOW->m_bPinned)}); EMIT_HOOK_EVENT("pin", PWINDOW); } @@ -2094,12 +2098,12 @@ void CKeybindManager::mouse(std::string args) { g_pKeybindManager->m_bIsMouseBindActive = true; const auto mouseCoords = g_pInputManager->getMouseCoordsInternal(); - CWindow* pWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + PHLWINDOW pWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (pWindow && !pWindow->m_bIsFullscreen) pWindow->checkInputOnDecos(INPUT_TYPE_DRAG_START, mouseCoords); - if (!g_pInputManager->currentlyDraggedWindow) + if (g_pInputManager->currentlyDraggedWindow.expired()) g_pInputManager->currentlyDraggedWindow = pWindow; g_pInputManager->dragMode = MBIND_MOVE; @@ -2107,10 +2111,10 @@ void CKeybindManager::mouse(std::string args) { } else { g_pKeybindManager->m_bIsMouseBindActive = false; - if (g_pInputManager->currentlyDraggedWindow) { + if (!g_pInputManager->currentlyDraggedWindow.expired()) { g_pLayoutManager->getCurrentLayout()->onEndDragWindow(); - g_pInputManager->currentlyDraggedWindow = nullptr; - g_pInputManager->dragMode = MBIND_INVALID; + g_pInputManager->currentlyDraggedWindow.reset(); + g_pInputManager->dragMode = MBIND_INVALID; } } } else if (ARGS[0] == "resizewindow") { @@ -2131,18 +2135,18 @@ void CKeybindManager::mouse(std::string args) { } else { g_pKeybindManager->m_bIsMouseBindActive = false; - if (g_pInputManager->currentlyDraggedWindow) { + if (!g_pInputManager->currentlyDraggedWindow.expired()) { g_pLayoutManager->getCurrentLayout()->onEndDragWindow(); - g_pInputManager->currentlyDraggedWindow = nullptr; - g_pInputManager->dragMode = MBIND_INVALID; + g_pInputManager->currentlyDraggedWindow.reset(); + g_pInputManager->dragMode = MBIND_INVALID; } } } } void CKeybindManager::bringActiveToTop(std::string args) { - if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsFloating) - g_pCompositor->changeWindowZOrder(g_pCompositor->m_pLastWindow, true); + if (g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock()->m_bIsFloating) + g_pCompositor->changeWindowZOrder(g_pCompositor->m_pLastWindow.lock(), true); } void CKeybindManager::alterZOrder(std::string args) { @@ -2150,8 +2154,8 @@ void CKeybindManager::alterZOrder(std::string args) { const auto POSITION = args.substr(0, args.find_first_of(',')); auto PWINDOW = g_pCompositor->getWindowByRegex(WINDOWREGEX); - if (!PWINDOW && g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsFloating) - PWINDOW = g_pCompositor->m_pLastWindow; + if (!PWINDOW && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock()->m_bIsFloating) + PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) { Debug::log(ERR, "alterZOrder: no window"); @@ -2171,10 +2175,10 @@ void CKeybindManager::alterZOrder(std::string args) { } void CKeybindManager::fakeFullscreenActive(std::string args) { - if (g_pCompositor->m_pLastWindow) { + if (!g_pCompositor->m_pLastWindow.expired()) { // will also set the flag - g_pCompositor->m_pLastWindow->m_bFakeFullscreenState = !g_pCompositor->m_pLastWindow->m_bFakeFullscreenState; - g_pXWaylandManager->setWindowFullscreen(g_pCompositor->m_pLastWindow, g_pCompositor->m_pLastWindow->shouldSendFullscreenState()); + g_pCompositor->m_pLastWindow.lock()->m_bFakeFullscreenState = !g_pCompositor->m_pLastWindow.lock()->m_bFakeFullscreenState; + g_pXWaylandManager->setWindowFullscreen(g_pCompositor->m_pLastWindow.lock(), g_pCompositor->m_pLastWindow.lock()->shouldSendFullscreenState()); } } @@ -2190,9 +2194,9 @@ void CKeybindManager::lockGroups(std::string args) { } void CKeybindManager::lockActiveGroup(std::string args) { - const auto PWINDOW = g_pCompositor->m_pLastWindow; + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); - if (!PWINDOW || !PWINDOW->m_sGroupData.pNextWindow) + if (!PWINDOW || !PWINDOW->m_sGroupData.pNextWindow.lock()) return; const auto PHEAD = PWINDOW->getGroupHead(); @@ -2207,7 +2211,7 @@ void CKeybindManager::lockActiveGroup(std::string args) { g_pCompositor->updateWindowAnimatedDecorationValues(PWINDOW); } -void CKeybindManager::moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDirection) { +void CKeybindManager::moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection) { if (pWindow->m_sGroupData.deny) return; @@ -2227,7 +2231,7 @@ void CKeybindManager::moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDi pWindow->addWindowDeco(std::make_unique(pWindow)); } -void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir) { +void CKeybindManager::moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir) { static auto BFOCUSREMOVEDWINDOW = CConfigValue("group:focus_removed_window"); const auto PWINDOWPREV = pWindow->getGroupPrevious(); eDirection direction; @@ -2242,7 +2246,7 @@ void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow, const std::string& default: direction = DIRECTION_DEFAULT; } - if (pWindow->m_sGroupData.pNextWindow == pWindow) { + if (pWindow->m_sGroupData.pNextWindow.lock() == pWindow) { pWindow->destroyGroup(); } else { g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow); @@ -2277,18 +2281,18 @@ void CKeybindManager::moveIntoGroup(std::string args) { return; } - const auto PWINDOW = g_pCompositor->m_pLastWindow; + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW || PWINDOW->m_bIsFloating || PWINDOW->m_sGroupData.deny) return; auto PWINDOWINDIR = g_pCompositor->getWindowInDirection(PWINDOW, arg); - if (!PWINDOWINDIR || !PWINDOWINDIR->m_sGroupData.pNextWindow) + if (!PWINDOWINDIR || !PWINDOWINDIR->m_sGroupData.pNextWindow.lock()) return; // Do not move window into locked group if binds:ignore_group_lock is false - if (!*PIGNOREGROUPLOCK && (PWINDOWINDIR->getGroupHead()->m_sGroupData.locked || (PWINDOW->m_sGroupData.pNextWindow && PWINDOW->getGroupHead()->m_sGroupData.locked))) + if (!*PIGNOREGROUPLOCK && (PWINDOWINDIR->getGroupHead()->m_sGroupData.locked || (PWINDOW->m_sGroupData.pNextWindow.lock() && PWINDOW->getGroupHead()->m_sGroupData.locked))) return; moveWindowIntoGroup(PWINDOW, PWINDOWINDIR); @@ -2300,14 +2304,14 @@ void CKeybindManager::moveOutOfGroup(std::string args) { if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) return; - CWindow* PWINDOW = nullptr; + PHLWINDOW PWINDOW = nullptr; if (args != "active" && args.length() > 1) PWINDOW = g_pCompositor->getWindowByRegex(args); else - PWINDOW = g_pCompositor->m_pLastWindow; + PWINDOW = g_pCompositor->m_pLastWindow.lock(); - if (!PWINDOW || !PWINDOW->m_sGroupData.pNextWindow) + if (!PWINDOW || !PWINDOW->m_sGroupData.pNextWindow.lock()) return; moveWindowOutOfGroup(PWINDOW); @@ -2323,7 +2327,7 @@ void CKeybindManager::moveWindowOrGroup(std::string args) { return; } - const auto PWINDOW = g_pCompositor->m_pLastWindow; + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW || PWINDOW->m_bIsFullscreen) return; @@ -2334,12 +2338,12 @@ void CKeybindManager::moveWindowOrGroup(std::string args) { const auto PWINDOWINDIR = g_pCompositor->getWindowInDirection(PWINDOW, arg); - const bool ISWINDOWGROUP = PWINDOW->m_sGroupData.pNextWindow; + const bool ISWINDOWGROUP = PWINDOW->m_sGroupData.pNextWindow.lock().get(); const bool ISWINDOWGROUPLOCKED = ISWINDOWGROUP && PWINDOW->getGroupHead()->m_sGroupData.locked; - const bool ISWINDOWGROUPSINGLE = ISWINDOWGROUP && PWINDOW->m_sGroupData.pNextWindow == PWINDOW; + const bool ISWINDOWGROUPSINGLE = ISWINDOWGROUP && PWINDOW->m_sGroupData.pNextWindow.lock() == PWINDOW; // note: PWINDOWINDIR is not null implies !PWINDOW->m_bIsFloating - if (PWINDOWINDIR && PWINDOWINDIR->m_sGroupData.pNextWindow) { // target is group + if (PWINDOWINDIR && PWINDOWINDIR->m_sGroupData.pNextWindow.lock()) { // target is group if (!*PIGNOREGROUPLOCK && (PWINDOWINDIR->getGroupHead()->m_sGroupData.locked || ISWINDOWGROUPLOCKED || PWINDOW->m_sGroupData.deny)) { g_pLayoutManager->getCurrentLayout()->moveWindowTo(PWINDOW, args); g_pCompositor->warpCursorTo(PWINDOW->middle()); @@ -2373,8 +2377,8 @@ void CKeybindManager::setIgnoreGroupLock(std::string args) { } void CKeybindManager::denyWindowFromGroup(std::string args) { - const auto PWINDOW = g_pCompositor->m_pLastWindow; - if (!PWINDOW || (PWINDOW && PWINDOW->m_sGroupData.pNextWindow)) + const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); + if (!PWINDOW || (PWINDOW && PWINDOW->m_sGroupData.pNextWindow.lock())) return; if (args == "toggle") @@ -2401,14 +2405,16 @@ void CKeybindManager::global(std::string args) { void CKeybindManager::moveGroupWindow(std::string args) { const auto BACK = args == "b" || args == "prev"; - if (!g_pCompositor->m_pLastWindow || !g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow) + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); + + if (!PLASTWINDOW || !PLASTWINDOW->m_sGroupData.pNextWindow.lock()) return; - if ((!BACK && g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow->m_sGroupData.head) || (BACK && g_pCompositor->m_pLastWindow->m_sGroupData.head)) { - std::swap(g_pCompositor->m_pLastWindow->m_sGroupData.head, g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow->m_sGroupData.head); - std::swap(g_pCompositor->m_pLastWindow->m_sGroupData.locked, g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow->m_sGroupData.locked); + if ((!BACK && PLASTWINDOW->m_sGroupData.pNextWindow.lock()->m_sGroupData.head) || (BACK && PLASTWINDOW->m_sGroupData.head)) { + std::swap(PLASTWINDOW->m_sGroupData.head, PLASTWINDOW->m_sGroupData.pNextWindow.lock()->m_sGroupData.head); + std::swap(PLASTWINDOW->m_sGroupData.locked, PLASTWINDOW->m_sGroupData.pNextWindow.lock()->m_sGroupData.locked); } else - g_pCompositor->m_pLastWindow->switchWithWindowInGroup(BACK ? g_pCompositor->m_pLastWindow->getGroupPrevious() : g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow); + PLASTWINDOW->switchWithWindowInGroup(BACK ? PLASTWINDOW->getGroupPrevious() : PLASTWINDOW->m_sGroupData.pNextWindow.lock()); - g_pCompositor->m_pLastWindow->updateWindowDecos(); + PLASTWINDOW->updateWindowDecos(); } diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index b0587b7f..deb25ae9 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -111,9 +111,9 @@ class CKeybindManager { bool ensureMouseBindState(); static bool tryMoveFocusToMonitor(CMonitor* monitor); - static void moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir = ""); - static void moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDirection); - static void switchToWindow(CWindow* PWINDOWTOCHANGETO); + static void moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir = ""); + static void moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection); + static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO); // -------------- Dispatchers -------------- // static void killActive(std::string); diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index c589c981..cbfc43d8 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -29,7 +29,7 @@ CHyprXWaylandManager::CHyprXWaylandManager() { CHyprXWaylandManager::~CHyprXWaylandManager() {} -wlr_surface* CHyprXWaylandManager::getWindowSurface(CWindow* pWindow) { +wlr_surface* CHyprXWaylandManager::getWindowSurface(PHLWINDOW pWindow) { if (pWindow->m_bIsX11) return pWindow->m_uSurface.xwayland->surface; @@ -53,7 +53,7 @@ void CHyprXWaylandManager::activateSurface(wlr_surface* pSurface, bool activate) } } -void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) { +void CHyprXWaylandManager::activateWindow(PHLWINDOW pWindow, bool activate) { if (pWindow->m_bIsX11) { setWindowSize(pWindow, pWindow->m_vRealSize.value()); // update xwayland output pos @@ -76,7 +76,7 @@ void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) { pWindow->m_pWorkspace->m_pLastFocusedWindow = pWindow; } -void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, CBox* pbox) { +void CHyprXWaylandManager::getGeometryForWindow(PHLWINDOW pWindow, CBox* pbox) { if (pWindow->m_bIsX11) { const auto SIZEHINTS = pWindow->m_uSurface.xwayland->size_hints; @@ -97,7 +97,7 @@ void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, CBox* pbox) { } } -std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { +std::string CHyprXWaylandManager::getTitle(PHLWINDOW pWindow) { try { if (pWindow->m_bIsX11) { if (!pWindow->m_bIsMapped) @@ -121,7 +121,7 @@ std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { return ""; } -std::string CHyprXWaylandManager::getAppIDClass(CWindow* pWindow) { +std::string CHyprXWaylandManager::getAppIDClass(PHLWINDOW pWindow) { try { if (pWindow->m_bIsX11) { if (!pWindow->m_bIsMapped) @@ -144,14 +144,14 @@ std::string CHyprXWaylandManager::getAppIDClass(CWindow* pWindow) { return ""; } -void CHyprXWaylandManager::sendCloseWindow(CWindow* pWindow) { +void CHyprXWaylandManager::sendCloseWindow(PHLWINDOW pWindow) { if (pWindow->m_bIsX11) wlr_xwayland_surface_close(pWindow->m_uSurface.xwayland); else wlr_xdg_toplevel_send_close(pWindow->m_uSurface.xdg->toplevel); } -void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, Vector2D size, bool force) { +void CHyprXWaylandManager::setWindowSize(PHLWINDOW pWindow, Vector2D size, bool force) { static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); @@ -189,7 +189,7 @@ void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, Vector2D size, bool f pWindow->m_vPendingSizeAcks.push_back(std::make_pair<>(wlr_xdg_toplevel_set_size(pWindow->m_uSurface.xdg->toplevel, size.x, size.y), size.floor())); } -void CHyprXWaylandManager::setWindowStyleTiled(CWindow* pWindow, uint32_t edgez) { +void CHyprXWaylandManager::setWindowStyleTiled(PHLWINDOW pWindow, uint32_t edgez) { if (pWindow->m_bIsX11) return; @@ -197,14 +197,14 @@ void CHyprXWaylandManager::setWindowStyleTiled(CWindow* pWindow, uint32_t edgez) wlr_xdg_toplevel_set_maximized(pWindow->m_uSurface.xdg->toplevel, true); } -wlr_surface* CHyprXWaylandManager::surfaceAt(CWindow* pWindow, const Vector2D& client, Vector2D& surface) { +wlr_surface* CHyprXWaylandManager::surfaceAt(PHLWINDOW pWindow, const Vector2D& client, Vector2D& surface) { if (pWindow->m_bIsX11) return wlr_surface_surface_at(pWindow->m_uSurface.xwayland->surface, client.x, client.y, &surface.x, &surface.y); return wlr_xdg_surface_surface_at(pWindow->m_uSurface.xdg, client.x, client.y, &surface.x, &surface.y); } -bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow, bool pending) { +bool CHyprXWaylandManager::shouldBeFloated(PHLWINDOW pWindow, bool pending) { if (pWindow->m_bIsX11) { for (size_t i = 0; i < pWindow->m_uSurface.xwayland->window_type_len; i++) if (pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_DIALOG"] || @@ -257,8 +257,8 @@ bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow, bool pending) { return false; } -void CHyprXWaylandManager::moveXWaylandWindow(CWindow* pWindow, const Vector2D& pos) { - if (!g_pCompositor->windowValidMapped(pWindow)) +void CHyprXWaylandManager::moveXWaylandWindow(PHLWINDOW pWindow, const Vector2D& pos) { + if (!validMapped(pWindow)) return; if (!pWindow->m_bIsX11) @@ -267,7 +267,7 @@ void CHyprXWaylandManager::moveXWaylandWindow(CWindow* pWindow, const Vector2D& wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.value().x, pWindow->m_vRealSize.value().y); } -void CHyprXWaylandManager::checkBorders(CWindow* pWindow) { +void CHyprXWaylandManager::checkBorders(PHLWINDOW pWindow) { if (!pWindow->m_bIsX11) return; @@ -290,15 +290,15 @@ void CHyprXWaylandManager::checkBorders(CWindow* pWindow) { } } -void CHyprXWaylandManager::setWindowFullscreen(CWindow* pWindow, bool fullscreen) { +void CHyprXWaylandManager::setWindowFullscreen(PHLWINDOW pWindow, bool fullscreen) { if (pWindow->m_bIsX11) wlr_xwayland_surface_set_fullscreen(pWindow->m_uSurface.xwayland, fullscreen); else wlr_xdg_toplevel_set_fullscreen(pWindow->m_uSurface.xdg->toplevel, fullscreen); } -Vector2D CHyprXWaylandManager::getMaxSizeForWindow(CWindow* pWindow) { - if (!g_pCompositor->windowValidMapped(pWindow)) +Vector2D CHyprXWaylandManager::getMaxSizeForWindow(PHLWINDOW pWindow) { + if (!validMapped(pWindow)) return Vector2D(99999, 99999); if ((pWindow->m_bIsX11 && !pWindow->m_uSurface.xwayland->size_hints) || (!pWindow->m_bIsX11 && !pWindow->m_uSurface.xdg->toplevel) || @@ -316,8 +316,8 @@ Vector2D CHyprXWaylandManager::getMaxSizeForWindow(CWindow* pWindow) { return MAXSIZE; } -Vector2D CHyprXWaylandManager::getMinSizeForWindow(CWindow* pWindow) { - if (!g_pCompositor->windowValidMapped(pWindow)) +Vector2D CHyprXWaylandManager::getMinSizeForWindow(PHLWINDOW pWindow) { + if (!validMapped(pWindow)) return Vector2D(0, 0); if ((pWindow->m_bIsX11 && !pWindow->m_uSurface.xwayland->size_hints) || (!pWindow->m_bIsX11 && !pWindow->m_uSurface.xdg->toplevel)) diff --git a/src/managers/XWaylandManager.hpp b/src/managers/XWaylandManager.hpp index c374f579..6edadd71 100644 --- a/src/managers/XWaylandManager.hpp +++ b/src/managers/XWaylandManager.hpp @@ -4,6 +4,7 @@ #include class CWindow; // because clangd +typedef SP PHLWINDOW; class CHyprXWaylandManager { public: @@ -12,22 +13,22 @@ class CHyprXWaylandManager { wlr_xwayland* m_sWLRXWayland = nullptr; - wlr_surface* getWindowSurface(CWindow*); + wlr_surface* getWindowSurface(PHLWINDOW); void activateSurface(wlr_surface*, bool); - void activateWindow(CWindow*, bool); - void getGeometryForWindow(CWindow*, CBox*); - std::string getTitle(CWindow*); - std::string getAppIDClass(CWindow*); - void sendCloseWindow(CWindow*); - void setWindowSize(CWindow*, Vector2D, bool force = false); - void setWindowStyleTiled(CWindow*, uint32_t); - void setWindowFullscreen(CWindow*, bool); - wlr_surface* surfaceAt(CWindow*, const Vector2D&, Vector2D&); - bool shouldBeFloated(CWindow*, bool pending = false); - void moveXWaylandWindow(CWindow*, const Vector2D&); - void checkBorders(CWindow*); - Vector2D getMaxSizeForWindow(CWindow*); - Vector2D getMinSizeForWindow(CWindow*); + void activateWindow(PHLWINDOW, bool); + void getGeometryForWindow(PHLWINDOW, CBox*); + std::string getTitle(PHLWINDOW); + std::string getAppIDClass(PHLWINDOW); + void sendCloseWindow(PHLWINDOW); + void setWindowSize(PHLWINDOW, Vector2D, bool force = false); + void setWindowStyleTiled(PHLWINDOW, uint32_t); + void setWindowFullscreen(PHLWINDOW, bool); + wlr_surface* surfaceAt(PHLWINDOW, const Vector2D&, Vector2D&); + bool shouldBeFloated(PHLWINDOW, bool pending = false); + void moveXWaylandWindow(PHLWINDOW, const Vector2D&); + void checkBorders(PHLWINDOW); + Vector2D getMaxSizeForWindow(PHLWINDOW); + Vector2D getMinSizeForWindow(PHLWINDOW); Vector2D xwaylandToWaylandCoords(const Vector2D&); }; diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp index b5e6feb2..6ec5fc81 100644 --- a/src/managers/input/IdleInhibitor.cpp +++ b/src/managers/input/IdleInhibitor.cpp @@ -19,7 +19,7 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) { PINHIBIT->pWindow = PWINDOW; PINHIBIT->windowDestroyListener = PWINDOW->events.destroy.registerListener([PINHIBIT](std::any data) { Debug::log(WARN, "Inhibitor got its window destroyed before its inhibitor resource."); - PINHIBIT->pWindow = nullptr; + PINHIBIT->pWindow.reset(); }); } else Debug::log(WARN, "Inhibitor is for no window?"); @@ -29,10 +29,10 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) { void CInputManager::recheckIdleInhibitorStatus() { for (auto& ii : m_vIdleInhibitors) { - if (!ii->pWindow) { + if (ii->pWindow.expired()) { g_pCompositor->setIdleActivityInhibit(false); return; - } else if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow)) { + } else if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow.lock())) { g_pCompositor->setIdleActivityInhibit(false); return; } @@ -48,7 +48,7 @@ void CInputManager::recheckIdleInhibitorStatus() { return; } - if (w->m_eIdleInhibitMode == IDLEINHIBIT_FOCUS && g_pCompositor->isWindowActive(w.get())) { + if (w->m_eIdleInhibitMode == IDLEINHIBIT_FOCUS && g_pCompositor->isWindowActive(w)) { g_pCompositor->setIdleActivityInhibit(false); return; } diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index b930838b..adfa5029 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -118,13 +118,13 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { const auto FOLLOWMOUSE = *PFOLLOWONDND && m_sDrag.drag ? 1 : *PFOLLOWMOUSE; - m_pFoundSurfaceToFocus = nullptr; - m_pFoundLSToFocus = nullptr; - m_pFoundWindowToFocus = nullptr; + m_pFoundSurfaceToFocus = nullptr; + m_pFoundLSToFocus = nullptr; + m_pFoundWindowToFocus.reset(); wlr_surface* foundSurface = nullptr; Vector2D surfaceCoords; - Vector2D surfacePos = Vector2D(-1337, -1337); - CWindow* pFoundWindow = nullptr; + Vector2D surfacePos = Vector2D(-1337, -1337); + PHLWINDOW pFoundWindow; SLayerSurface* pFoundLayerSurface = nullptr; if (!g_pCompositor->m_bReadyToProcess || g_pCompositor->m_bIsShuttingDown || g_pCompositor->m_bUnsafeState) @@ -157,10 +157,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (*PZOOMFACTOR != 1.f) g_pHyprRenderer->damageMonitor(PMONITOR); - if (!PMONITOR->solitaryClient && g_pHyprRenderer->shouldRenderCursor() && PMONITOR->output->software_cursor_locks > 0) + if (!PMONITOR->solitaryClient.lock() && g_pHyprRenderer->shouldRenderCursor() && PMONITOR->output->software_cursor_locks > 0) g_pCompositor->scheduleFrameForMonitor(PMONITOR); - CWindow* forcedFocus = m_pForcedFocus; + PHLWINDOW forcedFocus = m_pForcedFocus.lock(); if (!forcedFocus) forcedFocus = g_pCompositor->getForceFocus(); @@ -213,9 +213,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { surfacePos = foundPopup->globalBox().pos(); m_bFocusHeldByButtons = true; m_bRefocusHeldByButtons = refocus; - } else if (g_pCompositor->m_pLastWindow) { + } else if (!g_pCompositor->m_pLastWindow.expired()) { foundSurface = m_pLastMouseSurface; - pFoundWindow = g_pCompositor->m_pLastWindow; + pFoundWindow = g_pCompositor->m_pLastWindow.lock(); surfaceCoords = g_pCompositor->vectorToSurfaceLocal(mouseCoords, pFoundWindow, foundSurface); m_bFocusHeldByButtons = true; @@ -226,7 +226,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { g_pLayoutManager->getCurrentLayout()->onMouseMove(getMouseCoordsInternal()); - if (PMONITOR && PMONITOR != g_pCompositor->m_pLastMonitor && (*PMOUSEFOCUSMON || refocus) && !m_pForcedFocus) + if (PMONITOR && PMONITOR != g_pCompositor->m_pLastMonitor && (*PMOUSEFOCUSMON || refocus) && m_pForcedFocus.expired()) g_pCompositor->setActiveMonitor(PMONITOR); if (g_pSessionLockManager->isSessionLocked()) { @@ -356,7 +356,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { wlr_seat_pointer_clear_focus(g_pCompositor->m_sSeat.seat); m_pLastMouseSurface = nullptr; - if (refocus || !g_pCompositor->m_pLastWindow) // if we are forcing a refocus, and we don't find a surface, clear the kb focus too! + if (refocus || g_pCompositor->m_pLastWindow.expired()) // if we are forcing a refocus, and we don't find a surface, clear the kb focus too! g_pCompositor->focusWindow(nullptr); return; @@ -393,7 +393,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { m_pFoundSurfaceToFocus = foundSurface; } - if (currentlyDraggedWindow && pFoundWindow != currentlyDraggedWindow) { + if (currentlyDraggedWindow.lock() && pFoundWindow != currentlyDraggedWindow.lock()) { wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); return; @@ -418,8 +418,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { } if (FOLLOWMOUSE != 1 && !refocus) { - if (pFoundWindow != g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow && - ((pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR == 2) || (g_pCompositor->m_pLastWindow->m_bIsFloating != pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR != 0))) { + if (pFoundWindow != g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock() && + ((pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR == 2) || + (g_pCompositor->m_pLastWindow.lock()->m_bIsFloating != pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR != 0))) { // enter if change floating style if (FOLLOWMOUSE != 3 && allowKeyboardRefocus) g_pCompositor->focusWindow(pFoundWindow, foundSurface); @@ -430,24 +431,24 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); } - if (pFoundWindow == g_pCompositor->m_pLastWindow) { + if (pFoundWindow == g_pCompositor->m_pLastWindow.lock()) { m_pLastMouseSurface = foundSurface; wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); } - if (FOLLOWMOUSE != 0 || pFoundWindow == g_pCompositor->m_pLastWindow) + if (FOLLOWMOUSE != 0 || pFoundWindow == g_pCompositor->m_pLastWindow.lock()) wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); m_bLastFocusOnLS = false; return; // don't enter any new surfaces } else { - if (allowKeyboardRefocus && ((FOLLOWMOUSE != 3 && (*PMOUSEREFOCUS || m_pLastMouseFocus != pFoundWindow)) || refocus)) { - if (m_pLastMouseFocus != pFoundWindow || g_pCompositor->m_pLastWindow != pFoundWindow || g_pCompositor->m_pLastFocus != foundSurface || refocus) { + if (allowKeyboardRefocus && ((FOLLOWMOUSE != 3 && (*PMOUSEREFOCUS || m_pLastMouseFocus.lock() != pFoundWindow)) || refocus)) { + if (m_pLastMouseFocus.lock() != pFoundWindow || g_pCompositor->m_pLastWindow.lock() != pFoundWindow || g_pCompositor->m_pLastFocus != foundSurface || refocus) { m_pLastMouseFocus = pFoundWindow; // TODO: this looks wrong. When over a popup, it constantly is switching. // Temp fix until that's figured out. Otherwise spams windowrule lookups and other shit. - if (m_pLastMouseFocus != pFoundWindow || g_pCompositor->m_pLastWindow != pFoundWindow) + if (m_pLastMouseFocus.lock() != pFoundWindow || g_pCompositor->m_pLastWindow.lock() != pFoundWindow) g_pCompositor->focusWindow(pFoundWindow, foundSurface); else g_pCompositor->focusSurface(foundSurface, pFoundWindow); @@ -642,7 +643,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { break; if ((!g_pCompositor->m_sSeat.mouse || !isConstrained()) /* No constraints */ - && (w && g_pCompositor->m_pLastWindow != w) /* window should change */) { + && (w && g_pCompositor->m_pLastWindow.lock() != w) /* window should change */) { // a bit hacky // if we only pressed one button, allow us to refocus. m_lCurrentlyHeldButtons.size() > 0 will stick the focus if (m_lCurrentlyHeldButtons.size() == 1) { @@ -655,8 +656,8 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { } // if clicked on a floating window make it top - if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsFloating) - g_pCompositor->changeWindowZOrder(g_pCompositor->m_pLastWindow, true); + if (g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock()->m_bIsFloating) + g_pCompositor->changeWindowZOrder(g_pCompositor->m_pLastWindow.lock(), true); break; case WL_POINTER_BUTTON_STATE_RELEASED: break; @@ -1615,7 +1616,7 @@ void CInputManager::releaseAllMouseButtons() { m_lCurrentlyHeldButtons.clear(); } -void CInputManager::setCursorIconOnBorder(CWindow* w) { +void CInputManager::setCursorIconOnBorder(PHLWINDOW w) { // do not override cursor icons set by mouse binds if (g_pKeybindManager->m_bIsMouseBindActive) { m_eBorderIconDirection = BORDERICON_NONE; @@ -1636,7 +1637,7 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) { if (w->hasPopupAt(mouseCoords)) direction = BORDERICON_NONE; - else if (!boxFullGrabInput.containsPoint(mouseCoords) || (!m_lCurrentlyHeldButtons.empty() && !currentlyDraggedWindow)) + else if (!boxFullGrabInput.containsPoint(mouseCoords) || (!m_lCurrentlyHeldButtons.empty() && currentlyDraggedWindow.expired())) direction = BORDERICON_NONE; else { diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 2795d410..e20bca2a 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -38,7 +38,7 @@ enum eBorderIconDirection { }; struct STouchData { - CWindow* touchFocusWindow = nullptr; + PHLWINDOWREF touchFocusWindow; SLayerSurface* touchFocusLS = nullptr; wlr_surface* touchFocusSurface = nullptr; Vector2D touchSurfaceOrigin; @@ -114,12 +114,12 @@ class CInputManager { STouchData m_sTouchData; // for dragging floating windows - CWindow* currentlyDraggedWindow = nullptr; - eMouseBindMode dragMode = MBIND_INVALID; - bool m_bWasDraggingWindow = false; + PHLWINDOWREF currentlyDraggedWindow; + eMouseBindMode dragMode = MBIND_INVALID; + bool m_bWasDraggingWindow = false; // for refocus to be forced - CWindow* m_pForcedFocus = nullptr; + PHLWINDOWREF m_pForcedFocus; SDrag m_sDrag; @@ -188,7 +188,7 @@ class CInputManager { bool m_bLastInputTouch = false; // for tracking mouse refocus - CWindow* m_pLastMouseFocus = nullptr; + PHLWINDOWREF m_pLastMouseFocus; wlr_surface* m_pLastMouseSurface = nullptr; // @@ -226,7 +226,7 @@ class CInputManager { // this will be set after a refocus() wlr_surface* m_pFoundSurfaceToFocus = nullptr; SLayerSurface* m_pFoundLSToFocus = nullptr; - CWindow* m_pFoundWindowToFocus = nullptr; + PHLWINDOWREF m_pFoundWindowToFocus; // for holding focus on buttons held bool m_bFocusHeldByButtons = false; @@ -238,7 +238,7 @@ class CInputManager { // idle inhibitors struct SIdleInhibitor { std::shared_ptr inhibitor; - CWindow* pWindow = nullptr; + PHLWINDOWREF pWindow; CHyprSignalListener windowDestroyListener; }; std::vector> m_vIdleInhibitors; @@ -249,7 +249,7 @@ class CInputManager { void endWorkspaceSwipe(); void setBorderCursorIcon(eBorderIconDirection); - void setCursorIconOnBorder(CWindow* w); + void setCursorIconOnBorder(PHLWINDOW w); // temporary. Obeys setUntilUnset. void setCursorImageOverride(const std::string& name); diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index 9252fca4..d60a6a6f 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -263,7 +263,7 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool motion) { const auto PTOOL = g_pInputManager->ensureTabletToolPresent(pTool); - if (const auto PWINDOW = g_pCompositor->m_pLastWindow; PWINDOW) { + if (const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); PWINDOW) { const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal(); if (PTOOL->pSurface != g_pInputManager->m_pLastMouseSurface) diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index 36bf79b7..302d9e1d 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -64,12 +64,13 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) { Vector2D local; - if (m_sTouchData.touchFocusWindow) { - if (m_sTouchData.touchFocusWindow->m_bIsX11) { - local = (g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusWindow->m_vRealPosition.goal()) * m_sTouchData.touchFocusWindow->m_fX11SurfaceScaledBy; - m_sTouchData.touchSurfaceOrigin = m_sTouchData.touchFocusWindow->m_vRealPosition.goal(); + if (!m_sTouchData.touchFocusWindow.expired()) { + if (m_sTouchData.touchFocusWindow.lock()->m_bIsX11) { + local = (g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusWindow.lock()->m_vRealPosition.goal()) * + m_sTouchData.touchFocusWindow.lock()->m_fX11SurfaceScaledBy; + m_sTouchData.touchSurfaceOrigin = m_sTouchData.touchFocusWindow.lock()->m_vRealPosition.goal(); } else { - g_pCompositor->vectorWindowToSurface(g_pInputManager->getMouseCoordsInternal(), m_sTouchData.touchFocusWindow, local); + g_pCompositor->vectorWindowToSurface(g_pInputManager->getMouseCoordsInternal(), m_sTouchData.touchFocusWindow.lock(), local); m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local; } } else if (m_sTouchData.touchFocusLS) { @@ -126,14 +127,14 @@ void CInputManager::onTouchMove(wlr_touch_motion_event* e) { updateWorkspaceSwipe(SWIPEDISTANCE * (1 - (VERTANIMS ? e->y : e->x))); return; } - if (m_sTouchData.touchFocusWindow && g_pCompositor->windowValidMapped(m_sTouchData.touchFocusWindow)) { - const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusWindow->m_iMonitorID); + if (validMapped(m_sTouchData.touchFocusWindow)) { + const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusWindow.lock()->m_iMonitorID); wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PMONITOR->vecPosition.x + e->x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e->y * PMONITOR->vecSize.y); auto local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchSurfaceOrigin; - if (m_sTouchData.touchFocusWindow->m_bIsX11) - local = local * m_sTouchData.touchFocusWindow->m_fX11SurfaceScaledBy; + if (m_sTouchData.touchFocusWindow.lock()->m_bIsX11) + local = local * m_sTouchData.touchFocusWindow.lock()->m_fX11SurfaceScaledBy; wlr_seat_touch_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id, local.x, local.y); // wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, local.x, local.y); -- cgit v1.2.3