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
This commit is contained in:
Vaxry 2024-04-27 12:43:12 +01:00 committed by GitHub
parent 25aec3ac8c
commit bca7804bb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
72 changed files with 1416 additions and 1346 deletions

View file

@ -362,8 +362,8 @@ void CCompositor::cleanup() {
// still in a normal working state.
g_pPluginSystem->unloadAllPlugins();
m_pLastFocus = nullptr;
m_pLastWindow = nullptr;
m_pLastFocus = nullptr;
m_pLastWindow.reset();
// end threads
g_pEventManager->m_tThread = std::thread();
@ -662,29 +662,15 @@ CMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
return getMonitorFromOutput(OUTPUT);
}
void CCompositor::removeWindowFromVectorSafe(CWindow* pWindow) {
if (windowExists(pWindow) && !pWindow->m_bFadingOut) {
void CCompositor::removeWindowFromVectorSafe(PHLWINDOW pWindow) {
if (!pWindow->m_bFadingOut) {
EMIT_HOOK_EVENT("destroyWindow", pWindow);
std::erase_if(m_vWindows, [&](std::unique_ptr<CWindow>& el) { return el.get() == pWindow; });
std::erase_if(m_vWindowsFadingOut, [&](CWindow* el) { return el == pWindow; });
std::erase_if(m_vWindows, [&](SP<CWindow>& el) { return el == pWindow; });
std::erase_if(m_vWindowsFadingOut, [&](PHLWINDOWREF el) { return el.lock() == pWindow; });
}
}
bool CCompositor::windowExists(CWindow* pWindow) {
for (auto& w : m_vWindows) {
if (w.get() == pWindow)
return true;
}
// FIXME: this is here only temporarily,
// remove this func altogether if no reports
// of this being hit.
RASSERT(!pWindow, "windowExists: attempted UAF");
return false;
}
bool CCompositor::monitorExists(CMonitor* pMonitor) {
for (auto& m : m_vRealMonitors) {
if (m.get() == pMonitor)
@ -694,7 +680,7 @@ bool CCompositor::monitorExists(CMonitor* pMonitor) {
return false;
}
CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t properties, CWindow* pIgnoreWindow) {
PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t properties, PHLWINDOW pIgnoreWindow) {
const auto PMONITOR = getMonitorFromVector(pos);
static auto PRESIZEONBORDER = CConfigValue<Hyprlang::INT>("general:resize_on_border");
static auto PBORDERSIZE = CConfigValue<Hyprlang::INT>("general:border_size");
@ -707,21 +693,20 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert
for (auto& w : m_vWindows | std::views::reverse) {
const auto BB = w->getWindowBoxUnified(properties);
CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA};
if (w->m_bIsFloating && w->m_bIsMapped && !w->isHidden() && !w->m_bX11ShouldntFocus && w->m_bPinned && !w->m_sAdditionalConfigData.noFocus &&
w.get() != pIgnoreWindow) {
if (w->m_bIsFloating && w->m_bIsMapped && !w->isHidden() && !w->m_bX11ShouldntFocus && w->m_bPinned && !w->m_sAdditionalConfigData.noFocus && w != pIgnoreWindow) {
if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}))
return w.get();
return w;
if (!w->m_bIsX11) {
if (w->hasPopupAt(pos))
return w.get();
return w;
}
}
}
}
auto windowForWorkspace = [&](bool special) -> CWindow* {
auto floating = [&](bool aboveFullscreen) -> CWindow* {
auto windowForWorkspace = [&](bool special) -> PHLWINDOW {
auto floating = [&](bool aboveFullscreen) -> PHLWINDOW {
for (auto& w : m_vWindows | std::views::reverse) {
if (special && !w->onSpecialWorkspace()) // because special floating may creep up into regular
@ -738,7 +723,7 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert
CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA};
if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_pWorkspace) && !w->isHidden() && !w->m_bPinned && !w->m_sAdditionalConfigData.noFocus &&
w.get() != pIgnoreWindow && (!aboveFullscreen || w->m_bCreatedOverFullscreen)) {
w != pIgnoreWindow && (!aboveFullscreen || w->m_bCreatedOverFullscreen)) {
// OR windows should add focus to parent
if (w->m_bX11ShouldntFocus && w->m_iX11Type != 2)
continue;
@ -747,16 +732,16 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert
if (w->m_bIsX11 && w->m_iX11Type == 2 && !wlr_xwayland_or_surface_wants_focus(w->m_uSurface.xwayland)) {
// Override Redirect
return g_pCompositor->m_pLastWindow; // we kinda trick everything here.
// TODO: this is wrong, we should focus the parent, but idk how to get it considering it's nullptr in most cases.
return g_pCompositor->m_pLastWindow.lock(); // we kinda trick everything here.
// TODO: this is wrong, we should focus the parent, but idk how to get it considering it's nullptr in most cases.
}
return w.get();
return w;
}
if (!w->m_bIsX11) {
if (w->hasPopupAt(pos))
return w.get();
return w;
}
}
}
@ -790,9 +775,9 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert
continue;
if (!w->m_bIsX11 && !w->m_bIsFloating && w->m_bIsMapped && w->workspaceID() == WORKSPACEID && !w->isHidden() && !w->m_bX11ShouldntFocus &&
!w->m_sAdditionalConfigData.noFocus && w.get() != pIgnoreWindow) {
!w->m_sAdditionalConfigData.noFocus && w != pIgnoreWindow) {
if (w->hasPopupAt(pos))
return w.get();
return w;
}
}
@ -802,8 +787,8 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert
CBox box = (properties & USE_PROP_TILED) ? w->getWindowBoxUnified(properties) : CBox{w->m_vPosition, w->m_vSize};
if (!w->m_bIsFloating && w->m_bIsMapped && box.containsPoint(pos) && w->workspaceID() == WORKSPACEID && !w->isHidden() && !w->m_bX11ShouldntFocus &&
!w->m_sAdditionalConfigData.noFocus && w.get() != pIgnoreWindow)
return w.get();
!w->m_sAdditionalConfigData.noFocus && w != pIgnoreWindow)
return w;
}
return nullptr;
@ -823,9 +808,9 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert
return windowForWorkspace(false);
}
wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pWindow, Vector2D& sl) {
wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, PHLWINDOW pWindow, Vector2D& sl) {
if (!windowValidMapped(pWindow))
if (!validMapped(pWindow))
return nullptr;
RASSERT(!pWindow->m_bIsX11, "Cannot call vectorWindowToSurface on an X11 window!");
@ -857,8 +842,8 @@ wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pW
return PSURFACE->surface;
}
Vector2D CCompositor::vectorToSurfaceLocal(const Vector2D& vec, CWindow* pWindow, wlr_surface* pSurface) {
if (!windowValidMapped(pWindow))
Vector2D CCompositor::vectorToSurfaceLocal(const Vector2D& vec, PHLWINDOW pWindow, wlr_surface* pSurface) {
if (!validMapped(pWindow))
return {};
if (pWindow->m_bIsX11)
@ -909,7 +894,7 @@ CMonitor* CCompositor::getRealMonitorFromOutput(wlr_output* out) {
return nullptr;
}
void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
void CCompositor::focusWindow(PHLWINDOW pWindow, wlr_surface* pSurface) {
static auto PFOLLOWMOUSE = CConfigValue<Hyprlang::INT>("input:follow_mouse");
static auto PSPECIALFALLTHROUGH = CConfigValue<Hyprlang::INT>("input:special_fallthrough");
@ -929,15 +914,15 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
g_pLayoutManager->getCurrentLayout()->bringWindowToTop(pWindow);
if (!pWindow || !windowValidMapped(pWindow)) {
if (!pWindow || !validMapped(pWindow)) {
if (!m_pLastWindow && !pWindow)
if (m_pLastWindow.expired() && !pWindow)
return;
const auto PLASTWINDOW = m_pLastWindow;
m_pLastWindow = nullptr;
const auto PLASTWINDOW = m_pLastWindow.lock();
m_pLastWindow.reset();
if (windowValidMapped(PLASTWINDOW)) {
if (PLASTWINDOW && PLASTWINDOW->m_bIsMapped) {
updateWindowAnimatedDecorationValues(PLASTWINDOW);
g_pXWaylandManager->activateWindow(PLASTWINDOW, false);
@ -948,7 +933,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", ","});
g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", ","});
EMIT_HOOK_EVENT("activeWindow", (CWindow*)nullptr);
EMIT_HOOK_EVENT("activeWindow", (PHLWINDOW) nullptr);
g_pLayoutManager->getCurrentLayout()->onWindowFocusChange(nullptr);
@ -963,7 +948,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
return;
}
if (m_pLastWindow == pWindow && m_sSeat.seat->keyboard_state.focused_surface == pSurface)
if (m_pLastWindow.lock() == pWindow && m_sSeat.seat->keyboard_state.focused_surface == pSurface)
return;
if (pWindow->m_bPinned)
@ -984,7 +969,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
return;
}
const auto PLASTWINDOW = m_pLastWindow;
const auto PLASTWINDOW = m_pLastWindow.lock();
m_pLastWindow = pWindow;
/* If special fallthrough is enabled, this behavior will be disabled, as I have no better idea of nicely tracking which
@ -993,7 +978,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
PMONITOR->setSpecialWorkspace(nullptr);
// we need to make the PLASTWINDOW not equal to m_pLastWindow so that RENDERDATA is correct for an unfocused window
if (windowValidMapped(PLASTWINDOW)) {
if (PLASTWINDOW && PLASTWINDOW->m_bIsMapped) {
PLASTWINDOW->updateDynamicRules();
updateWindowAnimatedDecorationValues(PLASTWINDOW);
@ -1019,7 +1004,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
// Send an event
g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", g_pXWaylandManager->getAppIDClass(pWindow) + "," + pWindow->m_szTitle});
g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", std::format("{:x}", (uintptr_t)pWindow)});
g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", std::format("{:x}", (uintptr_t)pWindow.get())});
EMIT_HOOK_EVENT("activeWindow", pWindow);
@ -1028,7 +1013,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
g_pInputManager->recheckIdleInhibitorStatus();
// move to front of the window history
const auto HISTORYPIVOT = std::find_if(m_vWindowFocusHistory.begin(), m_vWindowFocusHistory.end(), [&](const auto& other) { return other == pWindow; });
const auto HISTORYPIVOT = std::find_if(m_vWindowFocusHistory.begin(), m_vWindowFocusHistory.end(), [&](const auto& other) { return other.lock() == pWindow; });
if (HISTORYPIVOT == m_vWindowFocusHistory.end()) {
Debug::log(ERR, "BUG THIS: {} has no pivot in history", pWindow);
} else {
@ -1039,7 +1024,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
g_pInputManager->sendMotionEventsToFocused();
}
void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) {
void CCompositor::focusSurface(wlr_surface* pSurface, PHLWINDOW pWindowOwner) {
if (m_sSeat.seat->keyboard_state.focused_surface == pSurface || (pWindowOwner && m_sSeat.seat->keyboard_state.focused_surface == pWindowOwner->m_pWLSurface.wlr()))
return; // Don't focus when already focused on this.
@ -1094,22 +1079,6 @@ void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) {
SURF->constraint()->activate();
}
bool CCompositor::windowValidMapped(CWindow* pWindow) {
if (!pWindow)
return false;
if (!windowExists(pWindow))
return false;
if (!pWindow->m_bIsMapped)
return false;
if (pWindow->isHidden())
return false;
return true;
}
wlr_surface* CCompositor::vectorToLayerPopupSurface(const Vector2D& pos, CMonitor* monitor, Vector2D* sCoords, SLayerSurface** ppLayerSurfaceFound) {
for (auto& lsl : monitor->m_aLayerSurfaceLayers | std::views::reverse) {
for (auto& ls : lsl | std::views::reverse) {
@ -1151,32 +1120,32 @@ wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::vector<
return nullptr;
}
CWindow* CCompositor::getWindowFromSurface(wlr_surface* pSurface) {
PHLWINDOW CCompositor::getWindowFromSurface(wlr_surface* pSurface) {
for (auto& w : m_vWindows) {
if (!w->m_bIsMapped || w->m_bFadingOut)
continue;
if (w->m_pWLSurface.wlr() == pSurface)
return w.get();
return w;
}
return nullptr;
}
CWindow* CCompositor::getWindowFromHandle(uint32_t handle) {
PHLWINDOW CCompositor::getWindowFromHandle(uint32_t handle) {
for (auto& w : m_vWindows) {
if ((uint32_t)(((uint64_t)w.get()) & 0xFFFFFFFF) == handle) {
return w.get();
return w;
}
}
return nullptr;
}
CWindow* CCompositor::getFullscreenWindowOnWorkspace(const int& ID) {
PHLWINDOW CCompositor::getFullscreenWindowOnWorkspace(const int& ID) {
for (auto& w : m_vWindows) {
if (w->workspaceID() == ID && w->m_bIsFullscreen)
return w.get();
return w;
}
return nullptr;
@ -1241,10 +1210,10 @@ int CCompositor::getGroupsOnWorkspace(const int& id, std::optional<bool> onlyTil
return no;
}
CWindow* CCompositor::getUrgentWindow() {
PHLWINDOW CCompositor::getUrgentWindow() {
for (auto& w : m_vWindows) {
if (w->m_bIsMapped && w->m_bIsUrgent)
return w.get();
return w;
}
return nullptr;
@ -1259,16 +1228,16 @@ bool CCompositor::hasUrgentWindowOnWorkspace(const int& id) {
return false;
}
CWindow* CCompositor::getFirstWindowOnWorkspace(const int& id) {
PHLWINDOW CCompositor::getFirstWindowOnWorkspace(const int& id) {
for (auto& w : m_vWindows) {
if (w->workspaceID() == id && w->m_bIsMapped && !w->isHidden())
return w.get();
return w;
}
return nullptr;
}
CWindow* CCompositor::getTopLeftWindowOnWorkspace(const int& id) {
PHLWINDOW CCompositor::getTopLeftWindowOnWorkspace(const int& id) {
const auto PWORKSPACE = getWorkspaceByID(id);
if (!PWORKSPACE)
@ -1283,7 +1252,7 @@ CWindow* CCompositor::getTopLeftWindowOnWorkspace(const int& id) {
const auto WINDOWIDEALBB = w->getWindowIdealBoundingBoxIgnoreReserved();
if (WINDOWIDEALBB.x <= PMONITOR->vecPosition.x + 1 && WINDOWIDEALBB.y <= PMONITOR->vecPosition.y + 1)
return w.get();
return w;
}
return nullptr;
}
@ -1309,8 +1278,8 @@ bool CCompositor::doesSeatAcceptInput(wlr_surface* surface) {
return true;
}
bool CCompositor::isWindowActive(CWindow* pWindow) {
if (!m_pLastWindow && !m_pLastFocus)
bool CCompositor::isWindowActive(PHLWINDOW pWindow) {
if (m_pLastWindow.expired() && !m_pLastFocus)
return false;
if (!pWindow->m_bIsMapped)
@ -1318,24 +1287,24 @@ bool CCompositor::isWindowActive(CWindow* pWindow) {
const auto PSURFACE = pWindow->m_pWLSurface.wlr();
return PSURFACE == m_pLastFocus || pWindow == m_pLastWindow;
return PSURFACE == m_pLastFocus || pWindow == m_pLastWindow.lock();
}
void CCompositor::changeWindowZOrder(CWindow* pWindow, bool top) {
if (!windowValidMapped(pWindow))
void CCompositor::changeWindowZOrder(PHLWINDOW pWindow, bool top) {
if (!validMapped(pWindow))
return;
auto moveToZ = [&](CWindow* pw, bool top) -> void {
auto moveToZ = [&](PHLWINDOW pw, bool top) -> void {
if (top) {
for (auto it = m_vWindows.begin(); it != m_vWindows.end(); ++it) {
if (it->get() == pw) {
if (*it == pw) {
std::rotate(it, it + 1, m_vWindows.end());
break;
}
}
} else {
for (auto it = m_vWindows.rbegin(); it != m_vWindows.rend(); ++it) {
if (it->get() == pw) {
if (*it == pw) {
std::rotate(it, it + 1, m_vWindows.rend());
break;
}
@ -1355,9 +1324,9 @@ void CCompositor::changeWindowZOrder(CWindow* pWindow, bool top) {
} else {
// move X11 window stack
std::deque<CWindow*> toMove;
std::deque<PHLWINDOW> toMove;
auto x11Stack = [&](CWindow* pw, bool top, auto&& x11Stack) -> void {
auto x11Stack = [&](PHLWINDOW pw, bool top, auto&& x11Stack) -> void {
if (top)
toMove.emplace_back(pw);
else
@ -1365,7 +1334,7 @@ void CCompositor::changeWindowZOrder(CWindow* pWindow, bool top) {
for (auto& w : m_vWindows) {
if (w->m_bIsMapped && !w->isHidden() && w->m_bIsX11 && w->X11TransientFor() == pw) {
x11Stack(w.get(), top, x11Stack);
x11Stack(w, top, x11Stack);
}
}
};
@ -1379,7 +1348,9 @@ void CCompositor::changeWindowZOrder(CWindow* pWindow, bool top) {
}
void CCompositor::cleanupFadingOut(const int& monid) {
for (auto& w : m_vWindowsFadingOut) {
for (auto& ww : m_vWindowsFadingOut) {
const auto w = ww.lock();
if (w->m_iMonitorID != (long unsigned int)monid)
continue;
@ -1462,8 +1433,8 @@ void CCompositor::addToFadingOutSafe(SLayerSurface* pLS) {
m_vSurfacesFadingOut.emplace_back(pLS);
}
void CCompositor::addToFadingOutSafe(CWindow* pWindow) {
const auto FOUND = std::find_if(m_vWindowsFadingOut.begin(), m_vWindowsFadingOut.end(), [&](CWindow* other) { return other == pWindow; });
void CCompositor::addToFadingOutSafe(PHLWINDOW pWindow) {
const auto FOUND = std::find_if(m_vWindowsFadingOut.begin(), m_vWindowsFadingOut.end(), [&](PHLWINDOWREF& other) { return other.lock() == pWindow; });
if (FOUND != m_vWindowsFadingOut.end())
return; // if it's already added, don't add it.
@ -1471,7 +1442,7 @@ void CCompositor::addToFadingOutSafe(CWindow* pWindow) {
m_vWindowsFadingOut.emplace_back(pWindow);
}
CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {
PHLWINDOW CCompositor::getWindowInDirection(PHLWINDOW pWindow, char dir) {
if (!isDirection(dir))
return nullptr;
@ -1492,13 +1463,13 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {
const auto PWORKSPACE = pWindow->m_pWorkspace;
auto leaderValue = -1;
CWindow* leaderWindow = nullptr;
PHLWINDOW leaderWindow = nullptr;
if (!pWindow->m_bIsFloating) {
// for tiled windows, we calc edges
for (auto& w : m_vWindows) {
if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && w->m_bIsFloating) || !isWorkspaceVisible(w->m_pWorkspace))
if (w == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && w->m_bIsFloating) || !isWorkspaceVisible(w->m_pWorkspace))
continue;
if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_pWorkspace != w->m_pWorkspace)
@ -1545,7 +1516,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {
// get idx
int windowIDX = -1;
for (size_t i = 0; i < g_pCompositor->m_vWindowFocusHistory.size(); ++i) {
if (g_pCompositor->m_vWindowFocusHistory[i] == w.get()) {
if (g_pCompositor->m_vWindowFocusHistory[i].lock() == w) {
windowIDX = i;
break;
}
@ -1555,13 +1526,13 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {
if (windowIDX > leaderValue) {
leaderValue = windowIDX;
leaderWindow = w.get();
leaderWindow = w;
}
}
} else /* length */ {
if (intersectLength > leaderValue) {
leaderValue = intersectLength;
leaderWindow = w.get();
leaderWindow = w;
}
}
}
@ -1587,7 +1558,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {
constexpr float THRESHOLD = 0.3 * M_PI;
for (auto& w : m_vWindows) {
if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && !w->m_bIsFloating) || !isWorkspaceVisible(w->m_pWorkspace))
if (w == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && !w->m_bIsFloating) || !isWorkspaceVisible(w->m_pWorkspace))
continue;
if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_pWorkspace != w->m_pWorkspace)
@ -1605,7 +1576,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {
if ((bestAngleAbs < THRESHOLD && DIST < leaderValue && ANGLE < THRESHOLD) || (ANGLE < bestAngleAbs && bestAngleAbs > THRESHOLD) || leaderValue == -1) {
leaderValue = DIST;
bestAngleAbs = ANGLE;
leaderWindow = w.get();
leaderWindow = w;
}
}
@ -1619,13 +1590,13 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {
return nullptr;
}
CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow, bool focusableOnly, std::optional<bool> floating) {
PHLWINDOW CCompositor::getNextWindowOnWorkspace(PHLWINDOW pWindow, bool focusableOnly, std::optional<bool> floating) {
bool gotToWindow = false;
for (auto& w : m_vWindows) {
if (w.get() != pWindow && !gotToWindow)
if (w != pWindow && !gotToWindow)
continue;
if (w.get() == pWindow) {
if (w == pWindow) {
gotToWindow = true;
continue;
}
@ -1634,27 +1605,27 @@ CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow, bool focusableO
continue;
if (w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus))
return w.get();
return w;
}
for (auto& w : m_vWindows) {
if (floating.has_value() && w->m_bIsFloating != floating.value())
continue;
if (w.get() != pWindow && w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus))
return w.get();
if (w != pWindow && w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus))
return w;
}
return nullptr;
}
CWindow* CCompositor::getPrevWindowOnWorkspace(CWindow* pWindow, bool focusableOnly, std::optional<bool> floating) {
PHLWINDOW CCompositor::getPrevWindowOnWorkspace(PHLWINDOW pWindow, bool focusableOnly, std::optional<bool> floating) {
bool gotToWindow = false;
for (auto& w : m_vWindows | std::views::reverse) {
if (w.get() != pWindow && !gotToWindow)
if (w != pWindow && !gotToWindow)
continue;
if (w.get() == pWindow) {
if (w == pWindow) {
gotToWindow = true;
continue;
}
@ -1663,15 +1634,15 @@ CWindow* CCompositor::getPrevWindowOnWorkspace(CWindow* pWindow, bool focusableO
continue;
if (w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus))
return w.get();
return w;
}
for (auto& w : m_vWindows | std::views::reverse) {
if (floating.has_value() && w->m_bIsFloating != floating.value())
continue;
if (w.get() != pWindow && w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus))
return w.get();
if (w != pWindow && w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus))
return w;
}
return nullptr;
@ -1805,7 +1776,7 @@ void CCompositor::updateAllWindowsAnimatedDecorationValues() {
if (!w->m_bIsMapped)
continue;
updateWindowAnimatedDecorationValues(w.get());
updateWindowAnimatedDecorationValues(w);
}
}
@ -1818,7 +1789,7 @@ void CCompositor::updateWorkspaceWindows(const int64_t& id) {
}
}
void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) {
// optimization
static auto PACTIVECOL = CConfigValue<Hyprlang::CUSTOMTYPE>("general:col.active_border");
static auto PINACTIVECOL = CConfigValue<Hyprlang::CUSTOMTYPE>("general:col.inactive_border");
@ -1860,15 +1831,15 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
if (RENDERDATA.isBorderGradient)
setBorderColor(*RENDERDATA.borderGradient);
else {
const bool GROUPLOCKED = pWindow->m_sGroupData.pNextWindow ? pWindow->getGroupHead()->m_sGroupData.locked : false;
if (pWindow == m_pLastWindow) {
const bool GROUPLOCKED = pWindow->m_sGroupData.pNextWindow.lock() ? pWindow->getGroupHead()->m_sGroupData.locked : false;
if (pWindow == m_pLastWindow.lock()) {
const auto* const ACTIVECOLOR =
!pWindow->m_sGroupData.pNextWindow ? (!pWindow->m_sGroupData.deny ? ACTIVECOL : NOGROUPACTIVECOL) : (GROUPLOCKED ? GROUPACTIVELOCKEDCOL : GROUPACTIVECOL);
!pWindow->m_sGroupData.pNextWindow.lock() ? (!pWindow->m_sGroupData.deny ? ACTIVECOL : NOGROUPACTIVECOL) : (GROUPLOCKED ? GROUPACTIVELOCKEDCOL : GROUPACTIVECOL);
setBorderColor(pWindow->m_sSpecialRenderData.activeBorderColor.toUnderlying().m_vColors.empty() ? *ACTIVECOLOR :
pWindow->m_sSpecialRenderData.activeBorderColor.toUnderlying());
} else {
const auto* const INACTIVECOLOR =
!pWindow->m_sGroupData.pNextWindow ? (!pWindow->m_sGroupData.deny ? INACTIVECOL : NOGROUPINACTIVECOL) : (GROUPLOCKED ? GROUPINACTIVELOCKEDCOL : GROUPINACTIVECOL);
const auto* const INACTIVECOLOR = !pWindow->m_sGroupData.pNextWindow.lock() ? (!pWindow->m_sGroupData.deny ? INACTIVECOL : NOGROUPINACTIVECOL) :
(GROUPLOCKED ? GROUPINACTIVELOCKEDCOL : GROUPINACTIVECOL);
setBorderColor(pWindow->m_sSpecialRenderData.inactiveBorderColor.toUnderlying().m_vColors.empty() ? *INACTIVECOLOR :
pWindow->m_sSpecialRenderData.inactiveBorderColor.toUnderlying());
}
@ -1886,7 +1857,7 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
pWindow->m_sSpecialRenderData.alphaFullscreen.toUnderlying() * *PFULLSCREENALPHA) :
*PFULLSCREENALPHA;
} else {
if (pWindow == m_pLastWindow)
if (pWindow == m_pLastWindow.lock())
pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaOverride.toUnderlying() ? pWindow->m_sSpecialRenderData.alpha.toUnderlying() :
pWindow->m_sSpecialRenderData.alpha.toUnderlying() * *PACTIVEALPHA;
else
@ -1897,7 +1868,7 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
}
// dim
if (pWindow == m_pLastWindow || pWindow->m_sAdditionalConfigData.forceNoDim || !*PDIMENABLED) {
if (pWindow == m_pLastWindow.lock() || pWindow->m_sAdditionalConfigData.forceNoDim || !*PDIMENABLED) {
pWindow->m_fDimPercent = 0;
} else {
pWindow->m_fDimPercent = *PDIMSTRENGTH;
@ -1905,7 +1876,7 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
// shadow
if (pWindow->m_iX11Type != 2 && !pWindow->m_bX11DoesntWantBorders) {
if (pWindow == m_pLastWindow) {
if (pWindow == m_pLastWindow.lock()) {
pWindow->m_cRealShadowColor = CColor(*PSHADOWCOL);
} else {
pWindow->m_cRealShadowColor = CColor(*PSHADOWCOLINACTIVE != INT_MAX ? *PSHADOWCOLINACTIVE : *PSHADOWCOL);
@ -2252,8 +2223,8 @@ void CCompositor::updateFullscreenFadeOnWorkspace(PHLWORKSPACE pWorkspace) {
}
}
void CCompositor::setWindowFullscreen(CWindow* pWindow, bool on, eFullscreenMode mode) {
if (!windowValidMapped(pWindow) || g_pCompositor->m_bUnsafeState)
void CCompositor::setWindowFullscreen(PHLWINDOW pWindow, bool on, eFullscreenMode mode) {
if (!validMapped(pWindow) || g_pCompositor->m_bUnsafeState)
return;
if (pWindow->m_bPinned) {
@ -2302,7 +2273,7 @@ void CCompositor::setWindowFullscreen(CWindow* pWindow, bool on, eFullscreenMode
g_pConfigManager->ensureVRR(PMONITOR);
}
CWindow* CCompositor::getX11Parent(CWindow* pWindow) {
PHLWINDOW CCompositor::getX11Parent(PHLWINDOW pWindow) {
if (!pWindow->m_bIsX11)
return nullptr;
@ -2311,7 +2282,7 @@ CWindow* CCompositor::getX11Parent(CWindow* pWindow) {
continue;
if (w->m_uSurface.xwayland == pWindow->m_uSurface.xwayland->parent)
return w.get();
return w;
}
return nullptr;
@ -2351,9 +2322,9 @@ void CCompositor::scheduleFrameForMonitor(CMonitor* pMonitor) {
wlr_output_schedule_frame(pMonitor->output);
}
CWindow* CCompositor::getWindowByRegex(const std::string& regexp) {
PHLWINDOW CCompositor::getWindowByRegex(const std::string& regexp) {
if (regexp.starts_with("active"))
return m_pLastWindow;
return m_pLastWindow.lock();
eFocusWindowMode mode = MODE_CLASS_REGEX;
@ -2378,28 +2349,28 @@ CWindow* CCompositor::getWindowByRegex(const std::string& regexp) {
matchCheck = regexp.substr(4);
} else if (regexp.starts_with("floating") || regexp.starts_with("tiled")) {
// first floating on the current ws
if (!m_pLastWindow)
if (!valid(m_pLastWindow))
return nullptr;
const bool FLOAT = regexp.starts_with("floating");
for (auto& w : m_vWindows) {
if (!w->m_bIsMapped || w->m_bIsFloating != FLOAT || w->m_pWorkspace != m_pLastWindow->m_pWorkspace || w->isHidden())
if (!w->m_bIsMapped || w->m_bIsFloating != FLOAT || w->m_pWorkspace != m_pLastWindow.lock()->m_pWorkspace || w->isHidden())
continue;
return w.get();
return w;
}
return nullptr;
}
for (auto& w : g_pCompositor->m_vWindows) {
if (!w->m_bIsMapped || (w->isHidden() && !g_pLayoutManager->getCurrentLayout()->isWindowReachable(w.get())))
if (!w->m_bIsMapped || (w->isHidden() && !g_pLayoutManager->getCurrentLayout()->isWindowReachable(w)))
continue;
switch (mode) {
case MODE_CLASS_REGEX: {
const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get());
const auto windowClass = g_pXWaylandManager->getAppIDClass(w);
if (!std::regex_search(windowClass, regexCheck))
continue;
break;
@ -2411,7 +2382,7 @@ CWindow* CCompositor::getWindowByRegex(const std::string& regexp) {
break;
}
case MODE_TITLE_REGEX: {
const auto windowTitle = g_pXWaylandManager->getTitle(w.get());
const auto windowTitle = g_pXWaylandManager->getTitle(w);
if (!std::regex_search(windowTitle, regexCheck))
continue;
break;
@ -2437,7 +2408,7 @@ CWindow* CCompositor::getWindowByRegex(const std::string& regexp) {
default: break;
}
return w.get();
return w;
}
return nullptr;
@ -2476,8 +2447,8 @@ SLayerSurface* CCompositor::getLayerSurfaceFromWlr(wlr_layer_surface_v1* pLS) {
return nullptr;
}
void CCompositor::closeWindow(CWindow* pWindow) {
if (pWindow && windowValidMapped(pWindow)) {
void CCompositor::closeWindow(PHLWINDOW pWindow) {
if (pWindow && validMapped(pWindow)) {
g_pXWaylandManager->sendCloseWindow(pWindow);
}
}
@ -2565,7 +2536,7 @@ Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, con
void CCompositor::forceReportSizesToWindowsOnWorkspace(const int& wid) {
for (auto& w : m_vWindows) {
if (w->workspaceID() == wid && w->m_bIsMapped && !w->isHidden()) {
g_pXWaylandManager->setWindowSize(w.get(), w->m_vRealSize.value(), true);
g_pXWaylandManager->setWindowSize(w, w->m_vRealSize.value(), true);
}
}
}
@ -2638,7 +2609,7 @@ void CCompositor::performUserChecks() {
; // intentional
}
void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, PHLWORKSPACE pWorkspace) {
void CCompositor::moveWindowToWorkspaceSafe(PHLWINDOW pWindow, PHLWORKSPACE pWorkspace) {
if (!pWindow || !pWorkspace)
return;
@ -2672,12 +2643,12 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, PHLWORKSPACE pWork
pWindow->updateDynamicRules();
pWindow->uncacheWindowDecos();
if (pWindow->m_sGroupData.pNextWindow) {
CWindow* next = pWindow->m_sGroupData.pNextWindow;
if (!pWindow->m_sGroupData.pNextWindow.expired()) {
PHLWINDOW next = pWindow->m_sGroupData.pNextWindow.lock();
while (next != pWindow) {
next->moveToWorkspace(pWorkspace);
next->updateToplevel();
next = next->m_sGroupData.pNextWindow;
next = next->m_sGroupData.pNextWindow.lock();
}
}
@ -2688,7 +2659,7 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, PHLWORKSPACE pWork
g_pCompositor->updateWorkspaceWindows(pWindow->workspaceID());
}
CWindow* CCompositor::getForceFocus() {
PHLWINDOW CCompositor::getForceFocus() {
for (auto& w : m_vWindows) {
if (!w->m_bIsMapped || w->isHidden() || !isWorkspaceVisible(w->m_pWorkspace))
continue;
@ -2696,7 +2667,7 @@ CWindow* CCompositor::getForceFocus() {
if (!w->m_bStayFocused)
continue;
return w.get();
return w;
}
return nullptr;
@ -2875,3 +2846,14 @@ void CCompositor::updateSuspendedStates() {
w->setSuspended(w->isHidden() || !isWorkspaceVisible(w->m_pWorkspace));
}
}
PHLWINDOW CCompositor::windowForCPointer(CWindow* pWindow) {
for (auto& w : m_vWindows) {
if (w.get() != pWindow)
continue;
return w;
}
return {};
}