diff --git a/src/Compositor.cpp b/src/Compositor.cpp index afffe7a6..c3758513 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -172,8 +172,8 @@ void CCompositor::cleanupExit() { m_pLastFocus = nullptr; m_pLastWindow = nullptr; - m_lWorkspaces.clear(); - m_lWindows.clear(); + m_vWorkspaces.clear(); + m_vWindows.clear(); if (g_pXWaylandManager->m_sWLRXWayland) { wlr_xwayland_destroy(g_pXWaylandManager->m_sWLRXWayland); @@ -269,9 +269,9 @@ void CCompositor::startCompositor() { } SMonitor* CCompositor::getMonitorFromID(const int& id) { - for (auto& m : m_lMonitors) { - if (m.ID == (uint64_t)id) { - return &m; + for (auto& m : m_vMonitors) { + if (m->ID == (uint64_t)id) { + return m.get(); } } @@ -279,9 +279,9 @@ SMonitor* CCompositor::getMonitorFromID(const int& id) { } SMonitor* CCompositor::getMonitorFromName(const std::string& name) { - for (auto& m : m_lMonitors) { - if (m.szName == name) { - return &m; + for (auto& m : m_vMonitors) { + if (m->szName == name) { + return m.get(); } } @@ -301,18 +301,18 @@ SMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) { float bestDistance = 0.f; SMonitor* pBestMon = nullptr; - for (auto& m : m_lMonitors) { - float dist = vecToRectDistanceSquared(point, m.vecPosition, m.vecPosition + m.vecSize); + for (auto& m : m_vMonitors) { + float dist = vecToRectDistanceSquared(point, m->vecPosition, m->vecPosition + m->vecSize); if (dist < bestDistance || !pBestMon) { bestDistance = dist; - pBestMon = &m; + pBestMon = m.get(); } } if (!pBestMon) { // ????? Debug::log(WARN, "getMonitorFromVector no close mon???"); - return &m_lMonitors.front(); + return m_vMonitors.front().get(); } return pBestMon; @@ -322,13 +322,35 @@ SMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) { } void CCompositor::removeWindowFromVectorSafe(CWindow* pWindow) { - if (windowExists(pWindow) && !pWindow->m_bFadingOut) - m_lWindows.remove(*pWindow); + if (windowExists(pWindow) && !pWindow->m_bFadingOut){ + if (pWindow->m_bIsX11 && pWindow->m_iX11Type == 2) { + m_dUnmanagedX11Windows.erase(std::remove_if(m_dUnmanagedX11Windows.begin(), m_dUnmanagedX11Windows.end(), [&](std::unique_ptr& el) { return el.get() == pWindow; })); + } + + // if X11, also check its children + // and delete any needed + if (pWindow->m_bIsX11) { + for (auto& w : m_vWindows) { + if (!w->m_bIsX11) + continue; + + if (w->m_pX11Parent == pWindow) + m_vWindows.erase(std::remove_if(m_vWindows.begin(), m_vWindows.end(), [&](std::unique_ptr& el) { return el.get() == w.get(); })); + } + + for (auto& w : m_dUnmanagedX11Windows) { + if (w->m_pX11Parent == pWindow) + m_dUnmanagedX11Windows.erase(std::remove_if(m_dUnmanagedX11Windows.begin(), m_dUnmanagedX11Windows.end(), [&](std::unique_ptr& el) { return el.get() == w.get(); })); + } + } + + m_vWindows.erase(std::remove_if(m_vWindows.begin(), m_vWindows.end(), [&](std::unique_ptr& el) { return el.get() == pWindow; })); + } } bool CCompositor::windowExists(CWindow* pWindow) { - for (auto& w : m_lWindows) { // TODO: get rid of unmanaged X11? - if (&w == pWindow) + for (auto& w : m_vWindows) { + if (w.get() == pWindow) return true; } @@ -339,24 +361,24 @@ CWindow* CCompositor::vectorToWindow(const Vector2D& pos) { const auto PMONITOR = getMonitorFromVector(pos); if (PMONITOR->specialWorkspaceOpen) { - for (auto& w : m_lWindows) { - wlr_box box = {w.m_vRealPosition.vec().x, w.m_vRealPosition.vec().y, w.m_vRealSize.vec().x, w.m_vRealSize.vec().y}; - if (w.m_iWorkspaceID == SPECIAL_WORKSPACE_ID && wlr_box_contains_point(&box, pos.x, pos.y) && w.m_bIsMapped && !w.m_bIsFloating && !w.m_bHidden) - return &w; + for (auto& w : m_vWindows) { + wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; + if (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && !w->m_bIsFloating && !w->m_bHidden) + return w.get(); } } - // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. - for (auto w = m_lWindows.rbegin(); w != m_lWindows.rend(); w++) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bHidden) - return &(*w); + // first loop over floating cuz they're above, m_vWindows should be sorted bottom->top, for tiled it doesn't matter. + for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) { + wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y}; + if (wlr_box_contains_point(&box, pos.x, pos.y) && (*w)->m_bIsMapped && (*w)->m_bIsFloating && isWorkspaceVisible((*w)->m_iWorkspaceID) && !(*w)->m_bHidden) + return w->get(); } - for (auto& w : m_lWindows) { - wlr_box box = {w.m_vRealPosition.vec().x, w.m_vRealPosition.vec().y, w.m_vRealSize.vec().x, w.m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, pos.x, pos.y) && w.m_bIsMapped && !w.m_bIsFloating && PMONITOR->activeWorkspace == w.m_iWorkspaceID && !w.m_bHidden) - return &w; + for (auto& w : m_vWindows) { + wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; + if (wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && !w->m_bIsFloating && PMONITOR->activeWorkspace == w->m_iWorkspaceID && !w->m_bHidden) + return w.get(); } return nullptr; @@ -366,17 +388,17 @@ CWindow* CCompositor::vectorToWindowTiled(const Vector2D& pos) { const auto PMONITOR = getMonitorFromVector(pos); if (PMONITOR->specialWorkspaceOpen) { - for (auto& w : m_lWindows) { - wlr_box box = {w.m_vPosition.x, w.m_vPosition.y, w.m_vSize.x, w.m_vSize.y}; - if (w.m_iWorkspaceID == SPECIAL_WORKSPACE_ID && wlr_box_contains_point(&box, pos.x, pos.y) && !w.m_bIsFloating && !w.m_bHidden) - return &w; + for (auto& w : m_vWindows) { + wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && wlr_box_contains_point(&box, pos.x, pos.y) && !w->m_bIsFloating && !w->m_bHidden) + return w.get(); } } - for (auto& w : m_lWindows) { - wlr_box box = {w.m_vPosition.x, w.m_vPosition.y, w.m_vSize.x, w.m_vSize.y}; - if (w.m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && w.m_iWorkspaceID == PMONITOR->activeWorkspace && !w.m_bIsFloating && !w.m_bHidden) - return &w; + for (auto& w : m_vWindows) { + wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bIsFloating && !w->m_bHidden) + return w.get(); } return nullptr; @@ -387,24 +409,24 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos) { // special workspace if (PMONITOR->specialWorkspaceOpen) { - for (auto& w : m_lWindows) { - wlr_box box = {w.m_vPosition.x, w.m_vPosition.y, w.m_vSize.x, w.m_vSize.y}; - if (w.m_iWorkspaceID == SPECIAL_WORKSPACE_ID && w.m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && !w.m_bHidden) - return &w; + for (auto& w : m_vWindows) { + wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && !w->m_bHidden) + return w.get(); } } // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. - for (auto w = m_lWindows.rbegin(); w != m_lWindows.rend(); w++) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (w->m_bIsFloating && w->m_bIsMapped && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bHidden) - return &(*w); + for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) { + wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y}; + if ((*w)->m_bIsFloating && (*w)->m_bIsMapped && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && isWorkspaceVisible((*w)->m_iWorkspaceID) && !(*w)->m_bHidden) + return w->get(); } - for (auto& w : m_lWindows) { - wlr_box box = {w.m_vPosition.x, w.m_vPosition.y, w.m_vSize.x, w.m_vSize.y}; - if (!w.m_bIsFloating && w.m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && w.m_iWorkspaceID == PMONITOR->activeWorkspace && !w.m_bHidden) - return &w; + for (auto& w : m_vWindows) { + wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (!w->m_bIsFloating && w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bHidden) + return w.get(); } return nullptr; @@ -414,34 +436,34 @@ CWindow* CCompositor::windowFromCursor() { const auto PMONITOR = getMonitorFromCursor(); if (PMONITOR->specialWorkspaceOpen) { - for (auto& w : m_lWindows) { - wlr_box box = {w.m_vPosition.x, w.m_vPosition.y, w.m_vSize.x, w.m_vSize.y}; - if (w.m_iWorkspaceID == SPECIAL_WORKSPACE_ID && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w.m_bIsMapped) - return &w; + for (auto& w : m_vWindows) { + wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped) + return w.get(); } } // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. - for (auto w = m_lWindows.rbegin(); w != m_lWindows.rend(); w++) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID)) - return &(*w); + for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) { + wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y}; + if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && (*w)->m_bIsMapped && (*w)->m_bIsFloating && isWorkspaceVisible((*w)->m_iWorkspaceID)) + return w->get(); } - for (auto& w : m_lWindows) { - wlr_box box = {w.m_vPosition.x, w.m_vPosition.y, w.m_vSize.x, w.m_vSize.y}; - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w.m_bIsMapped && w.m_iWorkspaceID == PMONITOR->activeWorkspace) - return &w; + for (auto& w : m_vWindows) { + wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_iWorkspaceID == PMONITOR->activeWorkspace) + return w.get(); } return nullptr; } CWindow* CCompositor::windowFloatingFromCursor() { - for (auto w = m_lWindows.rbegin(); w != m_lWindows.rend(); w++) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bHidden) - return &(*w); + for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) { + wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y}; + if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && (*w)->m_bIsMapped && (*w)->m_bIsFloating && isWorkspaceVisible((*w)->m_iWorkspaceID) && !(*w)->m_bHidden) + return w->get(); } return nullptr; @@ -480,9 +502,9 @@ wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pW } SMonitor* CCompositor::getMonitorFromOutput(wlr_output* out) { - for (auto& m : m_lMonitors) { - if (m.output == out) { - return &m; + for (auto& m : m_vMonitors) { + if (m->output == out) { + return m.get(); } } @@ -595,9 +617,9 @@ bool CCompositor::windowValidMapped(CWindow* pWindow) { } CWindow* CCompositor::getWindowForPopup(wlr_xdg_popup* popup) { - for (auto& p : m_lXDGPopups) { - if (p.popup == popup) - return p.parentWindow; + for (auto& p : m_vXDGPopups) { + if (p->popup == popup) + return p->parentWindow; } return nullptr; @@ -618,29 +640,29 @@ wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::listgetWindowSurface(&w) == pSurface) - return &w; + for (auto& w : m_vWindows) { + if (g_pXWaylandManager->getWindowSurface(w.get()) == pSurface) + return w.get(); } return nullptr; } CWindow* CCompositor::getFullscreenWindowOnWorkspace(const int& ID) { - for (auto& w : m_lWindows) { - if (w.m_iWorkspaceID == ID && w.m_bIsFullscreen) - return &w; + for (auto& w : m_vWindows) { + if (w->m_iWorkspaceID == ID && w->m_bIsFullscreen) + return w.get(); } return nullptr; } bool CCompositor::isWorkspaceVisible(const int& w) { - for (auto& m : m_lMonitors) { - if (m.activeWorkspace == w) + for (auto& m : m_vMonitors) { + if (m->activeWorkspace == w) return true; - if (m.specialWorkspaceOpen && w == SPECIAL_WORKSPACE_ID) + if (m->specialWorkspaceOpen && w == SPECIAL_WORKSPACE_ID) return true; } @@ -648,34 +670,42 @@ bool CCompositor::isWorkspaceVisible(const int& w) { } CWorkspace* CCompositor::getWorkspaceByID(const int& id) { - for (auto& w : m_lWorkspaces) { - if (w.m_iID == id) - return &w; + for (auto& w : m_vWorkspaces) { + if (w->m_iID == id) + return w.get(); } return nullptr; } void CCompositor::sanityCheckWorkspaces() { - for (auto it = m_lWorkspaces.begin(); it != m_lWorkspaces.end(); ++it) { - if ((getWindowsOnWorkspace(it->m_iID) == 0 && !isWorkspaceVisible(it->m_iID))) { - it = m_lWorkspaces.erase(it); + for (auto it = m_vWorkspaces.begin(); it != m_vWorkspaces.end(); ++it) { + const auto WINDOWSONWORKSPACE = getWindowsOnWorkspace((*it)->m_iID); + + if ((WINDOWSONWORKSPACE == 0 && !isWorkspaceVisible((*it)->m_iID))) { + it = m_vWorkspaces.erase(it); + + if (it == m_vWorkspaces.end()) + break; } - if (it->m_iID == SPECIAL_WORKSPACE_ID && getWindowsOnWorkspace(it->m_iID) == 0) { - for (auto& m : m_lMonitors) { - m.specialWorkspaceOpen = false; + if ((*it)->m_iID == SPECIAL_WORKSPACE_ID && WINDOWSONWORKSPACE == 0) { + for (auto& m : m_vMonitors) { + m->specialWorkspaceOpen = false; } - it = m_lWorkspaces.erase(it); + it = m_vWorkspaces.erase(it); + + if (it == m_vWorkspaces.end()) + break; } } } int CCompositor::getWindowsOnWorkspace(const int& id) { int no = 0; - for (auto& w : m_lWindows) { - if (w.m_iWorkspaceID == id && w.m_bIsMapped) + for (auto& w : m_vWindows) { + if (w->m_iWorkspaceID == id && w->m_bIsMapped) no++; } @@ -683,9 +713,9 @@ int CCompositor::getWindowsOnWorkspace(const int& id) { } CWindow* CCompositor::getFirstWindowOnWorkspace(const int& id) { - for (auto& w : m_lWindows) { - if (w.m_iWorkspaceID == id) - return &w; + for (auto& w : m_vWindows) { + if (w->m_iWorkspaceID == id) + return w.get(); } return nullptr; @@ -699,16 +729,16 @@ void CCompositor::fixXWaylandWindowsOnWorkspace(const int& id) { if (!PWORKSPACE) return; - for (auto& w : m_lWindows) { - if (w.m_iWorkspaceID == id) { + for (auto& w : m_vWindows) { + if (w->m_iWorkspaceID == id) { // moveXWaylandWindow only moves XWayland windows // so there is no need to check here // if the window is XWayland or not. - if (ISVISIBLE && (!PWORKSPACE->m_bHasFullscreenWindow || w.m_bIsFullscreen)) - g_pXWaylandManager->moveXWaylandWindow(&w, w.m_vRealPosition.vec()); + if (ISVISIBLE && (!PWORKSPACE->m_bHasFullscreenWindow || w->m_bIsFullscreen)) + g_pXWaylandManager->moveXWaylandWindow(w.get(), w->m_vRealPosition.vec()); else - g_pXWaylandManager->moveXWaylandWindow(&w, Vector2D(42069,42069)); + g_pXWaylandManager->moveXWaylandWindow(w.get(), Vector2D(42069,42069)); } } } @@ -733,37 +763,37 @@ void CCompositor::moveWindowToTop(CWindow* pWindow) { if (!windowValidMapped(pWindow)) return; - for (auto it = m_lWindows.begin(); it != m_lWindows.end(); ++it) { - if (&(*it) == pWindow) { - m_lWindows.splice(m_lWindows.end(), m_lWindows, it); + for (auto it = m_vWindows.begin(); it != m_vWindows.end(); ++it) { + if (it->get() == pWindow) { + std::rotate(it, it + 1, m_vWindows.end()); break; } } } void CCompositor::cleanupFadingOut() { - for (auto& w : m_lWindowsFadingOut) { + for (auto& w : m_vWindowsFadingOut) { bool valid = windowExists(w); - + if (!valid || !w->m_bFadingOut || w->m_fAlpha.fl() == 0.f) { if (valid && !w->m_bReadyToDelete) continue; g_pHyprOpenGL->m_mWindowFramebuffers[w].release(); g_pHyprOpenGL->m_mWindowFramebuffers.erase(w); - m_lWindows.remove(*w); - m_lWindowsFadingOut.remove(w); + removeWindowFromVectorSafe(w); + m_vWindowsFadingOut.erase(std::remove(m_vWindowsFadingOut.begin(), m_vWindowsFadingOut.end(), w)); Debug::log(LOG, "Cleanup: destroyed a window"); return; } } - for (auto& ls : m_lSurfacesFadingOut) { + for (auto& ls : m_vSurfacesFadingOut) { if (ls->fadingOut && ls->readyToDelete && !ls->alpha.isBeingAnimated()) { - for (auto& m : m_lMonitors) { - for (auto& lsl : m.m_aLayerSurfaceLists) { + for (auto& m : m_vMonitors) { + for (auto& lsl : m->m_aLayerSurfaceLists) { lsl.remove(ls); } } @@ -772,7 +802,7 @@ void CCompositor::cleanupFadingOut() { g_pHyprOpenGL->m_mLayerFramebuffers.erase(ls); delete ls; - m_lSurfacesFadingOut.remove(ls); + m_vSurfacesFadingOut.erase(std::remove(m_vSurfacesFadingOut.begin(), m_vSurfacesFadingOut.end(), ls)); Debug::log(LOG, "Cleanup: destroyed a layersurface"); @@ -791,11 +821,11 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { auto longestIntersect = -1; CWindow* longestIntersectWindow = nullptr; - for (auto& w : m_lWindows) { - if (&w == pWindow || !windowValidMapped(&w) || w.m_bIsFloating || !isWorkspaceVisible(w.m_iWorkspaceID)) + for (auto& w : m_vWindows) { + if (w.get() == pWindow || !w->m_bIsMapped || w->m_bHidden || w->m_bIsFloating || !isWorkspaceVisible(w->m_iWorkspaceID)) continue; - const auto BWINDOWIDEALBB = w.getWindowIdealBoundingBoxIgnoreReserved(); + const auto BWINDOWIDEALBB = w->getWindowIdealBoundingBoxIgnoreReserved(); const auto POSB = Vector2D(BWINDOWIDEALBB.x, BWINDOWIDEALBB.y); const auto SIZEB = Vector2D(BWINDOWIDEALBB.width, BWINDOWIDEALBB.height); @@ -806,7 +836,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y)); if (INTERSECTLEN > longestIntersect) { longestIntersect = INTERSECTLEN; - longestIntersectWindow = &w; + longestIntersectWindow = w.get(); } } break; @@ -815,7 +845,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y)); if (INTERSECTLEN > longestIntersect) { longestIntersect = INTERSECTLEN; - longestIntersectWindow = &w; + longestIntersectWindow = w.get(); } } break; @@ -825,7 +855,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x)); if (INTERSECTLEN > longestIntersect) { longestIntersect = INTERSECTLEN; - longestIntersectWindow = &w; + longestIntersectWindow = w.get(); } } break; @@ -835,7 +865,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x)); if (INTERSECTLEN > longestIntersect) { longestIntersect = INTERSECTLEN; - longestIntersectWindow = &w; + longestIntersectWindow = w.get(); } } break; @@ -849,30 +879,30 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { } void CCompositor::deactivateAllWLRWorkspaces(wlr_ext_workspace_handle_v1* exclude) { - for (auto& w : m_lWorkspaces) { - if (w.m_pWlrHandle && w.m_pWlrHandle != exclude) - w.setActive(false); + for (auto& w : m_vWorkspaces) { + if (w->m_pWlrHandle && w->m_pWlrHandle != exclude) + w->setActive(false); } } CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow) { bool gotToWindow = false; - for (auto& w : m_lWindows) { - if (&w != pWindow && !gotToWindow) + for (auto& w : m_vWindows) { + if (w.get() != pWindow && !gotToWindow) continue; - if (&w == pWindow) { + if (w.get() == pWindow) { gotToWindow = true; continue; } - if (w.m_iWorkspaceID == pWindow->m_iWorkspaceID && windowValidMapped(&w)) - return &w; + if (w->m_iWorkspaceID == pWindow->m_iWorkspaceID && w->m_bIsMapped && !w->m_bHidden) + return w.get(); } - for (auto& w : m_lWindows) { - if (&w != pWindow && w.m_iWorkspaceID == pWindow->m_iWorkspaceID && windowValidMapped(&w)) - return &w; + for (auto& w : m_vWindows) { + if (w.get() != pWindow && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && w->m_bIsMapped && !w->m_bHidden) + return w.get(); } return nullptr; @@ -880,18 +910,18 @@ CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow) { int CCompositor::getNextAvailableNamedWorkspace() { int lowest = -1337 + 1; - for (auto& w : m_lWorkspaces) { - if (w.m_iID < -1 && w.m_iID < lowest) - lowest = w.m_iID; + for (auto& w : m_vWorkspaces) { + if (w->m_iID < -1 && w->m_iID < lowest) + lowest = w->m_iID; } return lowest - 1; } CWorkspace* CCompositor::getWorkspaceByName(const std::string& name) { - for (auto& w : m_lWorkspaces) { - if (w.m_szName == name) - return &w; + for (auto& w : m_vWorkspaces) { + if (w->m_szName == name) + return w.get(); } return nullptr; @@ -913,8 +943,8 @@ CWorkspace* CCompositor::getWorkspaceByString(const std::string& str) { } bool CCompositor::isPointOnAnyMonitor(const Vector2D& point) { - for (auto& m : m_lMonitors) { - if (VECINRECT(point, m.vecPosition.x, m.vecPosition.y, m.vecSize.x + m.vecPosition.x, m.vecSize.y + m.vecPosition.y)) + for (auto& m : m_vMonitors) { + if (VECINRECT(point, m->vecPosition.x, m->vecPosition.y, m->vecSize.x + m->vecPosition.x, m->vecSize.y + m->vecPosition.y)) return true; } @@ -927,12 +957,12 @@ CWindow* CCompositor::getConstraintWindow(SMouse* pMouse) { const auto PSURFACE = pMouse->currentConstraint->surface; - for (auto& w : m_lWindows) { - if (PSURFACE == g_pXWaylandManager->getWindowSurface(&w)) { - if (!w.m_bIsX11 && !windowValidMapped(&w)) + for (auto& w : m_vWindows) { + if (PSURFACE == g_pXWaylandManager->getWindowSurface(w.get())) { + if (!w->m_bIsX11 && w->m_bIsMapped && !w->m_bHidden) continue; - return &w; + return w.get(); } } @@ -946,19 +976,19 @@ SMonitor* CCompositor::getMonitorInDirection(const char& dir) { auto longestIntersect = -1; SMonitor* longestIntersectMonitor = nullptr; - for (auto& m : m_lMonitors) { - if (&m == m_pLastMonitor) + for (auto& m : m_vMonitors) { + if (m.get() == m_pLastMonitor) continue; - const auto POSB = m.vecPosition; - const auto SIZEB = m.vecSize; + const auto POSB = m->vecPosition; + const auto SIZEB = m->vecSize; switch (dir) { case 'l': if (STICKS(POSA.x, POSB.x + SIZEB.x)) { const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y)); if (INTERSECTLEN > longestIntersect) { longestIntersect = INTERSECTLEN; - longestIntersectMonitor = &m; + longestIntersectMonitor = m.get(); } } break; @@ -967,7 +997,7 @@ SMonitor* CCompositor::getMonitorInDirection(const char& dir) { const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y)); if (INTERSECTLEN > longestIntersect) { longestIntersect = INTERSECTLEN; - longestIntersectMonitor = &m; + longestIntersectMonitor = m.get(); } } break; @@ -977,7 +1007,7 @@ SMonitor* CCompositor::getMonitorInDirection(const char& dir) { const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x)); if (INTERSECTLEN > longestIntersect) { longestIntersect = INTERSECTLEN; - longestIntersectMonitor = &m; + longestIntersectMonitor = m.get(); } } break; @@ -987,7 +1017,7 @@ SMonitor* CCompositor::getMonitorInDirection(const char& dir) { const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x)); if (INTERSECTLEN > longestIntersect) { longestIntersect = INTERSECTLEN; - longestIntersectMonitor = &m; + longestIntersectMonitor = m.get(); } } break; @@ -1001,11 +1031,11 @@ SMonitor* CCompositor::getMonitorInDirection(const char& dir) { } void CCompositor::updateAllWindowsBorders() { - for (auto& w : m_lWindows) { - if (!w.m_bIsMapped) + for (auto& w : m_vWindows) { + if (!w->m_bIsMapped) continue; - updateWindowBorderColor(&w); + updateWindowBorderColor(w.get()); } } @@ -1030,9 +1060,9 @@ void CCompositor::moveWindowToWorkspace(CWindow* pWindow, const std::string& wor int CCompositor::getNextAvailableMonitorID() { int64_t topID = -1; - for (auto& m : m_lMonitors) { - if ((int64_t)m.ID > topID) - topID = m.ID; + for (auto& m : m_vMonitors) { + if ((int64_t)m->ID > topID) + topID = m->ID; } return topID + 1; @@ -1053,9 +1083,9 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, SMonitor* pMoni // fix old mon int nextWorkspaceOnMonitorID = -1; - for (auto& w : m_lWorkspaces) { - if (w.m_iMonitorID == POLDMON->ID && w.m_iID != pWorkspace->m_iID) { - nextWorkspaceOnMonitorID = w.m_iID; + for (auto& w : m_vWorkspaces) { + if (w->m_iMonitorID == POLDMON->ID && w->m_iID != pWorkspace->m_iID) { + nextWorkspaceOnMonitorID = w->m_iID; break; } } @@ -1079,9 +1109,9 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, SMonitor* pMoni pWorkspace->m_iMonitorID = pMonitor->ID; pWorkspace->moveToMonitor(pMonitor->ID); - for (auto& w : m_lWindows) { - if (w.m_iWorkspaceID == pWorkspace->m_iID) - w.m_iMonitorID = pMonitor->ID; + for (auto& w : m_vWindows) { + if (w->m_iWorkspaceID == pWorkspace->m_iID) + w->m_iMonitorID = pMonitor->ID; } if (SWITCHINGISACTIVE) { // if it was active, preserve its' status. If it wasn't, don't. @@ -1108,12 +1138,12 @@ bool CCompositor::workspaceIDOutOfBounds(const int& id) { int lowestID = 99999; int highestID = -99999; - for (auto& w : m_lWorkspaces) { - if (w.m_iID < lowestID) - lowestID = w.m_iID; + for (auto& w : m_vWorkspaces) { + if (w->m_iID < lowestID) + lowestID = w->m_iID; - if (w.m_iID > highestID) - highestID = w.m_iID; + if (w->m_iID > highestID) + highestID = w->m_iID; } return std::clamp(id, lowestID, highestID) != id; @@ -1127,8 +1157,33 @@ void CCompositor::setWindowFullscreen(CWindow* pWindow, bool on, eFullscreenMode g_pXWaylandManager->setWindowFullscreen(pWindow, pWindow->m_bIsFullscreen && mode == FULLSCREEN_FULL); // make all windows on the same workspace under the fullscreen window - for (auto& w : g_pCompositor->m_lWindows) { - if (w.m_iWorkspaceID == pWindow->m_iWorkspaceID) - w.m_bCreatedOverFullscreen = false; + for (auto& w : g_pCompositor->m_vWindows) { + if (w->m_iWorkspaceID == pWindow->m_iWorkspaceID) + w->m_bCreatedOverFullscreen = false; } +} + +void CCompositor::moveUnmanagedX11ToWindows(CWindow* pWindow) { + for (auto it = m_dUnmanagedX11Windows.begin(); it != m_dUnmanagedX11Windows.end(); it++) { + if (it->get() == pWindow) { + m_vWindows.emplace_back(std::move(*it)); + m_dUnmanagedX11Windows.erase(it); + return; + } + } +} + +CWindow* CCompositor::getX11Parent(CWindow* pWindow) { + if (!pWindow->m_bIsX11) + return nullptr; + + for (auto& w : m_vWindows) { + if (!w->m_bIsX11) + continue; + + if (w->m_uSurface.xwayland == pWindow->m_uSurface.xwayland->parent) + return w.get(); + } + + return nullptr; } \ No newline at end of file diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 493d3744..ae7777d3 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -67,13 +67,14 @@ public: const char* m_szWLDisplaySocket; std::string m_szInstanceSignature = ""; - std::list m_lMonitors; - std::list m_lWindows; - std::list m_lXDGPopups; - std::list m_lWorkspaces; - std::list m_lSubsurfaces; - std::list m_lWindowsFadingOut; - std::list m_lSurfacesFadingOut; + std::vector> m_vMonitors; + std::vector> m_vWindows; + std::deque> m_dUnmanagedX11Windows; + std::vector> m_vXDGPopups; + std::vector> m_vWorkspaces; + std::vector> m_vSubsurfaces; + std::vector m_vWindowsFadingOut; + std::vector m_vSurfacesFadingOut; void startCompositor(); void cleanupExit(); @@ -134,6 +135,8 @@ public: void moveWorkspaceToMonitor(CWorkspace*, SMonitor*); bool workspaceIDOutOfBounds(const int&); void setWindowFullscreen(CWindow*, bool, eFullscreenMode); + void moveUnmanagedX11ToWindows(CWindow*); + CWindow* getX11Parent(CWindow*); private: void initAllSignals(); diff --git a/src/Window.hpp b/src/Window.hpp index 9bd44ae0..ca6bcbf6 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -67,6 +67,7 @@ public: // XWayland stuff bool m_bIsX11 = false; bool m_bMappedX11 = false; + CWindow* m_pX11Parent = nullptr; uint64_t m_iX11Type = 0; bool m_bIsModal = false; bool m_bX11DoesntWantBorders = false; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index c52a04bf..75546a63 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -613,8 +613,8 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: parseError = ""; // invalidate layouts jic - for (auto& m : g_pCompositor->m_lMonitors) - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m.ID); + for (auto& m : g_pCompositor->m_vMonitors) + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); // Update window border colors g_pCompositor->updateAllWindowsBorders(); @@ -774,8 +774,8 @@ void CConfigManager::loadConfigLoadVars() { ifs.close(); } - for (auto& m : g_pCompositor->m_lMonitors) - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m.ID); + for (auto& m : g_pCompositor->m_vMonitors) + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); // Update the keyboard layout to the cfg'd one if this is not the first launch if (!isFirstLaunch) @@ -810,8 +810,8 @@ void CConfigManager::loadConfigLoadVars() { g_pCompositor->updateAllWindowsBorders(); // Force the compositor to fully re-render all monitors - for (auto& m : g_pCompositor->m_lMonitors) - m.forceFullFrames = 2; + for (auto& m : g_pCompositor->m_vMonitors) + m->forceFullFrames = 2; } void CConfigManager::tick() { @@ -970,9 +970,9 @@ void CConfigManager::dispatchExecOnce() { } void CConfigManager::performMonitorReload() { - for (auto& m : g_pCompositor->m_lMonitors) { - auto rule = getMonitorRuleFor(m.szName); - g_pHyprRenderer->applyMonitorRule(&m, &rule); + for (auto& m : g_pCompositor->m_vMonitors) { + auto rule = getMonitorRuleFor(m->szName); + g_pHyprRenderer->applyMonitorRule(m.get(), &rule); } m_bWantsMonitorReload = false; diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index a19ef5ba..eb6c085c 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -15,9 +15,9 @@ std::string monitorsRequest() { std::string result = ""; - for (auto& m : g_pCompositor->m_lMonitors) { + for (auto& m : g_pCompositor->m_vMonitors) { result += getFormat("Monitor %s (ID %i):\n\t%ix%i@%f at %ix%i\n\tactive workspace: %i (%s)\n\treserved: %i %i %i %i\n\tscale: %.2f\n\ttransform: %i\n\n", - m.szName.c_str(), m.ID, (int)m.vecPixelSize.x, (int)m.vecPixelSize.y, m.refreshRate, (int)m.vecPosition.x, (int)m.vecPosition.y, m.activeWorkspace, g_pCompositor->getWorkspaceByID(m.activeWorkspace)->m_szName.c_str(), (int)m.vecReservedTopLeft.x, (int)m.vecReservedTopLeft.y, (int)m.vecReservedBottomRight.x, (int)m.vecReservedBottomRight.y, m.scale, (int)m.transform); + m->szName.c_str(), m->ID, (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, m->activeWorkspace, g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName.c_str(), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform); } return result; @@ -25,10 +25,10 @@ std::string monitorsRequest() { std::string clientsRequest() { std::string result = ""; - for (auto& w : g_pCompositor->m_lWindows) { - if (w.m_bIsMapped) { + for (auto& w : g_pCompositor->m_vWindows) { + if (w->m_bIsMapped) { result += getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i,%i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\tclass: %s\n\ttitle: %s\n\tpid: %i\n\n", - &w, w.m_szTitle.c_str(), (int)w.m_vRealPosition.vec().x, (int)w.m_vRealPosition.vec().y, (int)w.m_vRealSize.vec().x, (int)w.m_vRealSize.vec().y, w.m_iWorkspaceID, (w.m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w.m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w.m_iWorkspaceID)->m_szName.c_str() : std::string("Invalid workspace " + std::to_string(w.m_iWorkspaceID)).c_str()), (int)w.m_bIsFloating, w.m_iMonitorID, g_pXWaylandManager->getAppIDClass(&w).c_str(), g_pXWaylandManager->getTitle(&w).c_str(), w.getPID()); + &w, w->m_szTitle.c_str(), (int)w->m_vRealPosition.vec().x, (int)w->m_vRealPosition.vec().y, (int)w->m_vRealSize.vec().x, (int)w->m_vRealSize.vec().y, w->m_iWorkspaceID, (w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName.c_str() : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID)).c_str()), (int)w->m_bIsFloating, w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w.get()).c_str(), g_pXWaylandManager->getTitle(w.get()).c_str(), w->getPID()); } } @@ -37,9 +37,9 @@ std::string clientsRequest() { std::string workspacesRequest() { std::string result = ""; - for (auto& w : g_pCompositor->m_lWorkspaces) { + for (auto& w : g_pCompositor->m_vWorkspaces) { result += getFormat("workspace ID %i (%s) on monitor %s:\n\twindows: %i\n\thasfullscreen: %i\n\n", - w.m_iID, w.m_szName.c_str(), g_pCompositor->getMonitorFromID(w.m_iMonitorID)->szName.c_str(), g_pCompositor->getWindowsOnWorkspace(w.m_iID), (int)w.m_bHasFullscreenWindow); + w->m_iID, w->m_szName.c_str(), g_pCompositor->getMonitorFromID(w->m_iMonitorID)->szName.c_str(), g_pCompositor->getWindowsOnWorkspace(w->m_iID), (int)w->m_bHasFullscreenWindow); } return result; } @@ -57,10 +57,10 @@ std::string activeWindowRequest() { std::string layersRequest() { std::string result = ""; - for (auto& mon : g_pCompositor->m_lMonitors) { + for (auto& mon : g_pCompositor->m_vMonitors) { result += getFormat("Monitor %s:\n"); int layerLevel = 0; - for (auto& level : mon.m_aLayerSurfaceLists) { + for (auto& level : mon->m_aLayerSurfaceLists) { result += getFormat("\tLayer level %i:\n", layerLevel); for (auto& layer : level) { diff --git a/src/debug/HyprDebugOverlay.cpp b/src/debug/HyprDebugOverlay.cpp index 0eb3ba17..b8d7c32b 100644 --- a/src/debug/HyprDebugOverlay.cpp +++ b/src/debug/HyprDebugOverlay.cpp @@ -120,7 +120,7 @@ int CHyprMonitorDebugOverlay::draw(int offset) { yOffset += 11; g_pHyprRenderer->damageBox(&m_wbLastDrawnBox); - m_wbLastDrawnBox = {(int)g_pCompositor->m_lMonitors.front().vecPosition.x, (int)g_pCompositor->m_lMonitors.front().vecPosition.y + offset - 1, (int)maxX + 2, yOffset - offset + 2}; + m_wbLastDrawnBox = {(int)g_pCompositor->m_vMonitors.front()->vecPosition.x, (int)g_pCompositor->m_vMonitors.front()->vecPosition.y + offset - 1, (int)maxX + 2, yOffset - offset + 2}; g_pHyprRenderer->damageBox(&m_wbLastDrawnBox); return yOffset - offset; @@ -140,7 +140,7 @@ void CHyprDebugOverlay::frameData(SMonitor* pMonitor) { void CHyprDebugOverlay::draw() { - const auto PMONITOR = &g_pCompositor->m_lMonitors.front(); + const auto PMONITOR = g_pCompositor->m_vMonitors.front().get(); if (!m_pCairoSurface || !m_pCairo) { m_pCairoSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, PMONITOR->vecSize.x, PMONITOR->vecSize.y); @@ -155,8 +155,8 @@ void CHyprDebugOverlay::draw() { // draw the things int offsetY = 0; - for (auto& m : g_pCompositor->m_lMonitors) { - offsetY += m_mMonitorOverlays[&m].draw(offsetY); + for (auto& m : g_pCompositor->m_vMonitors) { + offsetY += m_mMonitorOverlays[m.get()].draw(offsetY); offsetY += 5; // for padding between mons } diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 01cc25cc..5e9675e9 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -36,7 +36,7 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) { SLayerSurface* layerSurface = PMONITOR->m_aLayerSurfaceLists[WLRLAYERSURFACE->pending.layer].back(); if (!WLRLAYERSURFACE->output) { - WLRLAYERSURFACE->output = g_pCompositor->m_lMonitors.front().output; // TODO: current mon + WLRLAYERSURFACE->output = g_pCompositor->m_vMonitors.front()->output; // TODO: current mon } layerSurface->hyprListener_commitLayerSurface.initCallback(&WLRLAYERSURFACE->surface->events.commit, &Events::listener_commitLayerSurface, layerSurface, "layerSurface"); @@ -145,7 +145,7 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { layersurface->fadingOut = true; - g_pCompositor->m_lSurfacesFadingOut.push_back(layersurface); + g_pCompositor->m_vSurfacesFadingOut.push_back(layersurface); if (layersurface->layerSurface->mapped) layersurface->layerSurface->mapped = false; diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index 8142d1c8..11527cee 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -21,24 +21,24 @@ void Events::listener_change(wl_listener* listener, void* data) { // layout got changed, let's update monitors. const auto CONFIG = wlr_output_configuration_v1_create(); - for (auto& m : g_pCompositor->m_lMonitors) { - const auto CONFIGHEAD = wlr_output_configuration_head_v1_create(CONFIG, m.output); + for (auto& m : g_pCompositor->m_vMonitors) { + const auto CONFIGHEAD = wlr_output_configuration_head_v1_create(CONFIG, m->output); // TODO: clients off of disabled wlr_box BOX; - wlr_output_layout_get_box(g_pCompositor->m_sWLROutputLayout, m.output, &BOX); + wlr_output_layout_get_box(g_pCompositor->m_sWLROutputLayout, m->output, &BOX); - //m.vecSize.x = BOX.width; - // m.vecSize.y = BOX.height; - m.vecPosition.x = BOX.x; - m.vecPosition.y = BOX.y; + //m->vecSize.x = BOX.width; + // m->vecSize.y = BOX.height; + m->vecPosition.x = BOX.x; + m->vecPosition.y = BOX.y; - CONFIGHEAD->state.enabled = m.output->enabled; - CONFIGHEAD->state.mode = m.output->current_mode; - CONFIGHEAD->state.x = m.vecPosition.x; - CONFIGHEAD->state.y = m.vecPosition.y; + CONFIGHEAD->state.enabled = m->output->enabled; + CONFIGHEAD->state.mode = m->output->current_mode; + CONFIGHEAD->state.x = m->vecPosition.x; + CONFIGHEAD->state.y = m->vecPosition.y; - wlr_output_set_custom_mode(m.output, m.vecPixelSize.x, m.vecPixelSize.y, (int)(round(m.refreshRate * 1000))); + wlr_output_set_custom_mode(m->output, m->vecPixelSize.x, m->vecPixelSize.y, (int)(round(m->refreshRate * 1000))); } wlr_output_manager_v1_set_configuration(g_pCompositor->m_sWLROutputMgr, CONFIG); @@ -90,8 +90,7 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { newMonitor.vecSize = monitorRule.resolution; newMonitor.refreshRate = monitorRule.refreshRate; - g_pCompositor->m_lMonitors.push_back(newMonitor); - const auto PNEWMONITOR = &g_pCompositor->m_lMonitors.back(); + const auto PNEWMONITOR = g_pCompositor->m_vMonitors.emplace_back(std::make_unique(newMonitor)).get(); PNEWMONITOR->hyprListener_monitorFrame.initCallback(&OUTPUT->events.frame, &Events::listener_monitorFrame, PNEWMONITOR); PNEWMONITOR->hyprListener_monitorDestroy.initCallback(&OUTPUT->events.destroy, &Events::listener_monitorDestroy, PNEWMONITOR); @@ -115,10 +114,10 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { // Workspace std::string newDefaultWorkspaceName = ""; - auto WORKSPACEID = monitorRule.defaultWorkspace == "" ? g_pCompositor->m_lWorkspaces.size() + 1 : getWorkspaceIDFromString(monitorRule.defaultWorkspace, newDefaultWorkspaceName); + auto WORKSPACEID = monitorRule.defaultWorkspace == "" ? g_pCompositor->m_vWorkspaces.size() + 1 : getWorkspaceIDFromString(monitorRule.defaultWorkspace, newDefaultWorkspaceName); if (WORKSPACEID == INT_MAX || WORKSPACEID == (long unsigned int)SPECIAL_WORKSPACE_ID) { - WORKSPACEID = g_pCompositor->m_lWorkspaces.size() + 1; + WORKSPACEID = g_pCompositor->m_vWorkspaces.size() + 1; newDefaultWorkspaceName = std::to_string(WORKSPACEID); Debug::log(LOG, "Invalid workspace= directive name in monitor parsing, workspace name \"%s\" is invalid.", monitorRule.defaultWorkspace); @@ -135,7 +134,7 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PNEWMONITOR->ID); PNEWWORKSPACE->startAnim(true,true,true); } else { - PNEWWORKSPACE = &g_pCompositor->m_lWorkspaces.emplace_back(newMonitor.ID, newDefaultWorkspaceName); + PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique(newMonitor.ID, newDefaultWorkspaceName)).get(); // We are required to set the name here immediately wlr_ext_workspace_handle_v1_set_name(PNEWWORKSPACE->m_pWlrHandle, newDefaultWorkspaceName.c_str()); @@ -339,9 +338,9 @@ void Events::listener_monitorDestroy(void* owner, void* data) { SMonitor* pMonitor = nullptr; - for (auto& m : g_pCompositor->m_lMonitors) { - if (m.szName == OUTPUT->name) { - pMonitor = &m; + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->szName == OUTPUT->name) { + pMonitor = m.get(); break; } } @@ -350,7 +349,7 @@ void Events::listener_monitorDestroy(void* owner, void* data) { return; // Cleanup everything. Move windows back, snap cursor, shit. - const auto BACKUPMON = &g_pCompositor->m_lMonitors.front(); + const auto BACKUPMON = g_pCompositor->m_vMonitors.front().get(); if (!BACKUPMON) { Debug::log(CRIT, "No monitors! Unplugged last! Exiting."); @@ -366,9 +365,9 @@ void Events::listener_monitorDestroy(void* owner, void* data) { // move workspaces std::deque wspToMove; - for (auto& w : g_pCompositor->m_lWorkspaces) { - if (w.m_iMonitorID == pMonitor->ID) { - wspToMove.push_back(&w); + for (auto& w : g_pCompositor->m_vWorkspaces) { + if (w->m_iMonitorID == pMonitor->ID) { + wspToMove.push_back(w.get()); } } @@ -379,27 +378,23 @@ void Events::listener_monitorDestroy(void* owner, void* data) { pMonitor->activeWorkspace = -1; - for (auto it = g_pCompositor->m_lWorkspaces.begin(); it != g_pCompositor->m_lWorkspaces.end(); ++it) { - if (it->m_iMonitorID == pMonitor->ID) { - it = g_pCompositor->m_lWorkspaces.erase(it); - } - } + g_pCompositor->m_vWorkspaces.erase(std::remove_if(g_pCompositor->m_vWorkspaces.begin(), g_pCompositor->m_vWorkspaces.end(), [&](std::unique_ptr& el) { return el->m_iMonitorID == pMonitor->ID; })); Debug::log(LOG, "Removed monitor %s!", pMonitor->szName.c_str()); g_pEventManager->postEvent(SHyprIPCEvent("monitorremoved", pMonitor->szName)); - g_pCompositor->m_lMonitors.remove(*pMonitor); + g_pCompositor->m_vMonitors.erase(std::remove_if(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](std::unique_ptr& el) { return el.get() == pMonitor; })); // update the pMostHzMonitor if (pMostHzMonitor == pMonitor) { int mostHz = 0; SMonitor* pMonitorMostHz = nullptr; - for (auto& m : g_pCompositor->m_lMonitors) { - if (m.refreshRate > mostHz) { - pMonitorMostHz = &m; - mostHz = m.refreshRate; + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->refreshRate > mostHz) { + pMonitorMostHz = m.get(); + mostHz = m->refreshRate; } } diff --git a/src/events/Popups.cpp b/src/events/Popups.cpp index 7e619632..cfb92f9b 100644 --- a/src/events/Popups.cpp +++ b/src/events/Popups.cpp @@ -76,8 +76,7 @@ void Events::listener_newPopup(void* owner, void* data) { const auto WLRPOPUP = (wlr_xdg_popup*)data; - g_pCompositor->m_lXDGPopups.push_back(SXDGPopup()); - const auto PNEWPOPUP = &g_pCompositor->m_lXDGPopups.back(); + const auto PNEWPOPUP = g_pCompositor->m_vXDGPopups.emplace_back(std::make_unique()).get(); const auto PMONITOR = g_pCompositor->getMonitorFromID(layersurface->monitorID); @@ -97,8 +96,7 @@ void Events::listener_newPopupXDG(void* owner, void* data) { const auto WLRPOPUP = (wlr_xdg_popup*)data; - g_pCompositor->m_lXDGPopups.push_back(SXDGPopup()); - const auto PNEWPOPUP = &g_pCompositor->m_lXDGPopups.back(); + const auto PNEWPOPUP = g_pCompositor->m_vXDGPopups.emplace_back(std::make_unique()).get(); const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); @@ -122,8 +120,7 @@ void Events::listener_newPopupFromPopupXDG(void* owner, void* data) { const auto WLRPOPUP = (wlr_xdg_popup*)data; - g_pCompositor->m_lXDGPopups.push_back(SXDGPopup()); - const auto PNEWPOPUP = &g_pCompositor->m_lXDGPopups.back(); + const auto PNEWPOPUP = g_pCompositor->m_vXDGPopups.emplace_back(std::make_unique()).get(); PNEWPOPUP->popup = WLRPOPUP; PNEWPOPUP->parentPopup = PPOPUP; @@ -170,5 +167,5 @@ void Events::listener_destroyPopupXDG(void* owner, void* data) { PPOPUP->pSurfaceTree = nullptr; } - g_pCompositor->m_lXDGPopups.remove(*PPOPUP); + g_pCompositor->m_vXDGPopups.erase(std::remove_if(g_pCompositor->m_vXDGPopups.begin(), g_pCompositor->m_vXDGPopups.end(), [&](std::unique_ptr& el) { return el.get() == PPOPUP; })); } \ No newline at end of file diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 29d21f6f..e5bf3696 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -43,6 +43,9 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->m_szTitle = g_pXWaylandManager->getTitle(PWINDOW); PWINDOW->m_fAlpha = 255.f; + if (PWINDOW->m_iX11Type == 2) + g_pCompositor->moveUnmanagedX11ToWindows(PWINDOW); + // Set all windows tiled regardless of anything g_pXWaylandManager->setWindowStyleTiled(PWINDOW, WLR_EDGE_LEFT | WLR_EDGE_RIGHT | WLR_EDGE_TOP | WLR_EDGE_BOTTOM); @@ -57,7 +60,7 @@ void Events::listener_mapWindow(void* owner, void* data) { const auto PWINDOWSURFACE = g_pXWaylandManager->getWindowSurface(PWINDOW); if (!PWINDOWSURFACE) { - g_pCompositor->m_lWindows.remove(*PWINDOW); + g_pCompositor->removeWindowFromVectorSafe(PWINDOW); return; } @@ -97,7 +100,7 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->m_iMonitorID = PMONITOR->ID; } else { const long int MONITOR = std::stoi(MONITORSTR); - if (MONITOR >= (long int)g_pCompositor->m_lMonitors.size() || MONITOR < (long int)0) + if (MONITOR >= (long int)g_pCompositor->m_vMonitors.size() || MONITOR < (long int)0) PWINDOW->m_iMonitorID = 0; else PWINDOW->m_iMonitorID = MONITOR; @@ -330,7 +333,7 @@ void Events::listener_unmapWindow(void* owner, void* data) { PWINDOW->m_bFadingOut = true; - g_pCompositor->m_lWindowsFadingOut.push_back(PWINDOW); + g_pCompositor->m_vWindowsFadingOut.emplace_back(PWINDOW); g_pHyprRenderer->damageMonitor(g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)); @@ -474,13 +477,14 @@ void Events::listener_surfaceXWayland(wl_listener* listener, void* data) { if (XWSURFACE->parent) Debug::log(LOG, "Window parent data: %s at %x", XWSURFACE->parent->_class, XWSURFACE->parent); - g_pCompositor->m_lWindows.emplace_back(); - const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back(); + const auto PNEWWINDOW = XWSURFACE->override_redirect ? g_pCompositor->m_dUnmanagedX11Windows.emplace_back(std::make_unique()).get() : g_pCompositor->m_vWindows.emplace_back(std::make_unique()).get(); PNEWWINDOW->m_uSurface.xwayland = XWSURFACE; PNEWWINDOW->m_iX11Type = XWSURFACE->override_redirect ? 2 : 1; PNEWWINDOW->m_bIsX11 = true; + PNEWWINDOW->m_pX11Parent = g_pCompositor->getX11Parent(PNEWWINDOW); + PNEWWINDOW->hyprListener_mapWindow.initCallback(&XWSURFACE->events.map, &Events::listener_mapWindow, PNEWWINDOW, "XWayland Window"); PNEWWINDOW->hyprListener_unmapWindow.initCallback(&XWSURFACE->events.unmap, &Events::listener_unmapWindow, PNEWWINDOW, "XWayland Window"); PNEWWINDOW->hyprListener_destroyWindow.initCallback(&XWSURFACE->events.destroy, &Events::listener_destroyWindow, PNEWWINDOW, "XWayland Window"); @@ -495,8 +499,7 @@ void Events::listener_newXDGSurface(wl_listener* listener, void* data) { if (XDGSURFACE->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) return; // TODO: handle? - g_pCompositor->m_lWindows.emplace_back(); - const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back(); + const auto PNEWWINDOW = g_pCompositor->m_vWindows.emplace_back(std::make_unique()).get(); PNEWWINDOW->m_uSurface.xdg = XDGSURFACE; PNEWWINDOW->hyprListener_mapWindow.initCallback(&XDGSURFACE->events.map, &Events::listener_mapWindow, PNEWWINDOW, "XDG Window"); diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index d5eece67..067a351f 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -219,12 +219,12 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { int lowestID = 99999; int highestID = -99999; - for (auto& w : g_pCompositor->m_lWorkspaces) { - if (w.m_iID < lowestID) - lowestID = w.m_iID; + for (auto& w : g_pCompositor->m_vWorkspaces) { + if (w->m_iID < lowestID) + lowestID = w->m_iID; - if (w.m_iID > highestID) - highestID = w.m_iID; + if (w->m_iID > highestID) + highestID = w->m_iID; } if (remains < 0) diff --git a/src/hyprerror/HyprError.cpp b/src/hyprerror/HyprError.cpp index 135f9635..7255aae9 100644 --- a/src/hyprerror/HyprError.cpp +++ b/src/hyprerror/HyprError.cpp @@ -12,7 +12,7 @@ void CHyprError::createQueued() { m_tTexture.destroyTexture(); } - const auto PMONITOR = &g_pCompositor->m_lMonitors.front(); + const auto PMONITOR = g_pCompositor->m_vMonitors.front().get(); const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, PMONITOR->vecSize.x, PMONITOR->vecSize.y); @@ -95,11 +95,11 @@ void CHyprError::draw() { m_tTexture.destroyTexture(); m_bIsCreated = false; m_szQueued = ""; - g_pHyprRenderer->damageMonitor(&g_pCompositor->m_lMonitors.front()); + g_pHyprRenderer->damageMonitor(g_pCompositor->m_vMonitors.front().get()); return; } - const auto PMONITOR = &g_pCompositor->m_lMonitors.front(); + const auto PMONITOR = g_pCompositor->m_vMonitors.front().get(); if (g_pHyprOpenGL->m_RenderData.pMonitor != PMONITOR) return; // wrong mon diff --git a/src/includes.hpp b/src/includes.hpp index a1fdda70..2455171d 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -117,3 +117,5 @@ extern "C" { #include "helpers/Vector2D.hpp" #include "ext-workspace-unstable-v1-protocol.h" + +#include \ No newline at end of file diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 5e3df81f..e48b4d1e 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -145,14 +145,14 @@ void CAnimationManager::tick() { g_pHyprRenderer->damageWindow(PWINDOW); PWINDOW->updateWindowDecos(); } else if (PWORKSPACE) { - for (auto& w : g_pCompositor->m_lWindows) { - if (!w.m_bIsMapped || w.m_bHidden) + for (auto& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped || w->m_bHidden) continue; - if (w.m_iWorkspaceID != PWORKSPACE->m_iID) + if (w->m_iWorkspaceID != PWORKSPACE->m_iID) continue; - w.updateWindowDecos(); + w->updateWindowDecos(); } } break; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 64c0d886..e2a26781 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -118,10 +118,10 @@ bool CKeybindManager::handleVT(xkb_keysym_t keysym) { const int TTY = keysym - XKB_KEY_XF86Switch_VT_1 + 1; wlr_session_change_vt(PSESSION, TTY); - for (auto& m : g_pCompositor->m_lMonitors) { - g_pHyprOpenGL->destroyMonitorResources(&m); // mark resources as unusable anymore - m.noFrameSchedule = true; - m.framesToSkip = 2; + for (auto& m : g_pCompositor->m_vMonitors) { + g_pHyprOpenGL->destroyMonitorResources(m.get()); // mark resources as unusable anymore + m->noFrameSchedule = true; + m->framesToSkip = 2; } Debug::log(LOG, "Switched to VT %i, destroyed all render data, frames to skip for each: 2", TTY); @@ -339,8 +339,7 @@ void CKeybindManager::changeworkspace(std::string args) { if (const auto POLDWORKSPACE = g_pCompositor->getWorkspaceByID(OLDWORKSPACE); POLDWORKSPACE) POLDWORKSPACE->startAnim(false, ANIMTOLEFT); - g_pCompositor->m_lWorkspaces.emplace_back(PMONITOR->ID, workspaceName, workspaceToChangeTo == SPECIAL_WORKSPACE_ID); - const auto PWORKSPACE = &g_pCompositor->m_lWorkspaces.back(); + const auto PWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique(PMONITOR->ID, workspaceName, workspaceToChangeTo == SPECIAL_WORKSPACE_ID)).get(); // start anim on new workspace PWORKSPACE->startAnim(true, ANIMTOLEFT); @@ -456,8 +455,8 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { toggleSpecialWorkspace(""); g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(false, false, true); - for (auto& m : g_pCompositor->m_lMonitors) - m.specialWorkspaceOpen = false; + for (auto& m : g_pCompositor->m_vMonitors) + m->specialWorkspaceOpen = false; } g_pInputManager->refocus(); @@ -662,7 +661,7 @@ void CKeybindManager::focusMonitor(std::string arg) { Debug::log(ERR, "Error in focusMonitor: invalid num"); } - if (monID > -1 && monID < (int)g_pCompositor->m_lMonitors.size()) { + if (monID > -1 && monID < (int)g_pCompositor->m_vMonitors.size()) { changeworkspace(std::to_string(g_pCompositor->getMonitorFromID(monID)->activeWorkspace)); } else { Debug::log(ERR, "Error in focusMonitor: invalid arg 1"); @@ -681,9 +680,9 @@ void CKeybindManager::focusMonitor(std::string arg) { return; } } else { - for (auto& m : g_pCompositor->m_lMonitors) { - if (m.szName == arg) { - changeworkspace(std::to_string(m.activeWorkspace)); + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->szName == arg) { + changeworkspace(std::to_string(m->activeWorkspace)); return; } } @@ -743,11 +742,11 @@ void CKeybindManager::workspaceOpt(std::string args) { PWORKSPACE->m_bDefaultPseudo = !PWORKSPACE->m_bDefaultPseudo; // apply - for (auto& w : g_pCompositor->m_lWindows) { - if (!w.m_bIsMapped || w.m_iWorkspaceID != PWORKSPACE->m_iID) + for (auto& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID) continue; - w.m_bIsPseudotiled = PWORKSPACE->m_bDefaultPseudo; + w->m_bIsPseudotiled = PWORKSPACE->m_bDefaultPseudo; } } else if (args == "allfloat") { PWORKSPACE->m_bDefaultFloating = !PWORKSPACE->m_bDefaultFloating; @@ -755,8 +754,8 @@ void CKeybindManager::workspaceOpt(std::string args) { // we make a copy because changeWindowFloatingMode might invalidate the iterator std::deque ptrs; - for (auto& w : g_pCompositor->m_lWindows) - ptrs.push_back(&w); + for (auto& w : g_pCompositor->m_vWindows) + ptrs.push_back(w.get()); for (auto& w : ptrs) { if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID) @@ -860,8 +859,8 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { bool open = false; - for (auto& m : g_pCompositor->m_lMonitors) { - if (m.specialWorkspaceOpen) { + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->specialWorkspaceOpen) { open = true; break; } @@ -873,10 +872,10 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { Debug::log(LOG, "Toggling special workspace to open"); if (open) { - for (auto& m : g_pCompositor->m_lMonitors) { - if (m.specialWorkspaceOpen != !open) { - m.specialWorkspaceOpen = !open; - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m.ID); + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->specialWorkspaceOpen != !open) { + m->specialWorkspaceOpen = !open; + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(false, false); } @@ -895,9 +894,9 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { } void CKeybindManager::forceRendererReload(std::string args) { - for (auto& m : g_pCompositor->m_lMonitors) { - auto rule = g_pConfigManager->getMonitorRuleFor(m.szName); - g_pHyprRenderer->applyMonitorRule(&m, &rule, true); + for (auto& m : g_pCompositor->m_vMonitors) { + auto rule = g_pConfigManager->getMonitorRuleFor(m->szName); + g_pHyprRenderer->applyMonitorRule(m.get(), &rule, true); } } @@ -1013,22 +1012,22 @@ void CKeybindManager::circleNext(std::string) { void CKeybindManager::focusWindowByClass(std::string clazz) { std::regex classCheck(clazz); - for (auto& w : g_pCompositor->m_lWindows) { - if (!w.m_bIsMapped || w.m_bHidden) + for (auto& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped || w->m_bHidden) continue; - const auto windowClass = g_pXWaylandManager->getAppIDClass(&w); + const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get()); if (!std::regex_search(windowClass, classCheck)) continue; - Debug::log(LOG, "Focusing to window name: %s", w.m_szTitle.c_str()); + Debug::log(LOG, "Focusing to window name: %s", w->m_szTitle.c_str()); - changeworkspace(std::to_string(w.m_iWorkspaceID)); + changeworkspace(std::to_string(w->m_iWorkspaceID)); - g_pCompositor->focusWindow(&w); + g_pCompositor->focusWindow(w.get()); - const auto MIDPOINT = w.m_vRealPosition.goalv() + w.m_vRealSize.goalv() / 2.f; + const auto MIDPOINT = w->m_vRealPosition.goalv() + w->m_vRealSize.goalv() / 2.f; wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 93a590d8..e9d77489 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -123,10 +123,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { surfacePos = pFoundWindow->m_vRealPosition.vec(); // only check floating because tiled cant be over fullscreen - for (auto w = g_pCompositor->m_lWindows.rbegin(); w != g_pCompositor->m_lWindows.rend(); w++) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (((w->m_bIsFloating && w->m_bIsMapped && w->m_bCreatedOverFullscreen) || (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && PMONITOR->specialWorkspaceOpen)) && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y) && g_pCompositor->isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bHidden) { - pFoundWindow = &(*w); + for (auto w = g_pCompositor->m_vWindows.rbegin(); w != g_pCompositor->m_vWindows.rend(); w++) { + wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y}; + if ((((*w)->m_bIsFloating && (*w)->m_bIsMapped && (*w)->m_bCreatedOverFullscreen) || ((*w)->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && PMONITOR->specialWorkspaceOpen)) && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y) && g_pCompositor->isWorkspaceVisible((*w)->m_iWorkspaceID) && !(*w)->m_bHidden) { + pFoundWindow = (*w).get(); if (!pFoundWindow->m_bIsX11) { foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 731674d6..4eaf988d 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -74,11 +74,11 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow) { if (g_pCompositor->isWorkspaceVisible(pWindow->m_iWorkspaceID)) return true; - for (auto& m : g_pCompositor->m_lMonitors) { - if (PWORKSPACE && PWORKSPACE->m_iMonitorID == m.ID && (PWORKSPACE->m_vRenderOffset.isBeingAnimated() || PWORKSPACE->m_fAlpha.isBeingAnimated())) + for (auto& m : g_pCompositor->m_vMonitors) { + if (PWORKSPACE && PWORKSPACE->m_iMonitorID == m->ID && (PWORKSPACE->m_vRenderOffset.isBeingAnimated() || PWORKSPACE->m_fAlpha.isBeingAnimated())) return true; - if (m.specialWorkspaceOpen && pWindow->m_iWorkspaceID == SPECIAL_WORKSPACE_ID) + if (m->specialWorkspaceOpen && pWindow->m_iWorkspaceID == SPECIAL_WORKSPACE_ID) return true; } @@ -88,37 +88,37 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow) { void CHyprRenderer::renderWorkspaceWithFullscreenWindow(SMonitor* pMonitor, CWorkspace* pWorkspace, timespec* time) { CWindow* pWorkspaceWindow = nullptr; - for (auto& w : g_pCompositor->m_lWindows) { - if (w.m_iWorkspaceID != pWorkspace->m_iID || !w.m_bIsFullscreen) + for (auto& w : g_pCompositor->m_vWindows) { + if (w->m_iWorkspaceID != pWorkspace->m_iID || !w->m_bIsFullscreen) continue; // found it! - renderWindow(&w, pMonitor, time, pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL); + renderWindow(w.get(), pMonitor, time, pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL); - pWorkspaceWindow = &w; + pWorkspaceWindow = w.get(); } // then render windows over fullscreen - for (auto& w : g_pCompositor->m_lWindows) { - if (w.m_iWorkspaceID != pWorkspaceWindow->m_iWorkspaceID || !w.m_bCreatedOverFullscreen || !w.m_bIsMapped) + for (auto& w : g_pCompositor->m_vWindows) { + if (w->m_iWorkspaceID != pWorkspaceWindow->m_iWorkspaceID || !w->m_bCreatedOverFullscreen || !w->m_bIsMapped) continue; - renderWindow(&w, pMonitor, time, true); + renderWindow(w.get(), pMonitor, time, true); } // and then special windows - for (auto& w : g_pCompositor->m_lWindows) { - if (!g_pCompositor->windowValidMapped(&w) && !w.m_bFadingOut) + for (auto& w : g_pCompositor->m_vWindows) { + if (!g_pCompositor->windowValidMapped(w.get()) && !w->m_bFadingOut) continue; - if (w.m_iWorkspaceID != SPECIAL_WORKSPACE_ID) + if (w->m_iWorkspaceID != SPECIAL_WORKSPACE_ID) continue; - if (!shouldRenderWindow(&w, pMonitor)) + if (!shouldRenderWindow(w.get(), pMonitor)) continue; // render the bad boy - renderWindow(&w, pMonitor, time, true); + renderWindow(w.get(), pMonitor, time, true); } // and the overlay layers @@ -136,7 +136,7 @@ void CHyprRenderer::renderWorkspaceWithFullscreenWindow(SMonitor* pMonitor, CWor renderDragIcon(pMonitor, time); // if correct monitor draw hyprerror - if (pMonitor == &g_pCompositor->m_lMonitors.front()) + if (pMonitor == g_pCompositor->m_vMonitors.front().get()) g_pHyprError->draw(); } @@ -244,54 +244,54 @@ void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) { } // Non-floating - for (auto& w : g_pCompositor->m_lWindows) { - if (!g_pCompositor->windowValidMapped(&w) && !w.m_bFadingOut) + for (auto& w : g_pCompositor->m_vWindows) { + if (w->m_bHidden && !w->m_bIsMapped && !w->m_bFadingOut) continue; - if (w.m_bIsFloating) + if (w->m_bIsFloating) continue; // floating are in the second pass - if (w.m_iWorkspaceID == SPECIAL_WORKSPACE_ID) + if (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID) continue; // special are in the third pass - if (!shouldRenderWindow(&w, PMONITOR)) + if (!shouldRenderWindow(w.get(), PMONITOR)) continue; // render the bad boy - renderWindow(&w, PMONITOR, time, true); + renderWindow(w.get(), PMONITOR, time, true); } // floating on top - for (auto& w : g_pCompositor->m_lWindows) { - if (!g_pCompositor->windowValidMapped(&w) && !w.m_bFadingOut) + for (auto& w : g_pCompositor->m_vWindows) { + if (w->m_bHidden && !w->m_bIsMapped && !w->m_bFadingOut) continue; - if (!w.m_bIsFloating) + if (!w->m_bIsFloating) continue; - if (w.m_iWorkspaceID == SPECIAL_WORKSPACE_ID) + if (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID) continue; - if (!shouldRenderWindow(&w, PMONITOR)) + if (!shouldRenderWindow(w.get(), PMONITOR)) continue; // render the bad boy - renderWindow(&w, PMONITOR, time, true); + renderWindow(w.get(), PMONITOR, time, true); } // and then special - for (auto& w : g_pCompositor->m_lWindows) { - if (!g_pCompositor->windowValidMapped(&w) && !w.m_bFadingOut) + for (auto& w : g_pCompositor->m_vWindows) { + if (w->m_bHidden && !w->m_bIsMapped && !w->m_bFadingOut) continue; - if (w.m_iWorkspaceID != SPECIAL_WORKSPACE_ID) + if (w->m_iWorkspaceID != SPECIAL_WORKSPACE_ID) continue; - if (!shouldRenderWindow(&w, PMONITOR)) + if (!shouldRenderWindow(w.get(), PMONITOR)) continue; // render the bad boy - renderWindow(&w, PMONITOR, time, true); + renderWindow(w.get(), PMONITOR, time, true); } // Render surfaces above windows for monitor @@ -558,12 +558,12 @@ void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y) { pixman_region32_translate(&damageBox, x, y); - for (auto& m : g_pCompositor->m_lMonitors) { + for (auto& m : g_pCompositor->m_vMonitors) { double lx = 0, ly = 0; - wlr_output_layout_output_coords(g_pCompositor->m_sWLROutputLayout, m.output, &lx, &ly); + wlr_output_layout_output_coords(g_pCompositor->m_sWLROutputLayout, m->output, &lx, &ly); pixman_region32_translate(&damageBox, lx, ly); - wlr_region_scale(&damageBox, &damageBox, m.scale); - wlr_output_damage_add(m.damage, &damageBox); + wlr_region_scale(&damageBox, &damageBox, m->scale); + wlr_output_damage_add(m->damage, &damageBox); pixman_region32_translate(&damageBox, -lx, -ly); } @@ -577,10 +577,10 @@ void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y) { void CHyprRenderer::damageWindow(CWindow* pWindow) { wlr_box damageBox = pWindow->getFullWindowBoundingBox(); - for (auto& m : g_pCompositor->m_lMonitors) { - wlr_box fixedDamageBox = {damageBox.x - m.vecPosition.x, damageBox.y - m.vecPosition.y, damageBox.width, damageBox.height}; - scaleBox(&fixedDamageBox, m.scale); - wlr_output_damage_add_box(m.damage, &fixedDamageBox); + for (auto& m : g_pCompositor->m_vMonitors) { + wlr_box fixedDamageBox = {damageBox.x - m->vecPosition.x, damageBox.y - m->vecPosition.y, damageBox.width, damageBox.height}; + scaleBox(&fixedDamageBox, m->scale); + wlr_output_damage_add_box(m->damage, &fixedDamageBox); } static auto* const PLOGDAMAGE = &g_pConfigManager->getConfigValuePtr("debug:log_damage")->intValue; @@ -600,10 +600,10 @@ void CHyprRenderer::damageMonitor(SMonitor* pMonitor) { } void CHyprRenderer::damageBox(wlr_box* pBox) { - for (auto& m : g_pCompositor->m_lMonitors) { - wlr_box damageBox = {pBox->x - m.vecPosition.x, pBox->y - m.vecPosition.y, pBox->width, pBox->height}; - scaleBox(&damageBox, m.scale); - wlr_output_damage_add_box(m.damage, &damageBox); + for (auto& m : g_pCompositor->m_vMonitors) { + wlr_box damageBox = {pBox->x - m->vecPosition.x, pBox->y - m->vecPosition.y, pBox->width, pBox->height}; + scaleBox(&damageBox, m->scale); + wlr_output_damage_add_box(m->damage, &damageBox); } static auto *const PLOGDAMAGE = &g_pConfigManager->getConfigValuePtr("debug:log_damage")->intValue; @@ -768,8 +768,8 @@ void CHyprRenderer::ensureCursorRenderingMode() { Debug::log(LOG, "Hiding the cursor (timeout)"); - for (auto& m : g_pCompositor->m_lMonitors) - g_pHyprRenderer->damageMonitor(&m); // TODO: maybe just damage the cursor area? + for (auto& m : g_pCompositor->m_vMonitors) + g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? } else if (*PCURSORTIMEOUT > PASSEDCURSORSECONDS && !m_bHasARenderedCursor) { m_bHasARenderedCursor = true; @@ -778,8 +778,8 @@ void CHyprRenderer::ensureCursorRenderingMode() { Debug::log(LOG, "Showing the cursor (timeout)"); - for (auto& m : g_pCompositor->m_lMonitors) - g_pHyprRenderer->damageMonitor(&m); // TODO: maybe just damage the cursor area? + for (auto& m : g_pCompositor->m_vMonitors) + g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? } } else { m_bHasARenderedCursor = true;