diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 49cfb5610..0d9c2f8c8 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -41,7 +41,7 @@ #include "protocols/ColorManagement.hpp" #include "protocols/core/Compositor.hpp" #include "protocols/core/Subcompositor.hpp" -#include "desktop/LayerSurface.hpp" +#include "desktop/view/LayerSurface.hpp" #include "render/Renderer.hpp" #include "xwayland/XWayland.hpp" #include "helpers/ByteOperations.hpp" @@ -884,7 +884,7 @@ void CCompositor::removeWindowFromVectorSafe(PHLWINDOW pWindow) { if (!pWindow->m_fadingOut) { EMIT_HOOK_EVENT("destroyWindow", pWindow); - std::erase_if(m_windows, [&](SP& el) { return el == pWindow; }); + std::erase_if(m_windows, [&](SP& el) { return el == pWindow; }); std::erase_if(m_windowsFadingOut, [&](PHLWINDOWREF el) { return el.lock() == pWindow; }); } } @@ -901,14 +901,14 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper static auto PSPECIALFALLTHRU = CConfigValue("input:special_fallthrough"); static auto PMODALPARENTBLOCKING = CConfigValue("general:modal_parent_blocking"); const auto BORDER_GRAB_AREA = *PRESIZEONBORDER ? *PBORDERSIZE + *PBORDERGRABEXTEND : 0; - const bool ONLY_PRIORITY = properties & FOCUS_PRIORITY; + const bool ONLY_PRIORITY = properties & Desktop::View::FOCUS_PRIORITY; const auto isShadowedByModal = [](PHLWINDOW w) -> bool { return *PMODALPARENTBLOCKING && w->m_xdgSurface && w->m_xdgSurface->m_toplevel && w->m_xdgSurface->m_toplevel->anyChildModal(); }; // pinned windows on top of floating regardless - if (properties & ALLOW_FLOATING) { + if (properties & Desktop::View::ALLOW_FLOATING) { for (auto const& w : m_windows | std::views::reverse) { if (ONLY_PRIORITY && !w->priorityFocus()) continue; @@ -980,20 +980,20 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper return nullptr; }; - if (properties & ALLOW_FLOATING) { + if (properties & Desktop::View::ALLOW_FLOATING) { // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. auto found = floating(true); if (found) return found; } - if (properties & FLOATING_ONLY) + if (properties & Desktop::View::FLOATING_ONLY) return floating(false); const WORKSPACEID WSPID = special ? PMONITOR->activeSpecialWorkspaceID() : PMONITOR->activeWorkspaceID(); const auto PWORKSPACE = getWorkspaceByID(WSPID); - if (PWORKSPACE->m_hasFullscreenWindow && !(properties & SKIP_FULLSCREEN_PRIORITY) && !ONLY_PRIORITY) + if (PWORKSPACE->m_hasFullscreenWindow && !(properties & Desktop::View::SKIP_FULLSCREEN_PRIORITY) && !ONLY_PRIORITY) return PWORKSPACE->getFullscreenWindow(); auto found = floating(false); @@ -1030,7 +1030,7 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper if (!w->m_isFloating && w->m_isMapped && w->workspaceID() == WSPID && !w->isHidden() && !w->m_X11ShouldntFocus && !w->m_ruleApplicator->noFocus().valueOrDefault() && w != pIgnoreWindow && !isShadowedByModal(w)) { - CBox box = (properties & USE_PROP_TILED) ? w->getWindowBoxUnified(properties) : CBox{w->m_position, w->m_size}; + CBox box = (properties & Desktop::View::USE_PROP_TILED) ? w->getWindowBoxUnified(properties) : CBox{w->m_position, w->m_size}; if (box.containsPoint(pos)) return w; } @@ -1066,10 +1066,10 @@ SP CCompositor::vectorWindowToSurface(const Vector2D& pos, P if (PPOPUP) { const auto OFF = PPOPUP->coordsRelativeToParent(); sl = pos - pWindow->m_realPosition->goal() - OFF; - return PPOPUP->m_wlSurface->resource(); + return PPOPUP->wlSurface()->resource(); } - auto [surf, local] = pWindow->m_wlSurface->resource()->at(pos - pWindow->m_realPosition->goal(), true); + auto [surf, local] = pWindow->wlSurface()->resource()->at(pos - pWindow->m_realPosition->goal(), true); if (surf) { sl = local; return surf; @@ -1091,7 +1091,7 @@ Vector2D CCompositor::vectorToSurfaceLocal(const Vector2D& vec, PHLWINDOW pWindo std::tuple, Vector2D> iterData = {pSurface, {-1337, -1337}}; - pWindow->m_wlSurface->resource()->breadthfirst( + pWindow->wlSurface()->resource()->breadthfirst( [](SP surf, const Vector2D& offset, void* data) { const auto PDATA = sc, Vector2D>*>(data); if (surf == std::get<0>(*PDATA)) @@ -1130,7 +1130,7 @@ PHLMONITOR CCompositor::getRealMonitorFromOutput(SP out) { SP CCompositor::vectorToLayerPopupSurface(const Vector2D& pos, PHLMONITOR monitor, Vector2D* sCoords, PHLLS* ppLayerSurfaceFound) { for (auto const& lsl : monitor->m_layerSurfaceLayers | std::views::reverse) { for (auto const& ls : lsl | std::views::reverse) { - if (!ls->m_mapped || ls->m_fadingOut || !ls->m_layerSurface || (ls->m_layerSurface && !ls->m_layerSurface->m_mapped) || ls->m_alpha->value() == 0.f) + if (!ls->visible() || ls->m_fadingOut) continue; auto SURFACEAT = ls->m_popupHead->at(pos, true); @@ -1138,7 +1138,7 @@ SP CCompositor::vectorToLayerPopupSurface(const Vector2D& po if (SURFACEAT) { *ppLayerSurfaceFound = ls.lock(); *sCoords = pos - SURFACEAT->coordsGlobal(); - return SURFACEAT->m_wlSurface->resource(); + return SURFACEAT->wlSurface()->resource(); } } } @@ -1150,8 +1150,7 @@ SP CCompositor::vectorToLayerSurface(const Vector2D& pos, st bool aboveLockscreen) { for (auto const& ls : *layerSurfaces | std::views::reverse) { - if (!ls->m_mapped || ls->m_fadingOut || !ls->m_layerSurface || (ls->m_layerSurface && !ls->m_layerSurface->m_surface->m_mapped) || ls->m_alpha->value() == 0.f || - (aboveLockscreen && ls->m_ruleApplicator->aboveLock().valueOrDefault() != 2)) + if (!ls->visible() || ls->m_fadingOut || (aboveLockscreen && ls->m_ruleApplicator->aboveLock().valueOrDefault() != 2)) continue; auto [surf, local] = ls->m_layerSurface->m_surface->at(pos - ls->m_geometry.pos(), true); @@ -1175,7 +1174,12 @@ PHLWINDOW CCompositor::getWindowFromSurface(SP pSurface) { if (!pSurface || !pSurface->m_hlSurface) return nullptr; - return pSurface->m_hlSurface->getWindow(); + const auto VIEW = pSurface->m_hlSurface->view(); + + if (VIEW->type() != Desktop::View::VIEW_TYPE_WINDOW) + return nullptr; + + return dynamicPointerCast(VIEW); } PHLWINDOW CCompositor::getWindowFromHandle(uint32_t handle) { @@ -1213,7 +1217,7 @@ bool CCompositor::isWindowActive(PHLWINDOW pWindow) { if (!pWindow->m_isMapped) return false; - const auto PSURFACE = pWindow->m_wlSurface->resource(); + const auto PSURFACE = pWindow->wlSurface()->resource(); return PSURFACE == Desktop::focusState()->surface() || pWindow == Desktop::focusState()->window(); } @@ -1819,7 +1823,9 @@ void CCompositor::swapActiveWorkspaces(PHLMONITOR pMonitorA, PHLMONITOR pMonitor if (pMonitorA->m_id == Desktop::focusState()->monitor()->m_id || pMonitorB->m_id == Desktop::focusState()->monitor()->m_id) { const auto LASTWIN = pMonitorA->m_id == Desktop::focusState()->monitor()->m_id ? PWORKSPACEB->getLastFocusedWindow() : PWORKSPACEA->getLastFocusedWindow(); Desktop::focusState()->fullWindowFocus( - LASTWIN ? LASTWIN : (g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING))); + LASTWIN ? LASTWIN : + (g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), + Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING))); const auto PNEWWORKSPACE = pMonitorA->m_id == Desktop::focusState()->monitor()->m_id ? PWORKSPACEB : PWORKSPACEA; g_pEventManager->postEvent(SHyprIPCEvent{.event = "workspace", .data = PNEWWORKSPACE->m_name}); @@ -2069,19 +2075,19 @@ void CCompositor::changeWindowFullscreenModeClient(const PHLWINDOW PWINDOW, cons // TODO: move fs functions to Desktop:: void CCompositor::setWindowFullscreenInternal(const PHLWINDOW PWINDOW, const eFullscreenMode MODE) { if (PWINDOW->m_ruleApplicator->syncFullscreen().valueOrDefault()) - setWindowFullscreenState(PWINDOW, SFullscreenState{.internal = MODE, .client = MODE}); + setWindowFullscreenState(PWINDOW, Desktop::View::SFullscreenState{.internal = MODE, .client = MODE}); else - setWindowFullscreenState(PWINDOW, SFullscreenState{.internal = MODE, .client = PWINDOW->m_fullscreenState.client}); + setWindowFullscreenState(PWINDOW, Desktop::View::SFullscreenState{.internal = MODE, .client = PWINDOW->m_fullscreenState.client}); } void CCompositor::setWindowFullscreenClient(const PHLWINDOW PWINDOW, const eFullscreenMode MODE) { if (PWINDOW->m_ruleApplicator->syncFullscreen().valueOrDefault()) - setWindowFullscreenState(PWINDOW, SFullscreenState{.internal = MODE, .client = MODE}); + setWindowFullscreenState(PWINDOW, Desktop::View::SFullscreenState{.internal = MODE, .client = MODE}); else - setWindowFullscreenState(PWINDOW, SFullscreenState{.internal = PWINDOW->m_fullscreenState.internal, .client = MODE}); + setWindowFullscreenState(PWINDOW, Desktop::View::SFullscreenState{.internal = PWINDOW->m_fullscreenState.internal, .client = MODE}); } -void CCompositor::setWindowFullscreenState(const PHLWINDOW PWINDOW, SFullscreenState state) { +void CCompositor::setWindowFullscreenState(const PHLWINDOW PWINDOW, Desktop::View::SFullscreenState state) { static auto PDIRECTSCANOUT = CConfigValue("render:direct_scanout"); static auto PALLOWPINFULLSCREEN = CConfigValue("binds:allow_pin_fullscreen"); @@ -2341,12 +2347,12 @@ PHLLS CCompositor::getLayerSurfaceFromSurface(SP pSurface) { std::pair, bool> result = {pSurface, false}; for (auto const& ls : m_layers) { - if (ls->m_layerSurface && ls->m_layerSurface->m_surface == pSurface) - return ls; - - if (!ls->m_layerSurface || !ls->m_mapped) + if (!ls->visible() || ls->m_fadingOut) continue; + if (ls->m_layerSurface->m_surface == pSurface) + return ls; + ls->m_layerSurface->m_surface->breadthfirst( [&result](SP surf, const Vector2D& offset, void* data) { if (surf == result.first) { @@ -2831,7 +2837,7 @@ void CCompositor::setPreferredScaleForSurface(SP pSurface, d PROTO::fractional->sendScale(pSurface, scale); pSurface->sendPreferredScale(std::ceil(scale)); - const auto PSURFACE = CWLSurface::fromResource(pSurface); + const auto PSURFACE = Desktop::View::CWLSurface::fromResource(pSurface); if (!PSURFACE) { Debug::log(WARN, "Orphaned CWLSurfaceResource {:x} in setPreferredScaleForSurface", rc(pSurface.get())); return; @@ -2844,7 +2850,7 @@ void CCompositor::setPreferredScaleForSurface(SP pSurface, d void CCompositor::setPreferredTransformForSurface(SP pSurface, wl_output_transform transform) { pSurface->sendPreferredTransform(transform); - const auto PSURFACE = CWLSurface::fromResource(pSurface); + const auto PSURFACE = Desktop::View::CWLSurface::fromResource(pSurface); if (!PSURFACE) { Debug::log(WARN, "Orphaned CWLSurfaceResource {:x} in setPreferredTransformForSurface", rc(pSurface.get())); return; diff --git a/src/Compositor.hpp b/src/Compositor.hpp index af06059fd..ca65a12d1 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -7,7 +7,7 @@ #include "managers/XWaylandManager.hpp" #include "managers/KeybindManager.hpp" #include "managers/SessionLockManager.hpp" -#include "desktop/Window.hpp" +#include "desktop/view/Window.hpp" #include "protocols/types/ColorManagement.hpp" #include @@ -56,6 +56,7 @@ class CCompositor { std::vector m_layers; std::vector m_windowsFadingOut; std::vector m_surfacesFadingOut; + std::vector> m_otherViews; std::unordered_map m_monitorIDMap; std::unordered_map m_seenMonitorWorkspaceMap; // map of seen monitor names to workspace IDs @@ -130,7 +131,7 @@ class CCompositor { bool workspaceIDOutOfBounds(const WORKSPACEID&); void setWindowFullscreenInternal(const PHLWINDOW PWINDOW, const eFullscreenMode MODE); void setWindowFullscreenClient(const PHLWINDOW PWINDOW, const eFullscreenMode MODE); - void setWindowFullscreenState(const PHLWINDOW PWINDOW, const SFullscreenState state); + void setWindowFullscreenState(const PHLWINDOW PWINDOW, const Desktop::View::SFullscreenState state); void changeWindowFullscreenModeClient(const PHLWINDOW PWINDOW, const eFullscreenMode MODE, const bool ON); PHLWINDOW getX11Parent(PHLWINDOW); void scheduleFrameForMonitor(PHLMONITOR, Aquamarine::IOutput::scheduleFrameReason reason = Aquamarine::IOutput::AQ_SCHEDULE_CLIENT_UNKNOWN); diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index bde4ebc05..f8acb4738 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -12,7 +12,7 @@ #include "../xwayland/XWayland.hpp" #include "../protocols/OutputManagement.hpp" #include "../managers/animation/AnimationManager.hpp" -#include "../desktop/LayerSurface.hpp" +#include "../desktop/view/LayerSurface.hpp" #include "../desktop/rule/Engine.hpp" #include "../desktop/rule/windowRule/WindowRule.hpp" #include "../desktop/rule/layerRule/LayerRule.hpp" diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 1055e5f28..83fef7b0b 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -12,7 +12,7 @@ #include #include #include "../helpers/Monitor.hpp" -#include "../desktop/Window.hpp" +#include "../desktop/view/Window.hpp" #include "ConfigDataValues.hpp" #include "../SharedDefs.hpp" diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 53bac0d8b..ad7f592c5 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -43,7 +43,7 @@ using namespace Hyprutils::OS; #include "debug/RollingLogFollow.hpp" #include "config/ConfigManager.hpp" #include "helpers/MiscFunctions.hpp" -#include "../desktop/LayerSurface.hpp" +#include "../desktop/view/LayerSurface.hpp" #include "../desktop/rule/Engine.hpp" #include "../desktop/state/FocusState.hpp" #include "../version.h" diff --git a/src/debug/HyprCtl.hpp b/src/debug/HyprCtl.hpp index d4f7aa149..a6fa37217 100644 --- a/src/debug/HyprCtl.hpp +++ b/src/debug/HyprCtl.hpp @@ -3,7 +3,7 @@ #include #include "../helpers/MiscFunctions.hpp" #include "../helpers/defer/Promise.hpp" -#include "../desktop/Window.hpp" +#include "../desktop/view/Window.hpp" #include #include #include diff --git a/src/desktop/DesktopTypes.hpp b/src/desktop/DesktopTypes.hpp index f724c7b96..b52f17cdd 100644 --- a/src/desktop/DesktopTypes.hpp +++ b/src/desktop/DesktopTypes.hpp @@ -1,26 +1,30 @@ #pragma once #include "../helpers/memory/Memory.hpp" + class CWorkspace; -class CWindow; -class CLayerSurface; class CMonitor; +namespace Desktop::View { + class CWindow; + class CLayerSurface; +} + /* Shared pointer to a workspace */ using PHLWORKSPACE = SP; /* Weak pointer to a workspace */ using PHLWORKSPACEREF = WP; /* Shared pointer to a window */ -using PHLWINDOW = SP; +using PHLWINDOW = SP; /* Weak pointer to a window */ -using PHLWINDOWREF = WP; +using PHLWINDOWREF = WP; /* Shared pointer to a layer surface */ -using PHLLS = SP; +using PHLLS = SP; /* Weak pointer to a layer surface */ -using PHLLSREF = WP; +using PHLLSREF = WP; /* Shared pointer to a monitor */ using PHLMONITOR = SP; /* Weak pointer to a monitor */ -using PHLMONITORREF = WP; +using PHLMONITORREF = WP; \ No newline at end of file diff --git a/src/desktop/LayerSurface.hpp b/src/desktop/LayerSurface.hpp deleted file mode 100644 index 5676e4d21..000000000 --- a/src/desktop/LayerSurface.hpp +++ /dev/null @@ -1,95 +0,0 @@ -#pragma once - -#include -#include "../defines.hpp" -#include "WLSurface.hpp" -#include "rule/layerRule/LayerRuleApplicator.hpp" -#include "../helpers/AnimatedVariable.hpp" - -class CLayerShellResource; - -class CLayerSurface { - public: - static PHLLS create(SP); - - private: - CLayerSurface(SP); - - public: - ~CLayerSurface(); - - bool isFadedOut(); - int popupsCount(); - - PHLANIMVAR m_realPosition; - PHLANIMVAR m_realSize; - PHLANIMVAR m_alpha; - - WP m_layerSurface; - - // the header providing the enum type cannot be imported here - int m_interactivity = 0; - - SP m_surface; - - bool m_mapped = false; - uint32_t m_layer = 0; - - PHLMONITORREF m_monitor; - - bool m_fadingOut = false; - bool m_readyToDelete = false; - bool m_noProcess = false; - - UP m_ruleApplicator; - - PHLLSREF m_self; - - CBox m_geometry = {0, 0, 0, 0}; - Vector2D m_position; - std::string m_namespace = ""; - UP m_popupHead; - - pid_t getPID(); - - void onDestroy(); - void onMap(); - void onUnmap(); - void onCommit(); - MONITORID monitorID(); - - private: - struct { - CHyprSignalListener destroy; - CHyprSignalListener map; - CHyprSignalListener unmap; - CHyprSignalListener commit; - } m_listeners; - - void registerCallbacks(); - - // For the list lookup - bool operator==(const CLayerSurface& rhs) const { - return m_layerSurface == rhs.m_layerSurface && m_monitor == rhs.m_monitor; - } -}; - -inline bool valid(PHLLS l) { - return l; -} - -inline bool valid(PHLLSREF l) { - return l; -} - -inline bool validMapped(PHLLS l) { - if (!valid(l)) - return false; - return l->m_mapped; -} - -inline bool validMapped(PHLLSREF l) { - if (!valid(l)) - return false; - return l->m_mapped; -} diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp deleted file mode 100644 index 964b36b6c..000000000 --- a/src/desktop/Popup.hpp +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include -#include "Subsurface.hpp" -#include "../helpers/signal/Signal.hpp" -#include "../helpers/memory/Memory.hpp" -#include "../helpers/AnimatedVariable.hpp" - -class CXDGPopupResource; - -class CPopup { - public: - // dummy head nodes - static UP create(PHLWINDOW pOwner); - static UP create(PHLLS pOwner); - - // real nodes - static UP create(SP popup, WP pOwner); - - ~CPopup(); - - SP getT1Owner(); - Vector2D coordsRelativeToParent(); - Vector2D coordsGlobal(); - PHLMONITOR getMonitor(); - - Vector2D size(); - - void onNewPopup(SP popup); - void onDestroy(); - void onMap(); - void onUnmap(); - void onCommit(bool ignoreSiblings = false); - void onReposition(); - - void recheckTree(); - - bool visible(); - bool inert() const; - - // will also loop over this node - void breadthfirst(std::function, void*)> fn, void* data); - WP at(const Vector2D& globalCoords, bool allowsInput = false); - - // - SP m_wlSurface; - WP m_self; - bool m_mapped = false; - - // fade in-out - PHLANIMVAR m_alpha; - bool m_fadingOut = false; - - private: - CPopup() = default; - - // T1 owners, each popup has to have one of these - PHLWINDOWREF m_windowOwner; - PHLLSREF m_layerOwner; - - // T2 owners - WP m_parent; - - WP m_resource; - - Vector2D m_lastSize = {}; - Vector2D m_lastPos = {}; - - bool m_requestedReposition = false; - - bool m_inert = false; - - // - std::vector> m_children; - UP m_subsurfaceHead; - - struct { - CHyprSignalListener newPopup; - CHyprSignalListener destroy; - CHyprSignalListener map; - CHyprSignalListener unmap; - CHyprSignalListener commit; - CHyprSignalListener dismissed; - CHyprSignalListener reposition; - } m_listeners; - - void initAllSignals(); - void reposition(); - void recheckChildrenRecursive(); - void sendScale(); - void fullyDestroy(); - - Vector2D localToGlobal(const Vector2D& rel); - Vector2D t1ParentCoords(); - static void bfHelper(std::vector> const& nodes, std::function, void*)> fn, void* data); -}; diff --git a/src/desktop/Subsurface.hpp b/src/desktop/Subsurface.hpp deleted file mode 100644 index 7c42dad9d..000000000 --- a/src/desktop/Subsurface.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -#include "../defines.hpp" -#include -#include "WLSurface.hpp" - -class CPopup; -class CWLSubsurfaceResource; - -class CSubsurface { - public: - // root dummy nodes - static UP create(PHLWINDOW pOwner); - static UP create(WP pOwner); - - // real nodes - static UP create(SP pSubsurface, PHLWINDOW pOwner); - static UP create(SP pSubsurface, WP pOwner); - - ~CSubsurface() = default; - - Vector2D coordsRelativeToParent(); - Vector2D coordsGlobal(); - - Vector2D size(); - - void onCommit(); - void onDestroy(); - void onNewSubsurface(SP pSubsurface); - void onMap(); - void onUnmap(); - - bool visible(); - - void recheckDamageForSubsurfaces(); - - WP m_self; - - private: - CSubsurface() = default; - - struct { - CHyprSignalListener destroySubsurface; - CHyprSignalListener commitSubsurface; - CHyprSignalListener mapSubsurface; - CHyprSignalListener unmapSubsurface; - CHyprSignalListener newSubsurface; - } m_listeners; - - WP m_subsurface; - SP m_wlSurface; - Vector2D m_lastSize = {}; - Vector2D m_lastPosition = {}; - - // if nullptr, means it's a dummy node - WP m_parent; - - PHLWINDOWREF m_windowParent; - WP m_popupParent; - - std::vector> m_children; - - bool m_inert = false; - - void initSignals(); - void initExistingSubsurfaces(SP pSurface); - void checkSiblingDamage(); - void damageLastArea(); -}; diff --git a/src/desktop/WLSurface.hpp b/src/desktop/WLSurface.hpp deleted file mode 100644 index 4d26d5092..000000000 --- a/src/desktop/WLSurface.hpp +++ /dev/null @@ -1,124 +0,0 @@ -#pragma once - -#include "../defines.hpp" -#include "../helpers/math/Math.hpp" -#include "../helpers/signal/Signal.hpp" - -class CSubsurface; -class CPopup; -class CPointerConstraint; -class CWLSurfaceResource; - -class CWLSurface { - public: - static SP create() { - auto p = SP(new CWLSurface); - p->m_self = p; - return p; - } - ~CWLSurface(); - - // anonymous surfaces are non-desktop components, e.g. a cursor surface or a DnD - void assign(SP pSurface); - void assign(SP pSurface, PHLWINDOW pOwner); - void assign(SP pSurface, PHLLS pOwner); - void assign(SP pSurface, CSubsurface* pOwner); - void assign(SP pSurface, CPopup* pOwner); - void unassign(); - - CWLSurface(const CWLSurface&) = delete; - CWLSurface(CWLSurface&&) = delete; - CWLSurface& operator=(const CWLSurface&) = delete; - CWLSurface& operator=(CWLSurface&&) = delete; - - SP resource() const; - bool exists() const; - bool small() const; // means surface is smaller than the requested size - Vector2D correctSmallVec() const; // returns a corrective vector for small() surfaces - Vector2D correctSmallVecBuf() const; // returns a corrective vector for small() surfaces, in BL coords - Vector2D getViewporterCorrectedSize() const; - CRegion computeDamage() const; // logical coordinates. May be wrong if the surface is unassigned - bool visible(); - bool keyboardFocusable() const; - - // getters for owners. - PHLWINDOW getWindow() const; - PHLLS getLayer() const; - CPopup* getPopup() const; - CSubsurface* getSubsurface() const; - - // desktop components misc utils - std::optional getSurfaceBoxGlobal() const; - void appendConstraint(WP constraint); - SP constraint() const; - - // allow stretching. Useful for plugins. - bool m_fillIgnoreSmall = false; - - // track surface data and avoid dupes - float m_lastScaleFloat = 0; - int m_lastScaleInt = 0; - wl_output_transform m_lastTransform = sc(-1); - - // - CWLSurface& operator=(SP pSurface) { - destroy(); - m_resource = pSurface; - init(); - - return *this; - } - - bool operator==(const CWLSurface& other) const { - return other.resource() == resource(); - } - - bool operator==(const SP other) const { - return other == resource(); - } - - explicit operator bool() const { - return exists(); - } - - static SP fromResource(SP pSurface); - - // used by the alpha-modifier protocol - float m_alphaModifier = 1.F; - - // used by the hyprland-surface protocol - float m_overallOpacity = 1.F; - CRegion m_visibleRegion; - - struct { - CSignalT<> destroy; - } m_events; - - WP m_self; - - private: - CWLSurface() = default; - - bool m_inert = true; - - WP m_resource; - - PHLWINDOWREF m_windowOwner; - PHLLSREF m_layerOwner; - CPopup* m_popupOwner = nullptr; - CSubsurface* m_subsurfaceOwner = nullptr; - - // - WP m_constraint; - - void destroy(); - void init(); - bool desktopComponent() const; - - struct { - CHyprSignalListener destroy; - } m_listeners; - - friend class CPointerConstraint; - friend class CXxColorManagerV4; -}; diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp deleted file mode 100644 index 63492682a..000000000 --- a/src/desktop/Window.hpp +++ /dev/null @@ -1,438 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "../config/ConfigDataValues.hpp" -#include "../helpers/AnimatedVariable.hpp" -#include "../helpers/TagKeeper.hpp" -#include "../macros.hpp" -#include "../managers/XWaylandManager.hpp" -#include "../render/decorations/IHyprWindowDecoration.hpp" -#include "../render/Transformer.hpp" -#include "DesktopTypes.hpp" -#include "Popup.hpp" -#include "Subsurface.hpp" -#include "WLSurface.hpp" -#include "Workspace.hpp" -#include "rule/windowRule/WindowRuleApplicator.hpp" -#include "../protocols/types/ContentType.hpp" - -class CXDGSurfaceResource; -class CXWaylandSurface; - -enum eGroupRules : uint8_t { - // effective only during first map, except for _ALWAYS variant - GROUP_NONE = 0, - GROUP_SET = 1 << 0, // Open as new group or add to focused group - GROUP_SET_ALWAYS = 1 << 1, - GROUP_BARRED = 1 << 2, // Don't insert to focused group. - GROUP_LOCK = 1 << 3, // Lock m_sGroupData.lock - GROUP_LOCK_ALWAYS = 1 << 4, - GROUP_INVADE = 1 << 5, // Force enter a group, event if lock is engaged - GROUP_OVERRIDE = 1 << 6, // Override other rules -}; - -enum eGetWindowProperties : uint8_t { - WINDOW_ONLY = 0, - RESERVED_EXTENTS = 1 << 0, - INPUT_EXTENTS = 1 << 1, - FULL_EXTENTS = 1 << 2, - FLOATING_ONLY = 1 << 3, - ALLOW_FLOATING = 1 << 4, - USE_PROP_TILED = 1 << 5, - SKIP_FULLSCREEN_PRIORITY = 1 << 6, - FOCUS_PRIORITY = 1 << 7, -}; - -enum eSuppressEvents : uint8_t { - SUPPRESS_NONE = 0, - SUPPRESS_FULLSCREEN = 1 << 0, - SUPPRESS_MAXIMIZE = 1 << 1, - SUPPRESS_ACTIVATE = 1 << 2, - SUPPRESS_ACTIVATE_FOCUSONLY = 1 << 3, - SUPPRESS_FULLSCREEN_OUTPUT = 1 << 4, -}; - -class IWindowTransformer; - -struct SInitialWorkspaceToken { - PHLWINDOWREF primaryOwner; - std::string workspace; -}; - -struct SFullscreenState { - eFullscreenMode internal = FSMODE_NONE; - eFullscreenMode client = FSMODE_NONE; -}; - -class CWindow { - public: - static PHLWINDOW create(SP); - static PHLWINDOW create(SP); - - private: - CWindow(SP resource); - CWindow(SP surface); - - public: - ~CWindow(); - - SP m_wlSurface; - - struct { - CSignalT<> destroy; - } m_events; - - WP m_xdgSurface; - WP m_xwaylandSurface; - - // this is the position and size of the "bounding box" - Vector2D m_position = Vector2D(0, 0); - Vector2D m_size = Vector2D(0, 0); - - // this is the real position and size used to draw the thing - PHLANIMVAR m_realPosition; - PHLANIMVAR m_realSize; - - // for not spamming the protocols - Vector2D m_reportedPosition; - Vector2D m_reportedSize; - Vector2D m_pendingReportedSize; - std::optional> m_pendingSizeAck; - std::vector> m_pendingSizeAcks; - - // for restoring floating statuses - Vector2D m_lastFloatingSize; - Vector2D m_lastFloatingPosition; - - // for floating window offset in workspace animations - Vector2D m_floatingOffset = Vector2D(0, 0); - - // this is used for pseudotiling - bool m_isPseudotiled = false; - Vector2D m_pseudoSize = Vector2D(1280, 720); - - // for recovering relative cursor position - Vector2D m_relativeCursorCoordsOnLastWarp = Vector2D(-1, -1); - - bool m_firstMap = false; // for layouts - bool m_isFloating = false; - bool m_draggingTiled = false; // for dragging around tiled windows - SFullscreenState m_fullscreenState = {.internal = FSMODE_NONE, .client = FSMODE_NONE}; - std::string m_title = ""; - std::string m_class = ""; - std::string m_initialTitle = ""; - std::string m_initialClass = ""; - PHLWORKSPACE m_workspace; - PHLMONITORREF m_monitor; - - bool m_isMapped = false; - - bool m_requestsFloat = false; - - // This is for fullscreen apps - bool m_createdOverFullscreen = false; - - // XWayland stuff - bool m_isX11 = false; - bool m_X11DoesntWantBorders = false; - bool m_X11ShouldntFocus = false; - float m_X11SurfaceScaledBy = 1.f; - // - - // For nofocus - bool m_noInitialFocus = false; - - // Fullscreen and Maximize - bool m_wantsInitialFullscreen = false; - MONITORID m_wantsInitialFullscreenMonitor = MONITOR_INVALID; - - // bitfield suppressEvents - uint64_t m_suppressedEvents = SUPPRESS_NONE; - - // desktop components - UP m_subsurfaceHead; - UP m_popupHead; - - // Animated border - CGradientValueData m_realBorderColor = {0}; - CGradientValueData m_realBorderColorPrevious = {0}; - PHLANIMVAR m_borderFadeAnimationProgress; - PHLANIMVAR m_borderAngleAnimationProgress; - - // Fade in-out - PHLANIMVAR m_alpha; - bool m_fadingOut = false; - bool m_readyToDelete = false; - Vector2D m_originalClosedPos; // these will be used for calculations later on in - Vector2D m_originalClosedSize; // drawing the closing animations - SBoxExtents m_originalClosedExtents; - bool m_animatingIn = false; - - // For pinned (sticky) windows - bool m_pinned = false; - - // For preserving pinned state when fullscreening a pinned window - bool m_pinFullscreened = false; - - // urgency hint - bool m_isUrgent = false; - - // for proper cycling. While cycling we can't just move the pointers, so we need to keep track of the last cycled window. - PHLWINDOWREF m_lastCycledWindow; - - // Window decorations - // TODO: make this a SP. - std::vector> m_windowDecorations; - std::vector m_decosToRemove; - - // Special render data, rules, etc - UP m_ruleApplicator; - - // Transformers - std::vector> m_transformers; - - // for alpha - PHLANIMVAR m_activeInactiveAlpha; - PHLANIMVAR m_movingFromWorkspaceAlpha; - - // animated shadow color - PHLANIMVAR m_realShadowColor; - - // animated tint - PHLANIMVAR m_dimPercent; - - // animate moving to an invisible workspace - int m_monitorMovedFrom = -1; // -1 means not moving - PHLANIMVAR m_movingToWorkspaceAlpha; - - // swallowing - PHLWINDOWREF m_swallowed; - bool m_currentlySwallowed = false; - bool m_groupSwallowed = false; - - // for toplevel monitor events - MONITORID m_lastSurfaceMonitorID = -1; - - // initial token. Will be unregistered on workspace change or timeout of 2 minutes - std::string m_initialWorkspaceToken = ""; - - // for groups - struct SGroupData { - PHLWINDOWREF pNextWindow; // nullptr means no grouping. Self means single group. - bool head = false; - bool locked = false; // per group lock - bool deny = false; // deny window from enter a group or made a group - } m_groupData; - uint16_t m_groupRules = GROUP_NONE; - - bool m_tearingHint = false; - - // ANR - PHLANIMVAR m_notRespondingTint; - - // For the noclosefor windowrule - Time::steady_tp m_closeableSince = Time::steadyNow(); - - // For the list lookup - bool operator==(const CWindow& rhs) const { - return m_xdgSurface == rhs.m_xdgSurface && m_xwaylandSurface == rhs.m_xwaylandSurface && m_position == rhs.m_position && m_size == rhs.m_size && - m_fadingOut == rhs.m_fadingOut; - } - - // methods - CBox getFullWindowBoundingBox(); - SBoxExtents getFullWindowExtents(); - CBox getWindowBoxUnified(uint64_t props); - SBoxExtents getWindowExtentsUnified(uint64_t props); - CBox getWindowIdealBoundingBoxIgnoreReserved(); - void addWindowDeco(UP deco); - void updateWindowDecos(); - void removeWindowDeco(IHyprWindowDecoration* deco); - void uncacheWindowDecos(); - bool checkInputOnDecos(const eInputType, const Vector2D&, std::any = {}); - pid_t getPID(); - IHyprWindowDecoration* getDecorationByType(eDecorationType); - void updateToplevel(); - void updateSurfaceScaleTransformDetails(bool force = false); - void moveToWorkspace(PHLWORKSPACE); - PHLWINDOW x11TransientFor(); - void onUnmap(); - void onMap(); - void setHidden(bool hidden); - bool isHidden(); - void updateDecorationValues(); - SBoxExtents getFullWindowReservedArea(); - Vector2D middle(); - bool opaque(); - float rounding(); - float roundingPower(); - bool canBeTorn(); - void setSuspended(bool suspend); - bool visibleOnMonitor(PHLMONITOR pMonitor); - WORKSPACEID workspaceID(); - MONITORID monitorID(); - bool onSpecialWorkspace(); - void activate(bool force = false); - int surfacesCount(); - void clampWindowSize(const std::optional minSize, const std::optional maxSize); - bool isFullscreen(); - bool isEffectiveInternalFSMode(const eFullscreenMode); - int getRealBorderSize(); - float getScrollMouse(); - float getScrollTouchpad(); - bool isScrollMouseOverridden(); - bool isScrollTouchpadOverridden(); - void updateWindowData(); - void updateWindowData(const struct SWorkspaceRule&); - void onBorderAngleAnimEnd(WP pav); - bool isInCurvedCorner(double x, double y); - bool hasPopupAt(const Vector2D& pos); - int popupsCount(); - void applyGroupRules(); - void createGroup(); - void destroyGroup(); - PHLWINDOW getGroupHead(); - PHLWINDOW getGroupTail(); - PHLWINDOW getGroupCurrent(); - PHLWINDOW getGroupPrevious(); - PHLWINDOW getGroupWindowByIndex(int); - bool hasInGroup(PHLWINDOW); - int getGroupSize(); - bool canBeGroupedInto(PHLWINDOW pWindow); - void setGroupCurrent(PHLWINDOW pWindow); - void insertWindowToGroup(PHLWINDOW pWindow); - void updateGroupOutputs(); - void switchWithWindowInGroup(PHLWINDOW pWindow); - void setAnimationsToMove(); - void onWorkspaceAnimUpdate(); - void onFocusAnimUpdate(); - void onUpdateState(); - void onUpdateMeta(); - void onX11ConfigureRequest(CBox box); - void onResourceChangeX11(); - std::string fetchTitle(); - std::string fetchClass(); - void warpCursor(bool force = false); - PHLWINDOW getSwallower(); - bool isX11OverrideRedirect(); - bool isModal(); - Vector2D requestedMinSize(); - Vector2D requestedMaxSize(); - Vector2D realToReportSize(); - Vector2D realToReportPosition(); - Vector2D xwaylandSizeToReal(Vector2D size); - Vector2D xwaylandPositionToReal(Vector2D size); - void updateX11SurfaceScale(); - void sendWindowSize(bool force = false); - NContentType::eContentType getContentType(); - void setContentType(NContentType::eContentType contentType); - void deactivateGroupMembers(); - bool isNotResponding(); - std::optional xdgTag(); - std::optional xdgDescription(); - PHLWINDOW parent(); - bool priorityFocus(); - SP getSolitaryResource(); - Vector2D getReportedSize(); - std::optional calculateExpression(const std::string& s); - - CBox getWindowMainSurfaceBox() const { - return {m_realPosition->value().x, m_realPosition->value().y, m_realSize->value().x, m_realSize->value().y}; - } - - // listeners - void onAck(uint32_t serial); - - // - std::unordered_map getEnv(); - - // - PHLWINDOWREF m_self; - - // make private once we move listeners to inside CWindow - struct { - CHyprSignalListener map; - CHyprSignalListener ack; - CHyprSignalListener unmap; - CHyprSignalListener commit; - CHyprSignalListener destroy; - CHyprSignalListener activate; - CHyprSignalListener configureRequest; - CHyprSignalListener setGeometry; - CHyprSignalListener updateState; - CHyprSignalListener updateMetadata; - CHyprSignalListener resourceChange; - } m_listeners; - - private: - std::optional calculateSingleExpr(const std::string& s); - - // For hidden windows and stuff - bool m_hidden = false; - bool m_suspended = false; - WORKSPACEID m_lastWorkspace = WORKSPACE_INVALID; -}; - -inline bool valid(PHLWINDOW w) { - return w.get(); -} - -inline bool valid(PHLWINDOWREF w) { - return !w.expired(); -} - -inline bool validMapped(PHLWINDOW w) { - if (!valid(w)) - return false; - return w->m_isMapped; -} - -inline bool validMapped(PHLWINDOWREF w) { - if (!valid(w)) - return false; - return w->m_isMapped; -} - -/** - format specification - - 'x', only address, equivalent of (uintpr_t)CWindow* - - 'm', with monitor id - - 'w', with workspace id - - 'c', with application class -*/ - -template -struct std::formatter : std::formatter { - bool formatAddressOnly = false; - bool formatWorkspace = false; - bool formatMonitor = false; - bool formatClass = false; - FORMAT_PARSE( // - FORMAT_FLAG('x', formatAddressOnly) // - FORMAT_FLAG('m', formatMonitor) // - FORMAT_FLAG('w', formatWorkspace) // - FORMAT_FLAG('c', formatClass), - PHLWINDOW) - - template - auto format(PHLWINDOW const& w, FormatContext& ctx) const { - auto&& out = ctx.out(); - if (formatAddressOnly) - return std::format_to(out, "{:x}", rc(w.get())); - if (!w) - return std::format_to(out, "[Window nullptr]"); - - std::format_to(out, "["); - std::format_to(out, "Window {:x}: title: \"{}\"", rc(w.get()), w->m_title); - if (formatWorkspace) - std::format_to(out, ", workspace: {}", w->m_workspace ? w->workspaceID() : WORKSPACE_INVALID); - if (formatMonitor) - std::format_to(out, ", monitor: {}", w->monitorID()); - if (formatClass) - std::format_to(out, ", class: {}", w->m_class); - return std::format_to(out, "]"); - } -}; diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index 72bc3a67e..392ef6429 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -13,8 +13,6 @@ enum eFullscreenMode : int8_t { FSMODE_MAX = (1 << 2) - 1 }; -class CWindow; - class CWorkspace { public: static PHLWORKSPACE create(WORKSPACEID id, PHLMONITOR monitor, std::string name, bool special = false, bool isEmpty = true); diff --git a/src/desktop/rule/Engine.cpp b/src/desktop/rule/Engine.cpp index 3232035d6..fa0c2e27b 100644 --- a/src/desktop/rule/Engine.cpp +++ b/src/desktop/rule/Engine.cpp @@ -1,6 +1,6 @@ #include "Engine.hpp" #include "Rule.hpp" -#include "../LayerSurface.hpp" +#include "../view/LayerSurface.hpp" #include "../../Compositor.hpp" using namespace Desktop; diff --git a/src/desktop/rule/layerRule/LayerRule.cpp b/src/desktop/rule/layerRule/LayerRule.cpp index be7576729..0356157f2 100644 --- a/src/desktop/rule/layerRule/LayerRule.cpp +++ b/src/desktop/rule/layerRule/LayerRule.cpp @@ -1,6 +1,6 @@ #include "LayerRule.hpp" #include "../../../debug/Log.hpp" -#include "../../LayerSurface.hpp" +#include "../../view/LayerSurface.hpp" using namespace Desktop; using namespace Desktop::Rule; diff --git a/src/desktop/rule/layerRule/LayerRuleApplicator.cpp b/src/desktop/rule/layerRule/LayerRuleApplicator.cpp index bb7da97fb..11e5c1370 100644 --- a/src/desktop/rule/layerRule/LayerRuleApplicator.cpp +++ b/src/desktop/rule/layerRule/LayerRuleApplicator.cpp @@ -1,7 +1,7 @@ #include "LayerRuleApplicator.hpp" #include "LayerRule.hpp" #include "../Engine.hpp" -#include "../../LayerSurface.hpp" +#include "../../view/LayerSurface.hpp" #include "../../types/OverridableVar.hpp" #include "../../../helpers/MiscFunctions.hpp" diff --git a/src/desktop/rule/windowRule/WindowRule.cpp b/src/desktop/rule/windowRule/WindowRule.cpp index 893243b09..7fb289fa3 100644 --- a/src/desktop/rule/windowRule/WindowRule.cpp +++ b/src/desktop/rule/windowRule/WindowRule.cpp @@ -1,5 +1,5 @@ #include "WindowRule.hpp" -#include "../../Window.hpp" +#include "../../view/Window.hpp" #include "../../../helpers/Monitor.hpp" #include "../../../Compositor.hpp" #include "../../../managers/TokenManager.hpp" diff --git a/src/desktop/rule/windowRule/WindowRuleApplicator.cpp b/src/desktop/rule/windowRule/WindowRuleApplicator.cpp index 3474f2400..76109a42f 100644 --- a/src/desktop/rule/windowRule/WindowRuleApplicator.cpp +++ b/src/desktop/rule/windowRule/WindowRuleApplicator.cpp @@ -2,7 +2,7 @@ #include "WindowRule.hpp" #include "../Engine.hpp" #include "../utils/SetUtils.hpp" -#include "../../Window.hpp" +#include "../../view/Window.hpp" #include "../../types/OverridableVar.hpp" #include "../../../managers/LayoutManager.hpp" #include "../../../managers/HookSystemManager.hpp" diff --git a/src/desktop/state/FocusState.cpp b/src/desktop/state/FocusState.cpp index 8908d3de2..1bb231aa0 100644 --- a/src/desktop/state/FocusState.cpp +++ b/src/desktop/state/FocusState.cpp @@ -1,5 +1,5 @@ #include "FocusState.hpp" -#include "../Window.hpp" +#include "../view/Window.hpp" #include "../../Compositor.hpp" #include "../../protocols/XDGShell.hpp" #include "../../render/Renderer.hpp" @@ -191,7 +191,7 @@ void CFocusState::rawWindowFocus(PHLWINDOW pWindow, SP surfa g_pXWaylandManager->activateWindow(PLASTWINDOW, false); } - const auto PWINDOWSURFACE = surface ? surface : pWindow->m_wlSurface->resource(); + const auto PWINDOWSURFACE = surface ? surface : pWindow->wlSurface()->resource(); rawSurfaceFocus(PWINDOWSURFACE, pWindow); @@ -227,7 +227,7 @@ void CFocusState::rawWindowFocus(PHLWINDOW pWindow, SP surfa } void CFocusState::rawSurfaceFocus(SP pSurface, PHLWINDOW pWindowOwner) { - if (g_pSeatManager->m_state.keyboardFocus == pSurface || (pWindowOwner && g_pSeatManager->m_state.keyboardFocus == pWindowOwner->m_wlSurface->resource())) + if (g_pSeatManager->m_state.keyboardFocus == pSurface || (pWindowOwner && g_pSeatManager->m_state.keyboardFocus == pWindowOwner->wlSurface()->resource())) return; // Don't focus when already focused on this. if (g_pSessionLockManager->isSessionLocked() && pSurface && !g_pSessionLockManager->isSurfaceSessionLock(pSurface)) @@ -266,8 +266,8 @@ void CFocusState::rawSurfaceFocus(SP pSurface, PHLWINDOW pWi EMIT_HOOK_EVENT("keyboardFocus", pSurface); - const auto SURF = CWLSurface::fromResource(pSurface); - const auto OLDSURF = CWLSurface::fromResource(PLASTSURF); + const auto SURF = Desktop::View::CWLSurface::fromResource(pSurface); + const auto OLDSURF = Desktop::View::CWLSurface::fromResource(PLASTSURF); if (OLDSURF && OLDSURF->constraint()) OLDSURF->constraint()->deactivate(); diff --git a/src/desktop/view/GlobalViewMethods.cpp b/src/desktop/view/GlobalViewMethods.cpp new file mode 100644 index 000000000..97dc99606 --- /dev/null +++ b/src/desktop/view/GlobalViewMethods.cpp @@ -0,0 +1,82 @@ +#include "GlobalViewMethods.hpp" +#include "../../Compositor.hpp" + +#include "LayerSurface.hpp" +#include "Window.hpp" +#include "Popup.hpp" +#include "Subsurface.hpp" +#include "SessionLock.hpp" + +#include "../../protocols/core/Compositor.hpp" +#include "../../protocols/core/Subcompositor.hpp" +#include "../../protocols/SessionLock.hpp" + +using namespace Desktop; +using namespace Desktop::View; + +std::vector> View::getViewsForWorkspace(PHLWORKSPACE ws) { + std::vector> views; + + for (const auto& w : g_pCompositor->m_windows) { + if (!w->visible() || w->m_workspace != ws) + continue; + + views.emplace_back(w); + + w->wlSurface()->resource()->breadthfirst( + [&views](SP s, const Vector2D& pos, void* data) { + auto surf = CWLSurface::fromResource(s); + if (!surf || !s->m_mapped) + return; + + views.emplace_back(surf->view()); + }, + nullptr); + + // xwl windows dont have this + if (w->m_popupHead) { + w->m_popupHead->breadthfirst( + [&views](SP s, void* data) { + auto surf = s->wlSurface(); + if (!surf || !s->visible()) + return; + + views.emplace_back(surf->view()); + }, + nullptr); + } + } + + for (const auto& l : g_pCompositor->m_layers) { + if (!l->visible() || l->m_monitor != ws->m_monitor) + continue; + + views.emplace_back(l); + + l->m_popupHead->breadthfirst( + [&views](SP p, void* data) { + auto surf = p->wlSurface(); + if (!surf || !p->visible()) + return; + + views.emplace_back(surf->view()); + }, + nullptr); + } + + for (const auto& v : g_pCompositor->m_otherViews) { + if (!v->visible() || !v->desktopComponent()) + continue; + + if (v->type() == VIEW_TYPE_LOCK_SCREEN) { + const auto LOCK = Desktop::View::CSessionLock::fromView(v); + if (LOCK->monitor() != ws->m_monitor) + continue; + + views.emplace_back(LOCK); + continue; + } + } + + return views; +} diff --git a/src/desktop/view/GlobalViewMethods.hpp b/src/desktop/view/GlobalViewMethods.hpp new file mode 100644 index 000000000..551a42da7 --- /dev/null +++ b/src/desktop/view/GlobalViewMethods.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "View.hpp" + +#include "../Workspace.hpp" + +#include + +namespace Desktop::View { + std::vector> getViewsForWorkspace(PHLWORKSPACE ws); +}; \ No newline at end of file diff --git a/src/desktop/LayerSurface.cpp b/src/desktop/view/LayerSurface.cpp similarity index 83% rename from src/desktop/LayerSurface.cpp rename to src/desktop/view/LayerSurface.cpp index 4f08bff6c..3192321ea 100644 --- a/src/desktop/LayerSurface.cpp +++ b/src/desktop/view/LayerSurface.cpp @@ -1,25 +1,27 @@ #include "LayerSurface.hpp" -#include "state/FocusState.hpp" -#include "../Compositor.hpp" -#include "../events/Events.hpp" -#include "../protocols/LayerShell.hpp" -#include "../protocols/core/Compositor.hpp" -#include "../managers/SeatManager.hpp" -#include "../managers/animation/AnimationManager.hpp" -#include "../managers/animation/DesktopAnimationManager.hpp" -#include "../render/Renderer.hpp" -#include "../config/ConfigManager.hpp" -#include "../helpers/Monitor.hpp" -#include "../managers/input/InputManager.hpp" -#include "../managers/HookSystemManager.hpp" -#include "../managers/EventManager.hpp" +#include "../state/FocusState.hpp" +#include "../../Compositor.hpp" +#include "../../protocols/LayerShell.hpp" +#include "../../protocols/core/Compositor.hpp" +#include "../../managers/SeatManager.hpp" +#include "../../managers/animation/AnimationManager.hpp" +#include "../../managers/animation/DesktopAnimationManager.hpp" +#include "../../render/Renderer.hpp" +#include "../../config/ConfigManager.hpp" +#include "../../helpers/Monitor.hpp" +#include "../../managers/input/InputManager.hpp" +#include "../../managers/HookSystemManager.hpp" +#include "../../managers/EventManager.hpp" + +using namespace Desktop; +using namespace Desktop::View; PHLLS CLayerSurface::create(SP resource) { PHLLS pLS = SP(new CLayerSurface(resource)); auto pMonitor = resource->m_monitor.empty() ? Desktop::focusState()->monitor() : g_pCompositor->getMonitorFromName(resource->m_monitor); - pLS->m_surface->assign(resource->m_surface.lock(), pLS); + pLS->m_wlSurface->assign(resource->m_surface.lock(), pLS); if (!pMonitor) { Debug::log(ERR, "New LS has no monitor??"); @@ -54,6 +56,12 @@ PHLLS CLayerSurface::create(SP resource) { return pLS; } +PHLLS CLayerSurface::fromView(SP v) { + if (!v || v->type() != VIEW_TYPE_LAYER_SURFACE) + return nullptr; + return dynamicPointerCast(v); +} + void CLayerSurface::registerCallbacks() { m_alpha->setUpdateCallback([this](auto) { if (m_ruleApplicator->dimAround().valueOrDefault() && m_monitor) @@ -61,21 +69,19 @@ void CLayerSurface::registerCallbacks() { }); } -CLayerSurface::CLayerSurface(SP resource_) : m_layerSurface(resource_) { +CLayerSurface::CLayerSurface(SP resource_) : IView(CWLSurface::create()), m_layerSurface(resource_) { m_listeners.commit = m_layerSurface->m_events.commit.listen([this] { onCommit(); }); m_listeners.map = m_layerSurface->m_events.map.listen([this] { onMap(); }); m_listeners.unmap = m_layerSurface->m_events.unmap.listen([this] { onUnmap(); }); m_listeners.destroy = m_layerSurface->m_events.destroy.listen([this] { onDestroy(); }); - - m_surface = CWLSurface::create(); } CLayerSurface::~CLayerSurface() { if (!g_pHyprOpenGL) return; - if (m_surface) - m_surface->unassign(); + if (m_wlSurface) + m_wlSurface->unassign(); g_pHyprRenderer->makeEGLCurrent(); std::erase_if(g_pHyprOpenGL->m_layerFramebuffers, [&](const auto& other) { return other.first.expired() || other.first.lock() == m_self.lock(); }); @@ -86,6 +92,29 @@ CLayerSurface::~CLayerSurface() { } } +eViewType CLayerSurface::type() const { + return VIEW_TYPE_LAYER_SURFACE; +} + +bool CLayerSurface::visible() const { + return (m_mapped && m_layerSurface && m_layerSurface->m_mapped && m_wlSurface && m_wlSurface->resource()) || (m_fadingOut && m_alpha->value() > 0.F); +} + +std::optional CLayerSurface::logicalBox() const { + return surfaceLogicalBox(); +} + +std::optional CLayerSurface::surfaceLogicalBox() const { + if (!visible()) + return std::nullopt; + + return CBox{m_realPosition->value(), m_realSize->value()}; +} + +bool CLayerSurface::desktopComponent() const { + return true; +} + void CLayerSurface::onDestroy() { Debug::log(LOG, "LayerSurface {:x} destroyed", rc(m_layerSurface.get())); @@ -123,8 +152,8 @@ void CLayerSurface::onDestroy() { m_readyToDelete = true; m_layerSurface.reset(); - if (m_surface) - m_surface->unassign(); + if (m_wlSurface) + m_wlSurface->unassign(); m_listeners.unmap.reset(); m_listeners.destroy.reset(); @@ -156,7 +185,7 @@ void CLayerSurface::onMap() { g_pHyprRenderer->arrangeLayersForMonitor(PMONITOR->m_id); - m_surface->resource()->enter(PMONITOR->m_self.lock()); + m_wlSurface->resource()->enter(PMONITOR->m_self.lock()); const bool ISEXCLUSIVE = m_layerSurface->m_current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE; @@ -170,14 +199,14 @@ void CLayerSurface::onMap() { if (GRABSFOCUS) { // TODO: use the new superb really very cool grab - if (g_pSeatManager->m_seatGrab && !g_pSeatManager->m_seatGrab->accepts(m_surface->resource())) + if (g_pSeatManager->m_seatGrab && !g_pSeatManager->m_seatGrab->accepts(m_wlSurface->resource())) g_pSeatManager->setGrab(nullptr); g_pInputManager->releaseAllMouseButtons(); - Desktop::focusState()->rawSurfaceFocus(m_surface->resource()); + Desktop::focusState()->rawSurfaceFocus(m_wlSurface->resource()); const auto LOCAL = g_pInputManager->getMouseCoordsInternal() - Vector2D(m_geometry.x + PMONITOR->m_position.x, m_geometry.y + PMONITOR->m_position.y); - g_pSeatManager->setPointerFocus(m_surface->resource(), LOCAL); + g_pSeatManager->setPointerFocus(m_wlSurface->resource(), LOCAL); g_pInputManager->m_emptyFocusCursorSet = false; } @@ -194,8 +223,8 @@ void CLayerSurface::onMap() { g_pEventManager->postEvent(SHyprIPCEvent{.event = "openlayer", .data = m_namespace}); EMIT_HOOK_EVENT("openLayer", m_self.lock()); - g_pCompositor->setPreferredScaleForSurface(m_surface->resource(), PMONITOR->m_scale); - g_pCompositor->setPreferredTransformForSurface(m_surface->resource(), PMONITOR->m_transform); + g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), PMONITOR->m_scale); + g_pCompositor->setPreferredTransformForSurface(m_wlSurface->resource(), PMONITOR->m_transform); } void CLayerSurface::onUnmap() { @@ -238,7 +267,7 @@ void CLayerSurface::onUnmap() { const auto PMONITOR = m_monitor.lock(); - const bool WASLASTFOCUS = g_pSeatManager->m_state.keyboardFocus == m_surface->resource() || g_pSeatManager->m_state.pointerFocus == m_surface->resource(); + const bool WASLASTFOCUS = g_pSeatManager->m_state.keyboardFocus == m_wlSurface->resource() || g_pSeatManager->m_state.pointerFocus == m_wlSurface->resource(); if (!PMONITOR) return; @@ -249,7 +278,7 @@ void CLayerSurface::onUnmap() { (Desktop::focusState()->surface() && Desktop::focusState()->surface()->m_hlSurface && !Desktop::focusState()->surface()->m_hlSurface->keyboardFocusable())) { if (!g_pInputManager->refocusLastWindow(PMONITOR)) g_pInputManager->refocus(); - } else if (Desktop::focusState()->surface() && Desktop::focusState()->surface() != m_surface->resource()) + } else if (Desktop::focusState()->surface() && Desktop::focusState()->surface() != m_wlSurface->resource()) g_pSeatManager->setKeyboardFocus(Desktop::focusState()->surface()); CBox geomFixed = {m_geometry.x + PMONITOR->m_position.x, m_geometry.y + PMONITOR->m_position.y, m_geometry.width, m_geometry.height}; @@ -359,8 +388,8 @@ void CLayerSurface::onCommit() { nullptr); if (!WASLASTFOCUS && m_popupHead) { m_popupHead->breadthfirst( - [&WASLASTFOCUS](WP popup, void* data) { - WASLASTFOCUS = WASLASTFOCUS || (popup->m_wlSurface && g_pSeatManager->m_state.keyboardFocus == popup->m_wlSurface->resource()); + [&WASLASTFOCUS](WP popup, void* data) { + WASLASTFOCUS = WASLASTFOCUS || (popup->wlSurface() && g_pSeatManager->m_state.keyboardFocus == popup->wlSurface()->resource()); }, nullptr); } @@ -384,20 +413,20 @@ void CLayerSurface::onCommit() { // if now exclusive and not previously g_pSeatManager->setGrab(nullptr); g_pInputManager->releaseAllMouseButtons(); - Desktop::focusState()->rawSurfaceFocus(m_surface->resource()); + Desktop::focusState()->rawSurfaceFocus(m_wlSurface->resource()); const auto LOCAL = g_pInputManager->getMouseCoordsInternal() - Vector2D(m_geometry.x + PMONITOR->m_position.x, m_geometry.y + PMONITOR->m_position.y); - g_pSeatManager->setPointerFocus(m_surface->resource(), LOCAL); + g_pSeatManager->setPointerFocus(m_wlSurface->resource(), LOCAL); g_pInputManager->m_emptyFocusCursorSet = false; } } m_interactivity = m_layerSurface->m_current.interactivity; - g_pHyprRenderer->damageSurface(m_surface->resource(), m_position.x, m_position.y); + g_pHyprRenderer->damageSurface(m_wlSurface->resource(), m_position.x, m_position.y); - g_pCompositor->setPreferredScaleForSurface(m_surface->resource(), PMONITOR->m_scale); - g_pCompositor->setPreferredTransformForSurface(m_surface->resource(), PMONITOR->m_transform); + g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), PMONITOR->m_scale); + g_pCompositor->setPreferredTransformForSurface(m_wlSurface->resource(), PMONITOR->m_transform); } bool CLayerSurface::isFadedOut() { @@ -412,7 +441,7 @@ int CLayerSurface::popupsCount() { return 0; int no = -1; // we have one dummy - m_popupHead->breadthfirst([](WP p, void* data) { *sc(data) += 1; }, &no); + m_popupHead->breadthfirst([](WP p, void* data) { *sc(data) += 1; }, &no); return no; } @@ -424,10 +453,10 @@ pid_t CLayerSurface::getPID() { pid_t PID = -1; if (!m_layerSurface || !m_layerSurface->m_surface || !m_layerSurface->m_surface->getResource() || !m_layerSurface->m_surface->getResource()->resource() || - !m_layerSurface->m_surface->getResource()->resource()->client) + !m_layerSurface->m_surface->getResource()->client()) return -1; - wl_client_get_credentials(m_layerSurface->m_surface->getResource()->resource()->client, &PID, nullptr, nullptr); + wl_client_get_credentials(m_layerSurface->m_surface->getResource()->client(), &PID, nullptr, nullptr); return PID; } diff --git a/src/desktop/view/LayerSurface.hpp b/src/desktop/view/LayerSurface.hpp new file mode 100644 index 000000000..3bca03d63 --- /dev/null +++ b/src/desktop/view/LayerSurface.hpp @@ -0,0 +1,105 @@ +#pragma once + +#include +#include "../../defines.hpp" +#include "WLSurface.hpp" +#include "View.hpp" +#include "../rule/layerRule/LayerRuleApplicator.hpp" +#include "../../helpers/AnimatedVariable.hpp" + +class CLayerShellResource; + +namespace Desktop::View { + + class CLayerSurface : public IView { + public: + static PHLLS create(SP); + static PHLLS fromView(SP); + + private: + CLayerSurface(SP); + + public: + virtual ~CLayerSurface(); + + virtual eViewType type() const; + virtual bool visible() const; + virtual std::optional logicalBox() const; + virtual bool desktopComponent() const; + virtual std::optional surfaceLogicalBox() const; + + bool isFadedOut(); + int popupsCount(); + + PHLANIMVAR m_realPosition; + PHLANIMVAR m_realSize; + PHLANIMVAR m_alpha; + + WP m_layerSurface; + + // the header providing the enum type cannot be imported here + int m_interactivity = 0; + + bool m_mapped = false; + uint32_t m_layer = 0; + + PHLMONITORREF m_monitor; + + bool m_fadingOut = false; + bool m_readyToDelete = false; + bool m_noProcess = false; + + UP m_ruleApplicator; + + PHLLSREF m_self; + + CBox m_geometry = {0, 0, 0, 0}; + Vector2D m_position; + std::string m_namespace = ""; + SP m_popupHead; + + pid_t getPID(); + + void onDestroy(); + void onMap(); + void onUnmap(); + void onCommit(); + MONITORID monitorID(); + + private: + struct { + CHyprSignalListener destroy; + CHyprSignalListener map; + CHyprSignalListener unmap; + CHyprSignalListener commit; + } m_listeners; + + void registerCallbacks(); + + // For the list lookup + bool operator==(const CLayerSurface& rhs) const { + return m_layerSurface == rhs.m_layerSurface && m_monitor == rhs.m_monitor; + } + }; + + inline bool valid(PHLLS l) { + return l; + } + + inline bool valid(PHLLSREF l) { + return l; + } + + inline bool validMapped(PHLLS l) { + if (!valid(l)) + return false; + return l->visible(); + } + + inline bool validMapped(PHLLSREF l) { + if (!valid(l)) + return false; + return l->visible(); + } + +} diff --git a/src/desktop/Popup.cpp b/src/desktop/view/Popup.cpp similarity index 82% rename from src/desktop/Popup.cpp rename to src/desktop/view/Popup.cpp index c3794c6ca..31ea125b2 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/view/Popup.cpp @@ -1,43 +1,45 @@ #include "Popup.hpp" -#include "../config/ConfigValue.hpp" -#include "../config/ConfigManager.hpp" -#include "../Compositor.hpp" -#include "../protocols/LayerShell.hpp" -#include "../protocols/XDGShell.hpp" -#include "../protocols/core/Compositor.hpp" -#include "../managers/SeatManager.hpp" -#include "../managers/animation/AnimationManager.hpp" -#include "../desktop/LayerSurface.hpp" -#include "../managers/input/InputManager.hpp" -#include "../render/Renderer.hpp" -#include "../render/OpenGL.hpp" +#include "../../config/ConfigValue.hpp" +#include "../../config/ConfigManager.hpp" +#include "../../Compositor.hpp" +#include "../../protocols/LayerShell.hpp" +#include "../../protocols/XDGShell.hpp" +#include "../../protocols/core/Compositor.hpp" +#include "../../managers/SeatManager.hpp" +#include "../../managers/animation/AnimationManager.hpp" +#include "LayerSurface.hpp" +#include "../../managers/input/InputManager.hpp" +#include "../../render/Renderer.hpp" +#include "../../render/OpenGL.hpp" #include -UP CPopup::create(PHLWINDOW pOwner) { - auto popup = UP(new CPopup()); +using namespace Desktop; +using namespace Desktop::View; + +SP CPopup::create(PHLWINDOW pOwner) { + auto popup = SP(new CPopup()); popup->m_windowOwner = pOwner; popup->m_self = popup; popup->initAllSignals(); return popup; } -UP CPopup::create(PHLLS pOwner) { - auto popup = UP(new CPopup()); +SP CPopup::create(PHLLS pOwner) { + auto popup = SP(new CPopup()); popup->m_layerOwner = pOwner; popup->m_self = popup; popup->initAllSignals(); return popup; } -UP CPopup::create(SP resource, WP pOwner) { - auto popup = UP(new CPopup()); +SP CPopup::create(SP resource, WP pOwner) { + auto popup = SP(new CPopup()); popup->m_resource = resource; popup->m_windowOwner = pOwner->m_windowOwner; popup->m_layerOwner = pOwner->m_layerOwner; popup->m_parent = pOwner; popup->m_self = popup; - popup->m_wlSurface = CWLSurface::create(); - popup->m_wlSurface->assign(resource->m_surface->m_surface.lock(), popup.get()); + popup->wlSurface()->assign(resource->m_surface->m_surface.lock(), popup); popup->m_lastSize = resource->m_surface->m_current.geometry.size(); popup->reposition(); @@ -46,11 +48,56 @@ UP CPopup::create(SP resource, WP pOwner) { return popup; } +SP CPopup::fromView(SP v) { + if (!v || v->type() != VIEW_TYPE_POPUP) + return nullptr; + return dynamicPointerCast(v); +} + +CPopup::CPopup() : IView(CWLSurface::create()) { + ; +} + CPopup::~CPopup() { if (m_wlSurface) m_wlSurface->unassign(); } +eViewType CPopup::type() const { + return VIEW_TYPE_POPUP; +} + +bool CPopup::visible() const { + if (!m_mapped || !m_wlSurface->resource()) + return false; + + if (!m_windowOwner.expired()) + return g_pHyprRenderer->shouldRenderWindow(m_windowOwner.lock()); + + if (!m_layerOwner.expired()) + return true; + + if (m_parent) + return m_parent->visible(); + + return false; +} + +std::optional CPopup::logicalBox() const { + return surfaceLogicalBox(); +} + +std::optional CPopup::surfaceLogicalBox() const { + if (!visible()) + return std::nullopt; + + return CBox{t1ParentCoords(), size()}; +} + +bool CPopup::desktopComponent() const { + return true; +} + void CPopup::initAllSignals() { g_pAnimationManager->createAnimation(0.f, m_alpha, g_pConfigManager->getAnimationPropertyConfig("fadePopupsIn"), AVARDAMAGE_NONE); @@ -286,11 +333,11 @@ void CPopup::reposition() { m_resource->applyPositioning(box, COORDS); } -SP CPopup::getT1Owner() { +SP CPopup::getT1Owner() { if (m_windowOwner) - return m_windowOwner->m_wlSurface; + return m_windowOwner->wlSurface(); else - return m_layerOwner->m_surface; + return m_layerOwner->wlSurface(); } Vector2D CPopup::coordsRelativeToParent() { @@ -304,7 +351,7 @@ Vector2D CPopup::coordsRelativeToParent() { while (current->m_parent && current->m_resource) { - offset += current->m_wlSurface->resource()->m_current.offset; + offset += current->wlSurface()->resource()->m_current.offset; offset += current->m_resource->m_geometry.pos(); current = current->m_parent; @@ -321,7 +368,7 @@ Vector2D CPopup::localToGlobal(const Vector2D& rel) { return t1ParentCoords() + rel; } -Vector2D CPopup::t1ParentCoords() { +Vector2D CPopup::t1ParentCoords() const { if (!m_windowOwner.expired()) return m_windowOwner->m_realPosition->value(); if (!m_layerOwner.expired()) @@ -352,36 +399,25 @@ void CPopup::recheckChildrenRecursive() { } } -Vector2D CPopup::size() { +Vector2D CPopup::size() const { return m_lastSize; } void CPopup::sendScale() { if (!m_windowOwner.expired()) - g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_windowOwner->m_wlSurface->m_lastScaleFloat); + g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_windowOwner->wlSurface()->m_lastScaleFloat); else if (!m_layerOwner.expired()) - g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_layerOwner->m_surface->m_lastScaleFloat); + g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_layerOwner->wlSurface()->m_lastScaleFloat); else UNREACHABLE(); } -bool CPopup::visible() { - if (!m_windowOwner.expired()) - return g_pHyprRenderer->shouldRenderWindow(m_windowOwner.lock()); - if (!m_layerOwner.expired()) - return true; - if (m_parent) - return m_parent->visible(); - - return false; -} - -void CPopup::bfHelper(std::vector> const& nodes, std::function, void*)> fn, void* data) { +void CPopup::bfHelper(std::vector> const& nodes, std::function, void*)> fn, void* data) { for (auto const& n : nodes) { fn(n, data); } - std::vector> nodes2; + std::vector> nodes2; nodes2.reserve(nodes.size() * 2); for (auto const& n : nodes) { @@ -389,7 +425,7 @@ void CPopup::bfHelper(std::vector> const& nodes, std::functionm_children) { - nodes2.push_back(c->m_self); + nodes2.emplace_back(c->m_self.lock()); } } @@ -397,18 +433,18 @@ void CPopup::bfHelper(std::vector> const& nodes, std::function, void*)> fn, void* data) { +void CPopup::breadthfirst(std::function, void*)> fn, void* data) { if (!m_self) return; - std::vector> popups; - popups.push_back(m_self); + std::vector> popups; + popups.emplace_back(m_self.lock()); bfHelper(popups, fn, data); } -WP CPopup::at(const Vector2D& globalCoords, bool allowsInput) { - std::vector> popups; - breadthfirst([&popups](WP popup, void* data) { popups.push_back(popup); }, &popups); +SP CPopup::at(const Vector2D& globalCoords, bool allowsInput) { + std::vector> popups; + breadthfirst([&popups](SP popup, void* data) { popups.push_back(popup); }, &popups); for (auto const& p : popups | std::views::reverse) { if (!p->m_resource || !p->m_mapped) @@ -427,7 +463,7 @@ WP CPopup::at(const Vector2D& globalCoords, bool allowsInput) { if (BOX.containsPoint(globalCoords)) return p; } else { - const auto REGION = CRegion{p->m_wlSurface->resource()->m_current.input}.intersect(CBox{{}, p->m_wlSurface->resource()->m_current.size}).translate(p->coordsGlobal()); + const auto REGION = CRegion{p->wlSurface()->resource()->m_current.input}.intersect(CBox{{}, p->wlSurface()->resource()->m_current.size}).translate(p->coordsGlobal()); if (REGION.containsPoint(globalCoords)) return p; } diff --git a/src/desktop/view/Popup.hpp b/src/desktop/view/Popup.hpp new file mode 100644 index 000000000..86b11acb5 --- /dev/null +++ b/src/desktop/view/Popup.hpp @@ -0,0 +1,106 @@ +#pragma once + +#include +#include "Subsurface.hpp" +#include "View.hpp" +#include "../../helpers/signal/Signal.hpp" +#include "../../helpers/memory/Memory.hpp" +#include "../../helpers/AnimatedVariable.hpp" + +class CXDGPopupResource; + +namespace Desktop::View { + + class CPopup : public IView { + public: + // dummy head nodes + static SP create(PHLWINDOW pOwner); + static SP create(PHLLS pOwner); + + // real nodes + static SP create(SP popup, WP pOwner); + + static SP fromView(SP); + + virtual ~CPopup(); + + virtual eViewType type() const; + virtual bool visible() const; + virtual std::optional logicalBox() const; + virtual bool desktopComponent() const; + virtual std::optional surfaceLogicalBox() const; + + SP getT1Owner(); + Vector2D coordsRelativeToParent(); + Vector2D coordsGlobal(); + PHLMONITOR getMonitor(); + + Vector2D size() const; + + void onNewPopup(SP popup); + void onDestroy(); + void onMap(); + void onUnmap(); + void onCommit(bool ignoreSiblings = false); + void onReposition(); + + void recheckTree(); + + bool inert() const; + + // will also loop over this node + void breadthfirst(std::function, void*)> fn, void* data); + SP at(const Vector2D& globalCoords, bool allowsInput = false); + + // + WP m_self; + bool m_mapped = false; + + // fade in-out + PHLANIMVAR m_alpha; + bool m_fadingOut = false; + + private: + CPopup(); + + // T1 owners, each popup has to have one of these + PHLWINDOWREF m_windowOwner; + PHLLSREF m_layerOwner; + + // T2 owners + WP m_parent; + + WP m_resource; + + Vector2D m_lastSize = {}; + Vector2D m_lastPos = {}; + + bool m_requestedReposition = false; + + bool m_inert = false; + + // + std::vector> m_children; + SP m_subsurfaceHead; + + struct { + CHyprSignalListener newPopup; + CHyprSignalListener destroy; + CHyprSignalListener map; + CHyprSignalListener unmap; + CHyprSignalListener commit; + CHyprSignalListener dismissed; + CHyprSignalListener reposition; + } m_listeners; + + void initAllSignals(); + void reposition(); + void recheckChildrenRecursive(); + void sendScale(); + void fullyDestroy(); + + Vector2D localToGlobal(const Vector2D& rel); + Vector2D t1ParentCoords() const; + static void bfHelper(std::vector> const& nodes, std::function, void*)> fn, void* data); + }; +} diff --git a/src/desktop/view/SessionLock.cpp b/src/desktop/view/SessionLock.cpp new file mode 100644 index 000000000..a4a5b78b0 --- /dev/null +++ b/src/desktop/view/SessionLock.cpp @@ -0,0 +1,74 @@ +#include "SessionLock.hpp" + +#include "../../protocols/SessionLock.hpp" +#include "../../protocols/core/Compositor.hpp" +#include "../../helpers/Monitor.hpp" + +#include "../../Compositor.hpp" + +using namespace Desktop; +using namespace Desktop::View; + +SP View::CSessionLock::create(SP resource) { + auto lock = SP(new CSessionLock()); + lock->m_surface = resource; + lock->m_self = lock; + + lock->init(); + + return lock; +} + +View::CSessionLock::CSessionLock() : IView(CWLSurface::create()) { + ; +} + +View::CSessionLock::~CSessionLock() { + m_wlSurface->unassign(); +} + +void View::CSessionLock::init() { + m_listeners.destroy = m_surface->m_events.destroy.listen([this] { std::erase_if(g_pCompositor->m_otherViews, [this](const auto& e) { return e == m_self; }); }); + + m_wlSurface->assign(m_surface->surface(), m_self.lock()); +} + +SP View::CSessionLock::fromView(SP v) { + if (!v || v->type() != VIEW_TYPE_LOCK_SCREEN) + return nullptr; + return dynamicPointerCast(v); +} + +eViewType View::CSessionLock::type() const { + return VIEW_TYPE_LOCK_SCREEN; +} + +bool View::CSessionLock::visible() const { + return m_wlSurface && m_wlSurface->resource() && m_wlSurface->resource()->m_mapped; +} + +std::optional View::CSessionLock::logicalBox() const { + return surfaceLogicalBox(); +} + +std::optional View::CSessionLock::surfaceLogicalBox() const { + if (!visible()) + return std::nullopt; + + const auto MON = m_surface->monitor(); + + if (!MON) + return std::nullopt; + + return MON->logicalBox(); +} + +bool View::CSessionLock::desktopComponent() const { + return true; +} + +PHLMONITOR View::CSessionLock::monitor() const { + if (m_surface) + return m_surface->monitor(); + return nullptr; +} diff --git a/src/desktop/view/SessionLock.hpp b/src/desktop/view/SessionLock.hpp new file mode 100644 index 000000000..c6141fb25 --- /dev/null +++ b/src/desktop/view/SessionLock.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include "../../defines.hpp" +#include +#include "WLSurface.hpp" +#include "View.hpp" + +class CSessionLockSurface; + +namespace Desktop::View { + class CSessionLock : public IView { + public: + static SP create(SP resource); + + static SP fromView(SP); + + virtual ~CSessionLock(); + + virtual eViewType type() const; + virtual bool visible() const; + virtual std::optional logicalBox() const; + virtual bool desktopComponent() const; + virtual std::optional surfaceLogicalBox() const; + + PHLMONITOR monitor() const; + + WP m_self; + + private: + CSessionLock(); + + void init(); + + struct { + CHyprSignalListener destroy; + } m_listeners; + + WP m_surface; + }; +} diff --git a/src/desktop/Subsurface.cpp b/src/desktop/view/Subsurface.cpp similarity index 71% rename from src/desktop/Subsurface.cpp rename to src/desktop/view/Subsurface.cpp index cea6977a9..2c39a083a 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/view/Subsurface.cpp @@ -1,56 +1,101 @@ #include "Subsurface.hpp" -#include "../events/Events.hpp" -#include "../desktop/state/FocusState.hpp" -#include "../desktop/Window.hpp" -#include "../config/ConfigValue.hpp" -#include "../protocols/core/Compositor.hpp" -#include "../protocols/core/Subcompositor.hpp" -#include "../render/Renderer.hpp" -#include "../managers/input/InputManager.hpp" +#include "../state/FocusState.hpp" +#include "Window.hpp" +#include "../../config/ConfigValue.hpp" +#include "../../protocols/core/Compositor.hpp" +#include "../../protocols/core/Subcompositor.hpp" +#include "../../render/Renderer.hpp" +#include "../../managers/input/InputManager.hpp" -UP CSubsurface::create(PHLWINDOW pOwner) { - auto subsurface = UP(new CSubsurface()); +using namespace Desktop; +using namespace Desktop::View; + +SP CSubsurface::create(PHLWINDOW pOwner) { + auto subsurface = SP(new CSubsurface()); subsurface->m_windowParent = pOwner; subsurface->m_self = subsurface; subsurface->initSignals(); - subsurface->initExistingSubsurfaces(pOwner->m_wlSurface->resource()); + subsurface->initExistingSubsurfaces(pOwner->wlSurface()->resource()); return subsurface; } -UP CSubsurface::create(WP pOwner) { - auto subsurface = UP(new CSubsurface()); +SP CSubsurface::create(WP pOwner) { + auto subsurface = SP(new CSubsurface()); subsurface->m_popupParent = pOwner; subsurface->m_self = subsurface; subsurface->initSignals(); - subsurface->initExistingSubsurfaces(pOwner->m_wlSurface->resource()); + subsurface->initExistingSubsurfaces(pOwner->wlSurface()->resource()); return subsurface; } -UP CSubsurface::create(SP pSubsurface, PHLWINDOW pOwner) { - auto subsurface = UP(new CSubsurface()); +SP CSubsurface::create(SP pSubsurface, PHLWINDOW pOwner) { + auto subsurface = SP(new CSubsurface()); subsurface->m_windowParent = pOwner; subsurface->m_subsurface = pSubsurface; subsurface->m_self = subsurface; - subsurface->m_wlSurface = CWLSurface::create(); - subsurface->m_wlSurface->assign(pSubsurface->m_surface.lock(), subsurface.get()); + subsurface->wlSurface() = CWLSurface::create(); + subsurface->wlSurface()->assign(pSubsurface->m_surface.lock(), subsurface); subsurface->initSignals(); subsurface->initExistingSubsurfaces(pSubsurface->m_surface.lock()); return subsurface; } -UP CSubsurface::create(SP pSubsurface, WP pOwner) { - auto subsurface = UP(new CSubsurface()); +SP CSubsurface::create(SP pSubsurface, WP pOwner) { + auto subsurface = SP(new CSubsurface()); subsurface->m_popupParent = pOwner; subsurface->m_subsurface = pSubsurface; subsurface->m_self = subsurface; - subsurface->m_wlSurface = CWLSurface::create(); - subsurface->m_wlSurface->assign(pSubsurface->m_surface.lock(), subsurface.get()); + subsurface->wlSurface() = CWLSurface::create(); + subsurface->wlSurface()->assign(pSubsurface->m_surface.lock(), subsurface); subsurface->initSignals(); subsurface->initExistingSubsurfaces(pSubsurface->m_surface.lock()); return subsurface; } +SP CSubsurface::fromView(SP v) { + if (!v || v->type() != VIEW_TYPE_SUBSURFACE) + return nullptr; + return dynamicPointerCast(v); +} + +CSubsurface::CSubsurface() : IView(CWLSurface::create()) { + ; +} + +eViewType CSubsurface::type() const { + return VIEW_TYPE_SUBSURFACE; +} + +bool CSubsurface::visible() const { + if (!m_wlSurface || !m_wlSurface->resource() || !m_wlSurface->resource()->m_mapped) + return false; + + if (!m_windowParent.expired()) + return g_pHyprRenderer->shouldRenderWindow(m_windowParent.lock()); + if (m_popupParent) + return m_popupParent->visible(); + if (m_parent) + return m_parent->visible(); + + return false; +} + +bool CSubsurface::desktopComponent() const { + return true; +} + +std::optional CSubsurface::logicalBox() const { + return surfaceLogicalBox(); +} + +std::optional CSubsurface::surfaceLogicalBox() const { + if (!visible()) + return std::nullopt; + + return CBox{coordsGlobal(), m_lastSize}; +} + void CSubsurface::initSignals() { if (m_subsurface) { m_listeners.commitSubsurface = m_subsurface->m_surface->m_events.commit.listen([this] { onCommit(); }); @@ -60,9 +105,9 @@ void CSubsurface::initSignals() { m_listeners.newSubsurface = m_subsurface->m_surface->m_events.newSubsurface.listen([this](const auto& resource) { onNewSubsurface(resource); }); } else { if (m_windowParent) - m_listeners.newSubsurface = m_windowParent->m_wlSurface->resource()->m_events.newSubsurface.listen([this](const auto& resource) { onNewSubsurface(resource); }); + m_listeners.newSubsurface = m_windowParent->wlSurface()->resource()->m_events.newSubsurface.listen([this](const auto& resource) { onNewSubsurface(resource); }); else if (m_popupParent) - m_listeners.newSubsurface = m_popupParent->m_wlSurface->resource()->m_events.newSubsurface.listen([this](const auto& resource) { onNewSubsurface(resource); }); + m_listeners.newSubsurface = m_popupParent->wlSurface()->resource()->m_events.newSubsurface.listen([this](const auto& resource) { onNewSubsurface(resource); }); else ASSERT(false); } @@ -79,14 +124,14 @@ void CSubsurface::checkSiblingDamage() { continue; const auto COORDS = n->coordsGlobal(); - g_pHyprRenderer->damageSurface(n->m_wlSurface->resource(), COORDS.x, COORDS.y, SCALE); + g_pHyprRenderer->damageSurface(n->wlSurface()->resource(), COORDS.x, COORDS.y, SCALE); } } void CSubsurface::recheckDamageForSubsurfaces() { for (auto const& n : m_children) { const auto COORDS = n->coordsGlobal(); - g_pHyprRenderer->damageSurface(n->m_wlSurface->resource(), COORDS.x, COORDS.y); + g_pHyprRenderer->damageSurface(n->wlSurface()->resource(), COORDS.x, COORDS.y); } } @@ -105,7 +150,7 @@ void CSubsurface::onCommit() { g_pHyprRenderer->damageSurface(m_wlSurface->resource(), COORDS.x, COORDS.y); - if (m_popupParent && !m_popupParent->inert() && m_popupParent->m_wlSurface) + if (m_popupParent && !m_popupParent->inert() && m_popupParent->wlSurface()) m_popupParent->recheckTree(); if (!m_windowParent.expired()) // I hate you firefox why are you doing this m_windowParent->m_popupHead->recheckTree(); @@ -187,13 +232,13 @@ void CSubsurface::damageLastArea() { g_pHyprRenderer->damageBox(box); } -Vector2D CSubsurface::coordsRelativeToParent() { +Vector2D CSubsurface::coordsRelativeToParent() const { if (!m_subsurface) return {}; return m_subsurface->posRelativeToParent(); } -Vector2D CSubsurface::coordsGlobal() { +Vector2D CSubsurface::coordsGlobal() const { Vector2D coords = coordsRelativeToParent(); if (!m_windowParent.expired()) @@ -215,14 +260,3 @@ void CSubsurface::initExistingSubsurfaces(SP pSurface) { Vector2D CSubsurface::size() { return m_wlSurface->resource()->m_current.size; } - -bool CSubsurface::visible() { - if (!m_windowParent.expired()) - return g_pHyprRenderer->shouldRenderWindow(m_windowParent.lock()); - if (m_popupParent) - return m_popupParent->visible(); - if (m_parent) - return m_parent->visible(); - - return false; -} diff --git a/src/desktop/view/Subsurface.hpp b/src/desktop/view/Subsurface.hpp new file mode 100644 index 000000000..ab74f48c3 --- /dev/null +++ b/src/desktop/view/Subsurface.hpp @@ -0,0 +1,77 @@ +#pragma once + +#include "../../defines.hpp" +#include +#include "WLSurface.hpp" +#include "View.hpp" + +class CWLSubsurfaceResource; + +namespace Desktop::View { + class CPopup; + class CSubsurface : public IView { + public: + // root dummy nodes + static SP create(PHLWINDOW pOwner); + static SP create(WP pOwner); + + // real nodes + static SP create(SP pSubsurface, PHLWINDOW pOwner); + static SP create(SP pSubsurface, WP pOwner); + + static SP fromView(SP); + + virtual ~CSubsurface() = default; + + virtual eViewType type() const; + virtual bool visible() const; + virtual std::optional logicalBox() const; + virtual bool desktopComponent() const; + virtual std::optional surfaceLogicalBox() const; + + Vector2D coordsRelativeToParent() const; + Vector2D coordsGlobal() const; + + Vector2D size(); + + void onCommit(); + void onDestroy(); + void onNewSubsurface(SP pSubsurface); + void onMap(); + void onUnmap(); + + void recheckDamageForSubsurfaces(); + + WP m_self; + + private: + CSubsurface(); + + struct { + CHyprSignalListener destroySubsurface; + CHyprSignalListener commitSubsurface; + CHyprSignalListener mapSubsurface; + CHyprSignalListener unmapSubsurface; + CHyprSignalListener newSubsurface; + } m_listeners; + + WP m_subsurface; + Vector2D m_lastSize = {}; + Vector2D m_lastPosition = {}; + + // if nullptr, means it's a dummy node + WP m_parent; + + PHLWINDOWREF m_windowParent; + WP m_popupParent; + + std::vector> m_children; + + bool m_inert = false; + + void initSignals(); + void initExistingSubsurfaces(SP pSurface); + void checkSiblingDamage(); + void damageLastArea(); + }; +} diff --git a/src/desktop/view/View.cpp b/src/desktop/view/View.cpp new file mode 100644 index 000000000..e7c6ce3ae --- /dev/null +++ b/src/desktop/view/View.cpp @@ -0,0 +1,16 @@ +#include "View.hpp" + +using namespace Desktop; +using namespace Desktop::View; + +SP IView::wlSurface() const { + return m_wlSurface; +} + +IView::IView(SP pWlSurface) : m_wlSurface(pWlSurface) { + ; +} + +SP IView::resource() const { + return m_wlSurface ? m_wlSurface->resource() : nullptr; +} diff --git a/src/desktop/view/View.hpp b/src/desktop/view/View.hpp new file mode 100644 index 000000000..0f412d2a1 --- /dev/null +++ b/src/desktop/view/View.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "WLSurface.hpp" +#include "../../helpers/math/Math.hpp" + +namespace Desktop::View { + enum eViewType : uint8_t { + VIEW_TYPE_WINDOW = 0, + VIEW_TYPE_SUBSURFACE, + VIEW_TYPE_POPUP, + VIEW_TYPE_LAYER_SURFACE, + VIEW_TYPE_LOCK_SCREEN, + }; + + class IView { + public: + virtual ~IView() = default; + + virtual SP wlSurface() const; + virtual SP resource() const; + virtual eViewType type() const = 0; + virtual bool visible() const = 0; + virtual bool desktopComponent() const = 0; + virtual std::optional logicalBox() const = 0; + virtual std::optional surfaceLogicalBox() const = 0; + + protected: + IView(SP pWlSurface); + + SP m_wlSurface; + }; +}; \ No newline at end of file diff --git a/src/desktop/WLSurface.cpp b/src/desktop/view/WLSurface.cpp similarity index 62% rename from src/desktop/WLSurface.cpp rename to src/desktop/view/WLSurface.cpp index a7b654f0b..1bf90ae8d 100644 --- a/src/desktop/WLSurface.cpp +++ b/src/desktop/view/WLSurface.cpp @@ -1,9 +1,12 @@ #include "WLSurface.hpp" #include "LayerSurface.hpp" -#include "../desktop/Window.hpp" -#include "../protocols/core/Compositor.hpp" -#include "../protocols/LayerShell.hpp" -#include "../render/Renderer.hpp" +#include "Window.hpp" +#include "../../protocols/core/Compositor.hpp" +#include "../../protocols/LayerShell.hpp" +#include "../../render/Renderer.hpp" + +using namespace Desktop; +using namespace Desktop::View; void CWLSurface::assign(SP pSurface) { m_resource = pSurface; @@ -11,30 +14,9 @@ void CWLSurface::assign(SP pSurface) { m_inert = false; } -void CWLSurface::assign(SP pSurface, PHLWINDOW pOwner) { - m_windowOwner = pOwner; - m_resource = pSurface; - init(); - m_inert = false; -} - -void CWLSurface::assign(SP pSurface, PHLLS pOwner) { - m_layerOwner = pOwner; - m_resource = pSurface; - init(); - m_inert = false; -} - -void CWLSurface::assign(SP pSurface, CSubsurface* pOwner) { - m_subsurfaceOwner = pOwner; - m_resource = pSurface; - init(); - m_inert = false; -} - -void CWLSurface::assign(SP pSurface, CPopup* pOwner) { - m_popupOwner = pOwner; - m_resource = pSurface; +void CWLSurface::assign(SP pSurface, SP pOwner) { + m_view = pOwner; + m_resource = pSurface; init(); m_inert = false; } @@ -56,24 +38,24 @@ SP CWLSurface::resource() const { } bool CWLSurface::small() const { - if (!validMapped(m_windowOwner) || !exists()) + if (!m_view || !m_view->visible() || m_view->type() != VIEW_TYPE_WINDOW || !exists()) return false; if (!m_resource->m_current.texture) return false; - const auto O = m_windowOwner.lock(); + const auto O = dynamicPointerCast(m_view.lock()); const auto REPORTED_SIZE = O->getReportedSize(); return REPORTED_SIZE.x > m_resource->m_current.size.x + 1 || REPORTED_SIZE.y > m_resource->m_current.size.y + 1; } Vector2D CWLSurface::correctSmallVec() const { - if (!validMapped(m_windowOwner) || !exists() || !small() || m_fillIgnoreSmall) + if (!m_view || !m_view->visible() || m_view->type() != VIEW_TYPE_WINDOW || !exists() || !small() || !m_fillIgnoreSmall) return {}; const auto SIZE = getViewporterCorrectedSize(); - const auto O = m_windowOwner.lock(); + const auto O = dynamicPointerCast(m_view.lock()); const auto REP = O->getReportedSize(); return Vector2D{(REP.x - SIZE.x) / 2, (REP.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) * (O->m_realSize->value() / REP); @@ -123,8 +105,8 @@ CRegion CWLSurface::computeDamage() const { damage.scale(SCALE); if (BOX.has_value()) { - if (m_windowOwner) - damage.intersect(CBox{{}, BOX->size() * m_windowOwner->m_X11SurfaceScaledBy}); + if (m_view->type() == VIEW_TYPE_WINDOW) + damage.intersect(CBox{{}, BOX->size() * dynamicPointerCast(m_view.lock())->m_X11SurfaceScaledBy}); else damage.intersect(CBox{{}, BOX->size()}); } @@ -142,11 +124,8 @@ void CWLSurface::destroy() { m_listeners.destroy.reset(); m_resource->m_hlSurface.reset(); - m_windowOwner.reset(); - m_layerOwner.reset(); - m_popupOwner = nullptr; - m_subsurfaceOwner = nullptr; - m_inert = true; + m_view.reset(); + m_inert = true; if (g_pHyprRenderer && g_pHyprRenderer->m_lastCursorData.surf && g_pHyprRenderer->m_lastCursorData.surf->get() == this) g_pHyprRenderer->m_lastCursorData.surf.reset(); @@ -169,40 +148,19 @@ void CWLSurface::init() { Debug::log(LOG, "CWLSurface {:x} called init()", rc(this)); } -PHLWINDOW CWLSurface::getWindow() const { - return m_windowOwner.lock(); -} - -PHLLS CWLSurface::getLayer() const { - return m_layerOwner.lock(); -} - -CPopup* CWLSurface::getPopup() const { - return m_popupOwner; -} - -CSubsurface* CWLSurface::getSubsurface() const { - return m_subsurfaceOwner; +SP CWLSurface::view() const { + return m_view.lock(); } bool CWLSurface::desktopComponent() const { - return !m_layerOwner.expired() || !m_windowOwner.expired() || m_subsurfaceOwner || m_popupOwner; + return m_view && m_view->visible(); } std::optional CWLSurface::getSurfaceBoxGlobal() const { if (!desktopComponent()) return {}; - if (!m_windowOwner.expired()) - return m_windowOwner->getWindowMainSurfaceBox(); - if (!m_layerOwner.expired()) - return m_layerOwner->m_geometry; - if (m_popupOwner) - return CBox{m_popupOwner->coordsGlobal(), m_popupOwner->size()}; - if (m_subsurfaceOwner) - return CBox{m_subsurfaceOwner->coordsGlobal(), m_subsurfaceOwner->size()}; - - return {}; + return m_view->surfaceLogicalBox(); } void CWLSurface::appendConstraint(WP constraint) { @@ -214,27 +172,23 @@ SP CWLSurface::constraint() const { } bool CWLSurface::visible() { - if (!m_windowOwner.expired()) - return g_pHyprRenderer->shouldRenderWindow(m_windowOwner.lock()); - if (!m_layerOwner.expired()) - return true; - if (m_popupOwner) - return m_popupOwner->visible(); - if (m_subsurfaceOwner) - return m_subsurfaceOwner->visible(); + if (m_view) + return m_view->visible(); return true; // non-desktop, we don't know much. } -SP CWLSurface::fromResource(SP pSurface) { +SP CWLSurface::fromResource(SP pSurface) { if (!pSurface) return nullptr; return pSurface->m_hlSurface.lock(); } bool CWLSurface::keyboardFocusable() const { - if (m_windowOwner || m_popupOwner || m_subsurfaceOwner) + if (!m_view) + return false; + if (m_view->type() == VIEW_TYPE_WINDOW || m_view->type() == VIEW_TYPE_SUBSURFACE || m_view->type() == VIEW_TYPE_POPUP) return true; - if (m_layerOwner && m_layerOwner->m_layerSurface) - return m_layerOwner->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE; + if (const auto LS = CLayerSurface::fromView(m_view.lock()); LS && LS->m_layerSurface) + return LS->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE; return false; } diff --git a/src/desktop/view/WLSurface.hpp b/src/desktop/view/WLSurface.hpp new file mode 100644 index 000000000..13c825941 --- /dev/null +++ b/src/desktop/view/WLSurface.hpp @@ -0,0 +1,118 @@ +#pragma once + +#include "../../defines.hpp" +#include "../../helpers/math/Math.hpp" +#include "../../helpers/signal/Signal.hpp" + +class CPointerConstraint; +class CWLSurfaceResource; + +namespace Desktop::View { + class CSubsurface; + class CPopup; + class IView; + + class CWLSurface { + public: + static SP create() { + auto p = SP(new CWLSurface); + p->m_self = p; + return p; + } + ~CWLSurface(); + + // anonymous surfaces are non-desktop components, e.g. a cursor surface or a DnD + void assign(SP pSurface); + void assign(SP pSurface, SP pOwner); + void unassign(); + + CWLSurface(const CWLSurface&) = delete; + CWLSurface(CWLSurface&&) = delete; + CWLSurface& operator=(const CWLSurface&) = delete; + CWLSurface& operator=(CWLSurface&&) = delete; + + SP resource() const; + bool exists() const; + bool small() const; // means surface is smaller than the requested size + Vector2D correctSmallVec() const; // returns a corrective vector for small() surfaces + Vector2D correctSmallVecBuf() const; // returns a corrective vector for small() surfaces, in BL coords + Vector2D getViewporterCorrectedSize() const; + CRegion computeDamage() const; // logical coordinates. May be wrong if the surface is unassigned + bool visible(); + bool keyboardFocusable() const; + + SP view() const; + + // desktop components misc utils + std::optional getSurfaceBoxGlobal() const; + void appendConstraint(WP constraint); + SP constraint() const; + + // allow stretching. Useful for plugins. + bool m_fillIgnoreSmall = false; + + // track surface data and avoid dupes + float m_lastScaleFloat = 0; + int m_lastScaleInt = 0; + wl_output_transform m_lastTransform = sc(-1); + + // + CWLSurface& operator=(SP pSurface) { + destroy(); + m_resource = pSurface; + init(); + + return *this; + } + + bool operator==(const CWLSurface& other) const { + return other.resource() == resource(); + } + + bool operator==(const SP other) const { + return other == resource(); + } + + explicit operator bool() const { + return exists(); + } + + static SP fromResource(SP pSurface); + + // used by the alpha-modifier protocol + float m_alphaModifier = 1.F; + + // used by the hyprland-surface protocol + float m_overallOpacity = 1.F; + CRegion m_visibleRegion; + + struct { + CSignalT<> destroy; + } m_events; + + WP m_self; + + private: + CWLSurface() = default; + + bool m_inert = true; + + WP m_resource; + + WP m_view; + + // + WP m_constraint; + + void destroy(); + void init(); + bool desktopComponent() const; + + struct { + CHyprSignalListener destroy; + } m_listeners; + + friend class ::CPointerConstraint; + friend class CXxColorManagerV4; + }; +} diff --git a/src/desktop/Window.cpp b/src/desktop/view/Window.cpp similarity index 66% rename from src/desktop/Window.cpp rename to src/desktop/view/Window.cpp index 75dc72153..e27129a1f 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/view/Window.cpp @@ -12,32 +12,35 @@ #include #include #include "Window.hpp" -#include "state/FocusState.hpp" -#include "../Compositor.hpp" -#include "../render/decorations/CHyprDropShadowDecoration.hpp" -#include "../render/decorations/CHyprGroupBarDecoration.hpp" -#include "../render/decorations/CHyprBorderDecoration.hpp" -#include "../config/ConfigValue.hpp" -#include "../config/ConfigManager.hpp" -#include "../managers/TokenManager.hpp" -#include "../managers/animation/AnimationManager.hpp" -#include "../managers/ANRManager.hpp" -#include "../managers/eventLoop/EventLoopManager.hpp" -#include "../protocols/XDGShell.hpp" -#include "../protocols/core/Compositor.hpp" -#include "../protocols/core/Subcompositor.hpp" -#include "../protocols/ContentType.hpp" -#include "../protocols/FractionalScale.hpp" -#include "../xwayland/XWayland.hpp" -#include "../helpers/Color.hpp" -#include "../helpers/math/Expression.hpp" -#include "../events/Events.hpp" -#include "../managers/XWaylandManager.hpp" -#include "../render/Renderer.hpp" -#include "../managers/LayoutManager.hpp" -#include "../managers/HookSystemManager.hpp" -#include "../managers/EventManager.hpp" -#include "../managers/input/InputManager.hpp" +#include "LayerSurface.hpp" +#include "../state/FocusState.hpp" +#include "../../Compositor.hpp" +#include "../../render/decorations/CHyprDropShadowDecoration.hpp" +#include "../../render/decorations/CHyprGroupBarDecoration.hpp" +#include "../../render/decorations/CHyprBorderDecoration.hpp" +#include "../../config/ConfigValue.hpp" +#include "../../config/ConfigManager.hpp" +#include "../../managers/TokenManager.hpp" +#include "../../managers/animation/AnimationManager.hpp" +#include "../../managers/ANRManager.hpp" +#include "../../managers/eventLoop/EventLoopManager.hpp" +#include "../../protocols/XDGShell.hpp" +#include "../../protocols/core/Compositor.hpp" +#include "../../protocols/core/Subcompositor.hpp" +#include "../../protocols/ContentType.hpp" +#include "../../protocols/FractionalScale.hpp" +#include "../../protocols/LayerShell.hpp" +#include "../../xwayland/XWayland.hpp" +#include "../../helpers/Color.hpp" +#include "../../helpers/math/Expression.hpp" +#include "../../managers/XWaylandManager.hpp" +#include "../../render/Renderer.hpp" +#include "../../managers/LayoutManager.hpp" +#include "../../managers/HookSystemManager.hpp" +#include "../../managers/EventManager.hpp" +#include "../../managers/input/InputManager.hpp" +#include "../../managers/PointerManager.hpp" +#include "../../managers/animation/DesktopAnimationManager.hpp" #include @@ -45,6 +48,9 @@ using namespace Hyprutils::String; using namespace Hyprutils::Animation; using enum NContentType::eContentType; +using namespace Desktop; +using namespace Desktop::View; + PHLWINDOW CWindow::create(SP surface) { PHLWINDOW pWindow = SP(new CWindow(surface)); @@ -92,38 +98,40 @@ PHLWINDOW CWindow::create(SP resource) { pWindow->addWindowDeco(makeUnique(pWindow)); pWindow->addWindowDeco(makeUnique(pWindow)); - pWindow->m_wlSurface->assign(pWindow->m_xdgSurface->m_surface.lock(), pWindow); + pWindow->wlSurface()->assign(pWindow->m_xdgSurface->m_surface.lock(), pWindow); return pWindow; } -CWindow::CWindow(SP resource) : m_xdgSurface(resource) { - m_wlSurface = CWLSurface::create(); - - m_listeners.map = m_xdgSurface->m_events.map.listen([this] { Events::listener_mapWindow(this, nullptr); }); +CWindow::CWindow(SP resource) : IView(CWLSurface::create()), m_xdgSurface(resource) { + m_listeners.map = m_xdgSurface->m_events.map.listen([this] { mapWindow(); }); m_listeners.ack = m_xdgSurface->m_events.ack.listen([this](uint32_t d) { onAck(d); }); - m_listeners.unmap = m_xdgSurface->m_events.unmap.listen([this] { Events::listener_unmapWindow(this, nullptr); }); - m_listeners.destroy = m_xdgSurface->m_events.destroy.listen([this] { Events::listener_destroyWindow(this, nullptr); }); - m_listeners.commit = m_xdgSurface->m_events.commit.listen([this] { Events::listener_commitWindow(this, nullptr); }); + m_listeners.unmap = m_xdgSurface->m_events.unmap.listen([this] { unmapWindow(); }); + m_listeners.destroy = m_xdgSurface->m_events.destroy.listen([this] { destroyWindow(); }); + m_listeners.commit = m_xdgSurface->m_events.commit.listen([this] { commitWindow(); }); m_listeners.updateState = m_xdgSurface->m_toplevel->m_events.stateChanged.listen([this] { onUpdateState(); }); m_listeners.updateMetadata = m_xdgSurface->m_toplevel->m_events.metadataChanged.listen([this] { onUpdateMeta(); }); } -CWindow::CWindow(SP surface) : m_xwaylandSurface(surface) { - m_wlSurface = CWLSurface::create(); - - m_listeners.map = m_xwaylandSurface->m_events.map.listen([this] { Events::listener_mapWindow(this, nullptr); }); - m_listeners.unmap = m_xwaylandSurface->m_events.unmap.listen([this] { Events::listener_unmapWindow(this, nullptr); }); - m_listeners.destroy = m_xwaylandSurface->m_events.destroy.listen([this] { Events::listener_destroyWindow(this, nullptr); }); - m_listeners.commit = m_xwaylandSurface->m_events.commit.listen([this] { Events::listener_commitWindow(this, nullptr); }); +CWindow::CWindow(SP surface) : IView(CWLSurface::create()), m_xwaylandSurface(surface) { + m_listeners.map = m_xwaylandSurface->m_events.map.listen([this] { mapWindow(); }); + m_listeners.unmap = m_xwaylandSurface->m_events.unmap.listen([this] { unmapWindow(); }); + m_listeners.destroy = m_xwaylandSurface->m_events.destroy.listen([this] { destroyWindow(); }); + m_listeners.commit = m_xwaylandSurface->m_events.commit.listen([this] { commitWindow(); }); m_listeners.configureRequest = m_xwaylandSurface->m_events.configureRequest.listen([this](const CBox& box) { onX11ConfigureRequest(box); }); m_listeners.updateState = m_xwaylandSurface->m_events.stateChanged.listen([this] { onUpdateState(); }); m_listeners.updateMetadata = m_xwaylandSurface->m_events.metadataChanged.listen([this] { onUpdateMeta(); }); m_listeners.resourceChange = m_xwaylandSurface->m_events.resourceChange.listen([this] { onResourceChangeX11(); }); - m_listeners.activate = m_xwaylandSurface->m_events.activate.listen([this] { Events::listener_activateX11(this, nullptr); }); + m_listeners.activate = m_xwaylandSurface->m_events.activate.listen([this] { activateX11(); }); if (m_xwaylandSurface->m_overrideRedirect) - m_listeners.setGeometry = m_xwaylandSurface->m_events.setGeometry.listen([this] { Events::listener_unmanagedSetGeometry(this, nullptr); }); + m_listeners.setGeometry = m_xwaylandSurface->m_events.setGeometry.listen([this] { unmanagedSetGeometry(); }); +} + +SP CWindow::fromView(SP v) { + if (!v || v->type() != VIEW_TYPE_WINDOW) + return nullptr; + return dynamicPointerCast(v); } CWindow::~CWindow() { @@ -141,7 +149,27 @@ CWindow::~CWindow() { std::erase_if(g_pHyprOpenGL->m_windowFramebuffers, [&](const auto& other) { return other.first.expired() || other.first.get() == this; }); } -SBoxExtents CWindow::getFullWindowExtents() { +eViewType CWindow::type() const { + return VIEW_TYPE_WINDOW; +} + +bool CWindow::visible() const { + return m_isMapped && !m_hidden && m_wlSurface && m_wlSurface->resource(); +} + +std::optional CWindow::logicalBox() const { + return getFullWindowBoundingBox(); +} + +bool CWindow::desktopComponent() const { + return true; +} + +std::optional CWindow::surfaceLogicalBox() const { + return getWindowMainSurfaceBox(); +} + +SBoxExtents CWindow::getFullWindowExtents() const { if (m_fadingOut) return m_originalClosedExtents; @@ -170,8 +198,8 @@ SBoxExtents CWindow::getFullWindowExtents() { CBox surfaceExtents = {0, 0, 0, 0}; // TODO: this could be better, perhaps make a getFullWindowRegion? m_popupHead->breadthfirst( - [](WP popup, void* data) { - if (!popup->m_wlSurface || !popup->m_wlSurface->resource()) + [](WP popup, void* data) { + if (!popup->wlSurface() || !popup->wlSurface()->resource()) return; CBox* pSurfaceExtents = sc(data); @@ -199,7 +227,7 @@ SBoxExtents CWindow::getFullWindowExtents() { return maxExtents; } -CBox CWindow::getFullWindowBoundingBox() { +CBox CWindow::getFullWindowBoundingBox() const { if (m_ruleApplicator->dimAround().valueOrDefault()) { if (const auto PMONITOR = m_monitor.lock(); PMONITOR) return {PMONITOR->m_position.x, PMONITOR->m_position.y, PMONITOR->m_size.x, PMONITOR->m_size.y}; @@ -249,9 +277,9 @@ CBox CWindow::getWindowIdealBoundingBoxIgnoreReserved() { SBoxExtents CWindow::getWindowExtentsUnified(uint64_t properties) { SBoxExtents extents = {.topLeft = {0, 0}, .bottomRight = {0, 0}}; - if (properties & RESERVED_EXTENTS) + if (properties & Desktop::View::RESERVED_EXTENTS) extents.addExtents(g_pDecorationPositioner->getWindowDecorationReserved(m_self)); - if (properties & INPUT_EXTENTS) + if (properties & Desktop::View::INPUT_EXTENTS) extents.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(m_self, true)); if (properties & FULL_EXTENTS) extents.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(m_self, false)); @@ -679,7 +707,7 @@ bool CWindow::hasPopupAt(const Vector2D& pos) { auto popup = m_popupHead->at(pos); - return popup && popup->m_wlSurface->resource(); + return popup && popup->wlSurface()->resource(); } void CWindow::applyGroupRules() { @@ -1048,7 +1076,7 @@ void CWindow::updateWindowData(const SWorkspaceRule& workspaceRule) { m_ruleApplicator->noShadow().matchOptional(workspaceRule.noShadow, Desktop::Types::PRIORITY_WORKSPACE_RULE); } -int CWindow::getRealBorderSize() { +int CWindow::getRealBorderSize() const { if ((m_workspace && isEffectiveInternalFSMode(FSMODE_FULLSCREEN)) || !m_ruleApplicator->decorate().valueOrDefault()) return 0; @@ -1156,7 +1184,7 @@ int CWindow::popupsCount() { return 0; int no = -1; - m_popupHead->breadthfirst([](WP p, void* d) { *sc(d) += 1; }, &no); + m_popupHead->breadthfirst([](WP p, void* d) { *sc(d) += 1; }, &no); return no; } @@ -1183,7 +1211,7 @@ bool CWindow::isFullscreen() { return m_fullscreenState.internal != FSMODE_NONE; } -bool CWindow::isEffectiveInternalFSMode(const eFullscreenMode MODE) { +bool CWindow::isEffectiveInternalFSMode(const eFullscreenMode MODE) const { return sc(std::bit_floor(sc(m_fullscreenState.internal))) == MODE; } @@ -1877,3 +1905,799 @@ std::optional CWindow::calculateExpression(const std::string& s) { return Vector2D{*LHS, *RHS}; } + +static void setVector2DAnimToMove(WP pav) { + const auto PAV = pav.lock(); + if (!PAV) + return; + + CAnimatedVariable* animvar = dc*>(PAV.get()); + animvar->setConfig(g_pConfigManager->getAnimationPropertyConfig("windowsMove")); + + const auto PHLWINDOW = animvar->m_Context.pWindow.lock(); + if (PHLWINDOW) + PHLWINDOW->m_animatingIn = false; +} + +void CWindow::mapWindow() { + static auto PINACTIVEALPHA = CConfigValue("decoration:inactive_opacity"); + static auto PACTIVEALPHA = CConfigValue("decoration:active_opacity"); + static auto PDIMSTRENGTH = CConfigValue("decoration:dim_strength"); + static auto PNEWTAKESOVERFS = CConfigValue("misc:on_focus_under_fullscreen"); + static auto PINITIALWSTRACKING = CConfigValue("misc:initial_workspace_tracking"); + + auto PMONITOR = Desktop::focusState()->monitor(); + if (!Desktop::focusState()->monitor()) { + Desktop::focusState()->rawMonitorFocus(g_pCompositor->getMonitorFromVector({})); + PMONITOR = Desktop::focusState()->monitor(); + } + auto PWORKSPACE = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace; + m_monitor = PMONITOR; + m_workspace = PWORKSPACE; + m_isMapped = true; + m_readyToDelete = false; + m_fadingOut = false; + m_title = fetchTitle(); + m_firstMap = true; + m_initialTitle = m_title; + m_initialClass = fetchClass(); + + // check for token + std::string requestedWorkspace = ""; + bool workspaceSilent = false; + + if (*PINITIALWSTRACKING) { + const auto WINDOWENV = getEnv(); + if (WINDOWENV.contains("HL_INITIAL_WORKSPACE_TOKEN")) { + const auto SZTOKEN = WINDOWENV.at("HL_INITIAL_WORKSPACE_TOKEN"); + Debug::log(LOG, "New window contains HL_INITIAL_WORKSPACE_TOKEN: {}", SZTOKEN); + const auto TOKEN = g_pTokenManager->getToken(SZTOKEN); + if (TOKEN) { + // find workspace and use it + Desktop::View::SInitialWorkspaceToken WS = std::any_cast(TOKEN->m_data); + + Debug::log(LOG, "HL_INITIAL_WORKSPACE_TOKEN {} -> {}", SZTOKEN, WS.workspace); + + if (g_pCompositor->getWorkspaceByString(WS.workspace) != m_workspace) { + requestedWorkspace = WS.workspace; + workspaceSilent = true; + } + + if (*PINITIALWSTRACKING == 1) // one-shot token + g_pTokenManager->removeToken(TOKEN); + else if (*PINITIALWSTRACKING == 2) { // persistent + if (WS.primaryOwner.expired()) { + WS.primaryOwner = m_self.lock(); + TOKEN->m_data = WS; + } + + m_initialWorkspaceToken = SZTOKEN; + } + } + } + } + + if (g_pInputManager->m_lastFocusOnLS) // waybar fix + g_pInputManager->releaseAllMouseButtons(); + + // checks if the window wants borders and sets the appropriate flag + g_pXWaylandManager->checkBorders(m_self.lock()); + + // registers the animated vars and stuff + onMap(); + + if (g_pXWaylandManager->shouldBeFloated(m_self.lock())) { + m_isFloating = true; + m_requestsFloat = true; + } + + m_X11ShouldntFocus = m_X11ShouldntFocus || (m_isX11 && isX11OverrideRedirect() && !m_xwaylandSurface->wantsFocus()); + + // window rules + std::optional requestedInternalFSMode, requestedClientFSMode; + std::optional requestedFSState; + if (m_wantsInitialFullscreen || (m_isX11 && m_xwaylandSurface->m_fullscreen)) + requestedClientFSMode = FSMODE_FULLSCREEN; + MONITORID requestedFSMonitor = m_wantsInitialFullscreenMonitor; + + m_ruleApplicator->readStaticRules(); + { + if (!m_ruleApplicator->static_.monitor.empty()) { + const auto& MONITORSTR = m_ruleApplicator->static_.monitor; + if (MONITORSTR == "unset") + m_monitor = PMONITOR; + else { + const auto MONITOR = g_pCompositor->getMonitorFromString(MONITORSTR); + + if (MONITOR) { + m_monitor = MONITOR; + + const auto PMONITORFROMID = m_monitor.lock(); + + if (m_monitor != PMONITOR) { + g_pKeybindManager->m_dispatchers["focusmonitor"](std::to_string(monitorID())); + PMONITOR = PMONITORFROMID; + } + m_workspace = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace; + PWORKSPACE = m_workspace; + + Debug::log(LOG, "Rule monitor, applying to {:mw}", m_self.lock()); + requestedFSMonitor = MONITOR_INVALID; + } else + Debug::log(ERR, "No monitor in monitor {} rule", MONITORSTR); + } + } + + if (!m_ruleApplicator->static_.workspace.empty()) { + const auto WORKSPACERQ = m_ruleApplicator->static_.workspace; + + if (WORKSPACERQ == "unset") + requestedWorkspace = ""; + else + requestedWorkspace = WORKSPACERQ; + + const auto JUSTWORKSPACE = WORKSPACERQ.contains(' ') ? WORKSPACERQ.substr(0, WORKSPACERQ.find_first_of(' ')) : WORKSPACERQ; + + if (JUSTWORKSPACE == PWORKSPACE->m_name || JUSTWORKSPACE == "name:" + PWORKSPACE->m_name) + requestedWorkspace = ""; + + Debug::log(LOG, "Rule workspace matched by {}, {} applied.", m_self.lock(), m_ruleApplicator->static_.workspace); + requestedFSMonitor = MONITOR_INVALID; + } + + if (m_ruleApplicator->static_.floating.has_value()) + m_isFloating = m_ruleApplicator->static_.floating.value(); + + if (m_ruleApplicator->static_.pseudo) + m_isPseudotiled = true; + + if (m_ruleApplicator->static_.noInitialFocus) + m_noInitialFocus = true; + + if (m_ruleApplicator->static_.fullscreenStateClient || m_ruleApplicator->static_.fullscreenStateInternal) { + requestedFSState = Desktop::View::SFullscreenState{ + .internal = sc(m_ruleApplicator->static_.fullscreenStateInternal.value_or(0)), + .client = sc(m_ruleApplicator->static_.fullscreenStateClient.value_or(0)), + }; + } + + if (!m_ruleApplicator->static_.suppressEvent.empty()) { + for (const auto& var : m_ruleApplicator->static_.suppressEvent) { + if (var == "fullscreen") + m_suppressedEvents |= Desktop::View::SUPPRESS_FULLSCREEN; + else if (var == "maximize") + m_suppressedEvents |= Desktop::View::SUPPRESS_MAXIMIZE; + else if (var == "activate") + m_suppressedEvents |= Desktop::View::SUPPRESS_ACTIVATE; + else if (var == "activatefocus") + m_suppressedEvents |= Desktop::View::SUPPRESS_ACTIVATE_FOCUSONLY; + else if (var == "fullscreenoutput") + m_suppressedEvents |= Desktop::View::SUPPRESS_FULLSCREEN_OUTPUT; + else + Debug::log(ERR, "Error while parsing suppressevent windowrule: unknown event type {}", var); + } + } + + if (m_ruleApplicator->static_.pin) + m_pinned = true; + + if (m_ruleApplicator->static_.fullscreen) + requestedInternalFSMode = FSMODE_FULLSCREEN; + + if (m_ruleApplicator->static_.maximize) + requestedInternalFSMode = FSMODE_MAXIMIZED; + + if (!m_ruleApplicator->static_.group.empty()) { + if (!(m_groupRules & Desktop::View::GROUP_OVERRIDE) && trim(m_ruleApplicator->static_.group) != "group") { + CVarList2 vars(std::string{m_ruleApplicator->static_.group}, 0, 's'); + std::string vPrev = ""; + + for (auto const& v : vars) { + if (v == "group") + continue; + + if (v == "set") { + m_groupRules |= Desktop::View::GROUP_SET; + } else if (v == "new") { + // shorthand for `group barred set` + m_groupRules |= (Desktop::View::GROUP_SET | Desktop::View::GROUP_BARRED); + } else if (v == "lock") { + m_groupRules |= Desktop::View::GROUP_LOCK; + } else if (v == "invade") { + m_groupRules |= Desktop::View::GROUP_INVADE; + } else if (v == "barred") { + m_groupRules |= Desktop::View::GROUP_BARRED; + } else if (v == "deny") { + m_groupData.deny = true; + } else if (v == "override") { + // Clear existing rules + m_groupRules = Desktop::View::GROUP_OVERRIDE; + } else if (v == "unset") { + // Clear existing rules and stop processing + m_groupRules = Desktop::View::GROUP_OVERRIDE; + break; + } else if (v == "always") { + if (vPrev == "set" || vPrev == "group") + m_groupRules |= Desktop::View::GROUP_SET_ALWAYS; + else if (vPrev == "lock") + m_groupRules |= Desktop::View::GROUP_LOCK_ALWAYS; + else + Debug::log(ERR, "windowrule `group` does not support `{} always`", vPrev); + } + vPrev = v; + } + } + } + + if (m_ruleApplicator->static_.content) + setContentType(sc(m_ruleApplicator->static_.content.value())); + + if (m_ruleApplicator->static_.noCloseFor) + m_closeableSince = Time::steadyNow() + std::chrono::milliseconds(m_ruleApplicator->static_.noCloseFor.value()); + } + + // make it uncloseable if it's a Hyprland dialog + // TODO: make some closeable? + if (CAsyncDialogBox::isAsyncDialogBox(getPID())) + m_closeableSince = Time::steadyNow() + std::chrono::years(10 /* Should be enough, no? */); + + // disallow tiled pinned + if (m_pinned && !m_isFloating) + m_pinned = false; + + CVarList2 WORKSPACEARGS = CVarList2(std::move(requestedWorkspace), 0, ' ', false, false); + + if (!WORKSPACEARGS[0].empty()) { + WORKSPACEID requestedWorkspaceID; + std::string requestedWorkspaceName; + if (WORKSPACEARGS.contains("silent")) + workspaceSilent = true; + + if (WORKSPACEARGS.contains("empty") && PWORKSPACE->getWindows() <= 1) { + requestedWorkspaceID = PWORKSPACE->m_id; + requestedWorkspaceName = PWORKSPACE->m_name; + } else { + auto result = getWorkspaceIDNameFromString(WORKSPACEARGS.join(" ", 0, workspaceSilent ? WORKSPACEARGS.size() - 1 : 0)); + requestedWorkspaceID = result.id; + requestedWorkspaceName = result.name; + } + + if (requestedWorkspaceID != WORKSPACE_INVALID) { + auto pWorkspace = g_pCompositor->getWorkspaceByID(requestedWorkspaceID); + + if (!pWorkspace) + pWorkspace = g_pCompositor->createNewWorkspace(requestedWorkspaceID, monitorID(), requestedWorkspaceName, false); + + PWORKSPACE = pWorkspace; + + m_workspace = pWorkspace; + m_monitor = pWorkspace->m_monitor; + + if (m_monitor.lock()->m_activeSpecialWorkspace && !pWorkspace->m_isSpecialWorkspace) + workspaceSilent = true; + + if (!workspaceSilent) { + if (pWorkspace->m_isSpecialWorkspace) + pWorkspace->m_monitor->setSpecialWorkspace(pWorkspace); + else if (PMONITOR->activeWorkspaceID() != requestedWorkspaceID && !m_noInitialFocus) + g_pKeybindManager->m_dispatchers["workspace"](requestedWorkspaceName); + + PMONITOR = Desktop::focusState()->monitor(); + } + + requestedFSMonitor = MONITOR_INVALID; + } else + workspaceSilent = false; + } + + if (m_suppressedEvents & Desktop::View::SUPPRESS_FULLSCREEN_OUTPUT) + requestedFSMonitor = MONITOR_INVALID; + else if (requestedFSMonitor != MONITOR_INVALID) { + if (const auto PM = g_pCompositor->getMonitorFromID(requestedFSMonitor); PM) + m_monitor = PM; + + const auto PMONITORFROMID = m_monitor.lock(); + + if (m_monitor != PMONITOR) { + g_pKeybindManager->m_dispatchers["focusmonitor"](std::to_string(monitorID())); + PMONITOR = PMONITORFROMID; + } + m_workspace = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace; + PWORKSPACE = m_workspace; + + Debug::log(LOG, "Requested monitor, applying to {:mw}", m_self.lock()); + } + + if (PWORKSPACE->m_defaultFloating) + m_isFloating = true; + + if (PWORKSPACE->m_defaultPseudo) { + m_isPseudotiled = true; + CBox desiredGeometry = g_pXWaylandManager->getGeometryForWindow(m_self.lock()); + m_pseudoSize = Vector2D(desiredGeometry.width, desiredGeometry.height); + } + + updateWindowData(); + + // Verify window swallowing. Get the swallower before calling onWindowCreated(m_self.lock()) because getSwallower() wouldn't get it after if m_self.lock() gets auto grouped. + const auto SWALLOWER = getSwallower(); + m_swallowed = SWALLOWER; + if (m_swallowed) + m_swallowed->m_currentlySwallowed = true; + + // emit the IPC event before the layout might focus the window to avoid a focus event first + g_pEventManager->postEvent(SHyprIPCEvent{"openwindow", std::format("{:x},{},{},{}", m_self.lock(), PWORKSPACE->m_name, m_class, m_title)}); + EMIT_HOOK_EVENT("openWindowEarly", m_self.lock()); + + if (m_isFloating) { + g_pLayoutManager->getCurrentLayout()->onWindowCreated(m_self.lock()); + m_createdOverFullscreen = true; + + if (!m_ruleApplicator->static_.size.empty()) { + const auto COMPUTED = calculateExpression(m_ruleApplicator->static_.size); + if (!COMPUTED) + Debug::log(ERR, "failed to parse {} as an expression", m_ruleApplicator->static_.size); + else { + *m_realSize = *COMPUTED; + setHidden(false); + } + } + + if (!m_ruleApplicator->static_.position.empty()) { + const auto COMPUTED = calculateExpression(m_ruleApplicator->static_.position); + if (!COMPUTED) + Debug::log(ERR, "failed to parse {} as an expression", m_ruleApplicator->static_.position); + else { + *m_realPosition = *COMPUTED + PMONITOR->m_position; + setHidden(false); + } + } + + if (m_ruleApplicator->static_.center) { + const auto WORKAREA = PMONITOR->logicalBoxMinusReserved(); + *m_realPosition = WORKAREA.middle() - m_realSize->goal() / 2.f; + } + + // set the pseudo size to the GOAL of our current size + // because the windows are animated on RealSize + m_pseudoSize = m_realSize->goal(); + + g_pCompositor->changeWindowZOrder(m_self.lock(), true); + } else { + g_pLayoutManager->getCurrentLayout()->onWindowCreated(m_self.lock()); + + bool setPseudo = false; + + if (!m_ruleApplicator->static_.size.empty()) { + const auto COMPUTED = calculateExpression(m_ruleApplicator->static_.size); + if (!COMPUTED) + Debug::log(ERR, "failed to parse {} as an expression", m_ruleApplicator->static_.size); + else { + setPseudo = true; + m_pseudoSize = *COMPUTED; + setHidden(false); + } + } + + if (!setPseudo) + m_pseudoSize = m_realSize->goal() - Vector2D(10, 10); + } + + const auto PFOCUSEDWINDOWPREV = Desktop::focusState()->window(); + + if (m_ruleApplicator->allowsInput().valueOrDefault()) { // if default value wasn't set to false getPriority() would throw an exception + m_ruleApplicator->noFocusOverride(Desktop::Types::COverridableVar(false, m_ruleApplicator->allowsInput().getPriority())); + m_noInitialFocus = false; + m_X11ShouldntFocus = false; + } + + // check LS focus grab + const auto PFORCEFOCUS = g_pCompositor->getForceFocus(); + const auto PLSFROMFOCUS = g_pCompositor->getLayerSurfaceFromSurface(Desktop::focusState()->surface()); + if (PLSFROMFOCUS && PLSFROMFOCUS->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE) + m_noInitialFocus = true; + + if (m_workspace->m_hasFullscreenWindow && !requestedInternalFSMode.has_value() && !requestedClientFSMode.has_value() && !m_isFloating) { + if (*PNEWTAKESOVERFS == 0) + m_noInitialFocus = true; + else if (*PNEWTAKESOVERFS == 1) + requestedInternalFSMode = m_workspace->m_fullscreenMode; + else if (*PNEWTAKESOVERFS == 2) + g_pCompositor->setWindowFullscreenInternal(m_workspace->getFullscreenWindow(), FSMODE_NONE); + } + + if (!m_ruleApplicator->noFocus().valueOrDefault() && !m_noInitialFocus && (!isX11OverrideRedirect() || (m_isX11 && m_xwaylandSurface->wantsFocus())) && !workspaceSilent && + (!PFORCEFOCUS || PFORCEFOCUS == m_self.lock()) && !g_pInputManager->isConstrained()) { + Desktop::focusState()->fullWindowFocus(m_self.lock()); + m_activeInactiveAlpha->setValueAndWarp(*PACTIVEALPHA); + m_dimPercent->setValueAndWarp(m_ruleApplicator->noDim().valueOrDefault() ? 0.f : *PDIMSTRENGTH); + } else { + m_activeInactiveAlpha->setValueAndWarp(*PINACTIVEALPHA); + m_dimPercent->setValueAndWarp(0); + } + + if (requestedClientFSMode.has_value() && (m_suppressedEvents & Desktop::View::SUPPRESS_FULLSCREEN)) + requestedClientFSMode = sc(sc(requestedClientFSMode.value_or(FSMODE_NONE)) & ~sc(FSMODE_FULLSCREEN)); + if (requestedClientFSMode.has_value() && (m_suppressedEvents & Desktop::View::SUPPRESS_MAXIMIZE)) + requestedClientFSMode = sc(sc(requestedClientFSMode.value_or(FSMODE_NONE)) & ~sc(FSMODE_MAXIMIZED)); + + if (!m_noInitialFocus && (requestedInternalFSMode.has_value() || requestedClientFSMode.has_value() || requestedFSState.has_value())) { + // fix fullscreen on requested (basically do a switcheroo) + if (m_workspace->m_hasFullscreenWindow) + g_pCompositor->setWindowFullscreenInternal(m_workspace->getFullscreenWindow(), FSMODE_NONE); + + m_realPosition->warp(); + m_realSize->warp(); + if (requestedFSState.has_value()) { + m_ruleApplicator->syncFullscreenOverride(Desktop::Types::COverridableVar(false, Desktop::Types::PRIORITY_WINDOW_RULE)); + g_pCompositor->setWindowFullscreenState(m_self.lock(), requestedFSState.value()); + } else if (requestedInternalFSMode.has_value() && requestedClientFSMode.has_value() && !m_ruleApplicator->syncFullscreen().valueOrDefault()) + g_pCompositor->setWindowFullscreenState(m_self.lock(), + Desktop::View::SFullscreenState{.internal = requestedInternalFSMode.value(), .client = requestedClientFSMode.value()}); + else if (requestedInternalFSMode.has_value()) + g_pCompositor->setWindowFullscreenInternal(m_self.lock(), requestedInternalFSMode.value()); + else if (requestedClientFSMode.has_value()) + g_pCompositor->setWindowFullscreenClient(m_self.lock(), requestedClientFSMode.value()); + } + + // recheck idle inhibitors + g_pInputManager->recheckIdleInhibitorStatus(); + + updateToplevel(); + m_ruleApplicator->propertiesChanged(Desktop::Rule::RULE_PROP_ALL); + + if (workspaceSilent) { + if (validMapped(PFOCUSEDWINDOWPREV)) { + Desktop::focusState()->rawWindowFocus(PFOCUSEDWINDOWPREV); + PFOCUSEDWINDOWPREV->updateWindowDecos(); // need to for some reason i cba to find out why + } else if (!PFOCUSEDWINDOWPREV) + Desktop::focusState()->rawWindowFocus(nullptr); + } + + // swallow + if (SWALLOWER) { + g_pLayoutManager->getCurrentLayout()->onWindowRemoved(SWALLOWER); + g_pHyprRenderer->damageWindow(SWALLOWER); + SWALLOWER->setHidden(true); + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(monitorID()); + } + + m_firstMap = false; + + Debug::log(LOG, "Map request dispatched, monitor {}, window pos: {:5j}, window size: {:5j}", PMONITOR->m_name, m_realPosition->goal(), m_realSize->goal()); + + // emit the hook event here after basic stuff has been initialized + EMIT_HOOK_EVENT("openWindow", m_self.lock()); + + // apply data from default decos. Borders, shadows. + g_pDecorationPositioner->forceRecalcFor(m_self.lock()); + updateWindowDecos(); + g_pLayoutManager->getCurrentLayout()->recalculateWindow(m_self.lock()); + + // do animations + g_pDesktopAnimationManager->startAnimation(m_self.lock(), CDesktopAnimationManager::ANIMATION_TYPE_IN); + + m_realPosition->setCallbackOnEnd(setVector2DAnimToMove); + m_realSize->setCallbackOnEnd(setVector2DAnimToMove); + + // recalc the values for this window + updateDecorationValues(); + // avoid this window being visible + if (PWORKSPACE->m_hasFullscreenWindow && !isFullscreen() && !m_isFloating) + m_alpha->setValueAndWarp(0.f); + + g_pCompositor->setPreferredScaleForSurface(wlSurface()->resource(), PMONITOR->m_scale); + g_pCompositor->setPreferredTransformForSurface(wlSurface()->resource(), PMONITOR->m_transform); + + if (g_pSeatManager->m_mouse.expired() || !g_pInputManager->isConstrained()) + g_pInputManager->sendMotionEventsToFocused(); + + // fix some xwayland apps that don't behave nicely + m_reportedSize = m_pendingReportedSize; + + if (m_workspace) + m_workspace->updateWindows(); + + if (PMONITOR && isX11OverrideRedirect()) + m_X11SurfaceScaledBy = PMONITOR->m_scale; +} + +void CWindow::unmapWindow() { + Debug::log(LOG, "{:c} unmapped", m_self.lock()); + + static auto PEXITRETAINSFS = CConfigValue("misc:exit_window_retains_fullscreen"); + + const auto CURRENTWINDOWFSSTATE = isFullscreen(); + const auto CURRENTFSMODE = m_fullscreenState.internal; + + if (!wlSurface()->exists() || !m_isMapped) { + Debug::log(WARN, "{} unmapped without being mapped??", m_self.lock()); + m_fadingOut = false; + return; + } + + const auto PMONITOR = m_monitor.lock(); + if (PMONITOR) { + m_originalClosedPos = m_realPosition->value() - PMONITOR->m_position; + m_originalClosedSize = m_realSize->value(); + m_originalClosedExtents = getFullWindowExtents(); + } + + g_pEventManager->postEvent(SHyprIPCEvent{"closewindow", std::format("{:x}", m_self.lock())}); + EMIT_HOOK_EVENT("closeWindow", m_self.lock()); + + if (m_isFloating && !m_isX11 && m_ruleApplicator->persistentSize().valueOrDefault()) { + Debug::log(LOG, "storing floating size {}x{} for window {}::{} on close", m_realSize->value().x, m_realSize->value().y, m_class, m_title); + g_pConfigManager->storeFloatingSize(m_self.lock(), m_realSize->value()); + } + + if (isFullscreen()) + g_pCompositor->setWindowFullscreenInternal(m_self.lock(), FSMODE_NONE); + + // Allow the renderer to catch the last frame. + if (g_pHyprRenderer->shouldRenderWindow(m_self.lock())) + g_pHyprRenderer->makeSnapshot(m_self.lock()); + + // swallowing + if (valid(m_swallowed)) { + if (m_swallowed->m_currentlySwallowed) { + m_swallowed->m_currentlySwallowed = false; + m_swallowed->setHidden(false); + + if (m_groupData.pNextWindow.lock()) + m_swallowed->m_groupSwallowed = true; // flag for the swallowed window to be created into the group where it belongs when auto_group = false. + + g_pLayoutManager->getCurrentLayout()->onWindowCreated(m_swallowed.lock()); + } + + m_swallowed->m_groupSwallowed = false; + m_swallowed.reset(); + } + + bool wasLastWindow = false; + + if (m_self.lock() == Desktop::focusState()->window()) { + wasLastWindow = true; + Desktop::focusState()->window().reset(); + Desktop::focusState()->surface().reset(); + + g_pInputManager->releaseAllMouseButtons(); + } + + if (m_self.lock() == g_pInputManager->m_currentlyDraggedWindow.lock()) + CKeybindManager::changeMouseBindMode(MBIND_INVALID); + + // remove the fullscreen window status from workspace if we closed it + const auto PWORKSPACE = m_workspace; + + if (PWORKSPACE->m_hasFullscreenWindow && isFullscreen()) + PWORKSPACE->m_hasFullscreenWindow = false; + + g_pLayoutManager->getCurrentLayout()->onWindowRemoved(m_self.lock()); + + g_pHyprRenderer->damageWindow(m_self.lock()); + + // do this after onWindowRemoved because otherwise it'll think the window is invalid + m_isMapped = false; + + // refocus on a new window if needed + if (wasLastWindow) { + static auto FOCUSONCLOSE = CConfigValue("input:focus_on_close"); + PHLWINDOW PWINDOWCANDIDATE = nullptr; + if (*FOCUSONCLOSE) + PWINDOWCANDIDATE = (g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), + Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING)); + else + PWINDOWCANDIDATE = g_pLayoutManager->getCurrentLayout()->getNextWindowCandidate(m_self.lock()); + + Debug::log(LOG, "On closed window, new focused candidate is {}", PWINDOWCANDIDATE); + + if (PWINDOWCANDIDATE != Desktop::focusState()->window() && PWINDOWCANDIDATE) { + Desktop::focusState()->fullWindowFocus(PWINDOWCANDIDATE); + if (*PEXITRETAINSFS && CURRENTWINDOWFSSTATE) + g_pCompositor->setWindowFullscreenInternal(PWINDOWCANDIDATE, CURRENTFSMODE); + } + + if (!PWINDOWCANDIDATE && m_workspace && m_workspace->getWindows() == 0) + g_pInputManager->refocus(); + + g_pInputManager->sendMotionEventsToFocused(); + + // CWindow::onUnmap will remove this window's active status, but we can't really do it above. + if (m_self.lock() == Desktop::focusState()->window() || !Desktop::focusState()->window()) { + g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", ","}); + g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", ""}); + EMIT_HOOK_EVENT("activeWindow", PHLWINDOW{nullptr}); + } + } else { + Debug::log(LOG, "Unmapped was not focused, ignoring a refocus."); + } + + m_fadingOut = true; + + g_pCompositor->addToFadingOutSafe(m_self.lock()); + + if (!m_X11DoesntWantBorders) // don't animate out if they weren't animated in. + *m_realPosition = m_realPosition->value() + Vector2D(0.01f, 0.01f); // it has to be animated, otherwise CesktopAnimationManager will ignore it + + // anims + g_pDesktopAnimationManager->startAnimation(m_self.lock(), CDesktopAnimationManager::ANIMATION_TYPE_OUT); + + // recheck idle inhibitors + g_pInputManager->recheckIdleInhibitorStatus(); + + // force report all sizes (QT sometimes has an issue with this) + if (m_workspace) + m_workspace->forceReportSizesToWindows(); + + // update lastwindow after focus + onUnmap(); +} + +void CWindow::commitWindow() { + if (!m_isX11 && m_xdgSurface->m_initialCommit) { + Vector2D predSize = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(m_self.lock()); + + Debug::log(LOG, "Layout predicts size {} for {}", predSize, m_self.lock()); + + m_xdgSurface->m_toplevel->setSize(predSize); + return; + } + + if (!m_isMapped || isHidden()) + return; + + if (m_isX11) + m_reportedSize = m_pendingReportedSize; + + if (!m_isX11 && !isFullscreen() && m_isFloating) { + const auto MINSIZE = m_xdgSurface->m_toplevel->layoutMinSize(); + const auto MAXSIZE = m_xdgSurface->m_toplevel->layoutMaxSize(); + + clampWindowSize(MINSIZE, MAXSIZE > Vector2D{1, 1} ? std::optional{MAXSIZE} : std::nullopt); + g_pHyprRenderer->damageWindow(m_self.lock()); + } + + if (!m_workspace->m_visible) + return; + + const auto PMONITOR = m_monitor.lock(); + + if (PMONITOR) + PMONITOR->debugLastPresentation(g_pSeatManager->m_isPointerFrameCommit ? "listener_commitWindow skip" : "listener_commitWindow"); + + if (g_pSeatManager->m_isPointerFrameCommit) { + g_pSeatManager->m_isPointerFrameSkipped = false; + g_pSeatManager->m_isPointerFrameCommit = false; + } else + g_pHyprRenderer->damageSurface(wlSurface()->resource(), m_realPosition->goal().x, m_realPosition->goal().y, m_isX11 ? 1.0 / m_X11SurfaceScaledBy : 1.0); + + if (g_pSeatManager->m_isPointerFrameSkipped) { + g_pPointerManager->sendStoredMovement(); + g_pSeatManager->sendPointerFrame(); + g_pSeatManager->m_isPointerFrameCommit = true; + } + + if (!m_isX11) { + m_subsurfaceHead->recheckDamageForSubsurfaces(); + m_popupHead->recheckTree(); + } + + // tearing: if solitary, redraw it. This still might be a single surface window + if (PMONITOR && PMONITOR->m_solitaryClient.lock() == m_self.lock() && canBeTorn() && PMONITOR->m_tearingState.canTear && wlSurface()->resource()->m_current.texture) { + CRegion damageBox{wlSurface()->resource()->m_current.accumulateBufferDamage()}; + + if (!damageBox.empty()) { + if (PMONITOR->m_tearingState.busy) { + PMONITOR->m_tearingState.frameScheduledWhileBusy = true; + } else { + PMONITOR->m_tearingState.nextRenderTorn = true; + g_pHyprRenderer->renderMonitor(PMONITOR); + } + } + } +} + +void CWindow::destroyWindow() { + Debug::log(LOG, "{:c} destroyed, queueing.", m_self.lock()); + + if (m_self.lock() == Desktop::focusState()->window()) { + Desktop::focusState()->window().reset(); + Desktop::focusState()->surface().reset(); + } + + wlSurface()->unassign(); + + m_listeners = {}; + + g_pLayoutManager->getCurrentLayout()->onWindowRemoved(m_self.lock()); + + m_readyToDelete = true; + + m_xdgSurface.reset(); + + if (!m_fadingOut) { + Debug::log(LOG, "Unmapped {} removed instantly", m_self.lock()); + g_pCompositor->removeWindowFromVectorSafe(m_self.lock()); // most likely X11 unmanaged or sumn + } + + m_listeners.unmap.reset(); + m_listeners.destroy.reset(); + m_listeners.map.reset(); + m_listeners.commit.reset(); +} + +void CWindow::activateX11() { + Debug::log(LOG, "X11 Activate request for window {}", m_self.lock()); + + if (isX11OverrideRedirect()) { + + Debug::log(LOG, "Unmanaged X11 {} requests activate", m_self.lock()); + + if (Desktop::focusState()->window() && Desktop::focusState()->window()->getPID() != getPID()) + return; + + if (!m_xwaylandSurface->wantsFocus()) + return; + + Desktop::focusState()->fullWindowFocus(m_self.lock()); + return; + } + + if (m_self.lock() == Desktop::focusState()->window() || (m_suppressedEvents & Desktop::View::SUPPRESS_ACTIVATE)) + return; + + activate(); +} + +void CWindow::unmanagedSetGeometry() { + if (!m_isMapped || !m_xwaylandSurface || !m_xwaylandSurface->m_overrideRedirect) + return; + + const auto POS = m_realPosition->goal(); + const auto SIZ = m_realSize->goal(); + + if (m_xwaylandSurface->m_geometry.size() > Vector2D{1, 1}) + setHidden(false); + else + setHidden(true); + + if (isFullscreen() || !m_isFloating) { + sendWindowSize(true); + g_pHyprRenderer->damageWindow(m_self.lock()); + return; + } + + static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); + + const auto LOGICALPOS = g_pXWaylandManager->xwaylandToWaylandCoords(m_xwaylandSurface->m_geometry.pos()); + + if (abs(std::floor(POS.x) - LOGICALPOS.x) > 2 || abs(std::floor(POS.y) - LOGICALPOS.y) > 2 || abs(std::floor(SIZ.x) - m_xwaylandSurface->m_geometry.width) > 2 || + abs(std::floor(SIZ.y) - m_xwaylandSurface->m_geometry.height) > 2) { + Debug::log(LOG, "Unmanaged window {} requests geometry update to {:j} {:j}", m_self.lock(), LOGICALPOS, m_xwaylandSurface->m_geometry.size()); + + g_pHyprRenderer->damageWindow(m_self.lock()); + m_realPosition->setValueAndWarp(Vector2D(LOGICALPOS.x, LOGICALPOS.y)); + + if (abs(std::floor(SIZ.x) - m_xwaylandSurface->m_geometry.w) > 2 || abs(std::floor(SIZ.y) - m_xwaylandSurface->m_geometry.h) > 2) + m_realSize->setValueAndWarp(m_xwaylandSurface->m_geometry.size()); + + if (*PXWLFORCESCALEZERO) { + if (const auto PMONITOR = m_monitor.lock(); PMONITOR) { + m_realSize->setValueAndWarp(m_realSize->goal() / PMONITOR->m_scale); + } + } + + m_position = m_realPosition->goal(); + m_size = m_realSize->goal(); + + m_workspace = g_pCompositor->getMonitorFromVector(m_realPosition->value() + m_realSize->value() / 2.f)->m_activeWorkspace; + + g_pCompositor->changeWindowZOrder(m_self.lock(), true); + updateWindowDecos(); + g_pHyprRenderer->damageWindow(m_self.lock()); + + m_reportedPosition = m_realPosition->goal(); + m_pendingReportedSize = m_realSize->goal(); + } +} diff --git a/src/desktop/view/Window.hpp b/src/desktop/view/Window.hpp new file mode 100644 index 000000000..e1a42eda5 --- /dev/null +++ b/src/desktop/view/Window.hpp @@ -0,0 +1,454 @@ +#pragma once + +#include +#include +#include + +#include "View.hpp" +#include "../../config/ConfigDataValues.hpp" +#include "../../helpers/AnimatedVariable.hpp" +#include "../../helpers/TagKeeper.hpp" +#include "../../macros.hpp" +#include "../../managers/XWaylandManager.hpp" +#include "../../render/decorations/IHyprWindowDecoration.hpp" +#include "../../render/Transformer.hpp" +#include "../DesktopTypes.hpp" +#include "Popup.hpp" +#include "Subsurface.hpp" +#include "WLSurface.hpp" +#include "../Workspace.hpp" +#include "../rule/windowRule/WindowRuleApplicator.hpp" +#include "../../protocols/types/ContentType.hpp" + +class CXDGSurfaceResource; +class CXWaylandSurface; +struct SWorkspaceRule; + +class IWindowTransformer; + +namespace Desktop::View { + + enum eGroupRules : uint8_t { + // effective only during first map, except for _ALWAYS variant + GROUP_NONE = 0, + GROUP_SET = 1 << 0, // Open as new group or add to focused group + GROUP_SET_ALWAYS = 1 << 1, + GROUP_BARRED = 1 << 2, // Don't insert to focused group. + GROUP_LOCK = 1 << 3, // Lock m_sGroupData.lock + GROUP_LOCK_ALWAYS = 1 << 4, + GROUP_INVADE = 1 << 5, // Force enter a group, event if lock is engaged + GROUP_OVERRIDE = 1 << 6, // Override other rules + }; + + enum eGetWindowProperties : uint8_t { + WINDOW_ONLY = 0, + RESERVED_EXTENTS = 1 << 0, + INPUT_EXTENTS = 1 << 1, + FULL_EXTENTS = 1 << 2, + FLOATING_ONLY = 1 << 3, + ALLOW_FLOATING = 1 << 4, + USE_PROP_TILED = 1 << 5, + SKIP_FULLSCREEN_PRIORITY = 1 << 6, + FOCUS_PRIORITY = 1 << 7, + }; + + enum eSuppressEvents : uint8_t { + SUPPRESS_NONE = 0, + SUPPRESS_FULLSCREEN = 1 << 0, + SUPPRESS_MAXIMIZE = 1 << 1, + SUPPRESS_ACTIVATE = 1 << 2, + SUPPRESS_ACTIVATE_FOCUSONLY = 1 << 3, + SUPPRESS_FULLSCREEN_OUTPUT = 1 << 4, + }; + + struct SInitialWorkspaceToken { + PHLWINDOWREF primaryOwner; + std::string workspace; + }; + + struct SFullscreenState { + eFullscreenMode internal = FSMODE_NONE; + eFullscreenMode client = FSMODE_NONE; + }; + + class CWindow : public IView { + public: + static PHLWINDOW create(SP); + static PHLWINDOW create(SP); + static PHLWINDOW fromView(SP); + + private: + CWindow(SP resource); + CWindow(SP surface); + + public: + virtual ~CWindow(); + + virtual eViewType type() const; + virtual bool visible() const; + virtual std::optional logicalBox() const; + virtual bool desktopComponent() const; + virtual std::optional surfaceLogicalBox() const; + + struct { + CSignalT<> destroy; + } m_events; + + WP m_xdgSurface; + WP m_xwaylandSurface; + + // this is the position and size of the "bounding box" + Vector2D m_position = Vector2D(0, 0); + Vector2D m_size = Vector2D(0, 0); + + // this is the real position and size used to draw the thing + PHLANIMVAR m_realPosition; + PHLANIMVAR m_realSize; + + // for not spamming the protocols + Vector2D m_reportedPosition; + Vector2D m_reportedSize; + Vector2D m_pendingReportedSize; + std::optional> m_pendingSizeAck; + std::vector> m_pendingSizeAcks; + + // for restoring floating statuses + Vector2D m_lastFloatingSize; + Vector2D m_lastFloatingPosition; + + // for floating window offset in workspace animations + Vector2D m_floatingOffset = Vector2D(0, 0); + + // this is used for pseudotiling + bool m_isPseudotiled = false; + Vector2D m_pseudoSize = Vector2D(1280, 720); + + // for recovering relative cursor position + Vector2D m_relativeCursorCoordsOnLastWarp = Vector2D(-1, -1); + + bool m_firstMap = false; // for layouts + bool m_isFloating = false; + bool m_draggingTiled = false; // for dragging around tiled windows + SFullscreenState m_fullscreenState = {.internal = FSMODE_NONE, .client = FSMODE_NONE}; + std::string m_title = ""; + std::string m_class = ""; + std::string m_initialTitle = ""; + std::string m_initialClass = ""; + PHLWORKSPACE m_workspace; + PHLMONITORREF m_monitor; + + bool m_isMapped = false; + + bool m_requestsFloat = false; + + // This is for fullscreen apps + bool m_createdOverFullscreen = false; + + // XWayland stuff + bool m_isX11 = false; + bool m_X11DoesntWantBorders = false; + bool m_X11ShouldntFocus = false; + float m_X11SurfaceScaledBy = 1.f; + // + + // For nofocus + bool m_noInitialFocus = false; + + // Fullscreen and Maximize + bool m_wantsInitialFullscreen = false; + MONITORID m_wantsInitialFullscreenMonitor = MONITOR_INVALID; + + // bitfield suppressEvents + uint64_t m_suppressedEvents = SUPPRESS_NONE; + + // desktop components + SP m_subsurfaceHead; + SP m_popupHead; + + // Animated border + CGradientValueData m_realBorderColor = {0}; + CGradientValueData m_realBorderColorPrevious = {0}; + PHLANIMVAR m_borderFadeAnimationProgress; + PHLANIMVAR m_borderAngleAnimationProgress; + + // Fade in-out + PHLANIMVAR m_alpha; + bool m_fadingOut = false; + bool m_readyToDelete = false; + Vector2D m_originalClosedPos; // these will be used for calculations later on in + Vector2D m_originalClosedSize; // drawing the closing animations + SBoxExtents m_originalClosedExtents; + bool m_animatingIn = false; + + // For pinned (sticky) windows + bool m_pinned = false; + + // For preserving pinned state when fullscreening a pinned window + bool m_pinFullscreened = false; + + // urgency hint + bool m_isUrgent = false; + + // for proper cycling. While cycling we can't just move the pointers, so we need to keep track of the last cycled window. + PHLWINDOWREF m_lastCycledWindow; + + // Window decorations + // TODO: make this a SP. + std::vector> m_windowDecorations; + std::vector m_decosToRemove; + + // Special render data, rules, etc + UP m_ruleApplicator; + + // Transformers + std::vector> m_transformers; + + // for alpha + PHLANIMVAR m_activeInactiveAlpha; + PHLANIMVAR m_movingFromWorkspaceAlpha; + + // animated shadow color + PHLANIMVAR m_realShadowColor; + + // animated tint + PHLANIMVAR m_dimPercent; + + // animate moving to an invisible workspace + int m_monitorMovedFrom = -1; // -1 means not moving + PHLANIMVAR m_movingToWorkspaceAlpha; + + // swallowing + PHLWINDOWREF m_swallowed; + bool m_currentlySwallowed = false; + bool m_groupSwallowed = false; + + // for toplevel monitor events + MONITORID m_lastSurfaceMonitorID = -1; + + // initial token. Will be unregistered on workspace change or timeout of 2 minutes + std::string m_initialWorkspaceToken = ""; + + // for groups + struct SGroupData { + PHLWINDOWREF pNextWindow; // nullptr means no grouping. Self means single group. + bool head = false; + bool locked = false; // per group lock + bool deny = false; // deny window from enter a group or made a group + } m_groupData; + uint16_t m_groupRules = Desktop::View::GROUP_NONE; + + bool m_tearingHint = false; + + // ANR + PHLANIMVAR m_notRespondingTint; + + // For the noclosefor windowrule + Time::steady_tp m_closeableSince = Time::steadyNow(); + + // For the list lookup + bool operator==(const CWindow& rhs) const { + return m_xdgSurface == rhs.m_xdgSurface && m_xwaylandSurface == rhs.m_xwaylandSurface && m_position == rhs.m_position && m_size == rhs.m_size && + m_fadingOut == rhs.m_fadingOut; + } + + // methods + CBox getFullWindowBoundingBox() const; + SBoxExtents getFullWindowExtents() const; + CBox getWindowBoxUnified(uint64_t props); + SBoxExtents getWindowExtentsUnified(uint64_t props); + CBox getWindowIdealBoundingBoxIgnoreReserved(); + void addWindowDeco(UP deco); + void updateWindowDecos(); + void removeWindowDeco(IHyprWindowDecoration* deco); + void uncacheWindowDecos(); + bool checkInputOnDecos(const eInputType, const Vector2D&, std::any = {}); + pid_t getPID(); + IHyprWindowDecoration* getDecorationByType(eDecorationType); + void updateToplevel(); + void updateSurfaceScaleTransformDetails(bool force = false); + void moveToWorkspace(PHLWORKSPACE); + PHLWINDOW x11TransientFor(); + void onUnmap(); + void onMap(); + void setHidden(bool hidden); + bool isHidden(); + void updateDecorationValues(); + SBoxExtents getFullWindowReservedArea(); + Vector2D middle(); + bool opaque(); + float rounding(); + float roundingPower(); + bool canBeTorn(); + void setSuspended(bool suspend); + bool visibleOnMonitor(PHLMONITOR pMonitor); + WORKSPACEID workspaceID(); + MONITORID monitorID(); + bool onSpecialWorkspace(); + void activate(bool force = false); + int surfacesCount(); + void clampWindowSize(const std::optional minSize, const std::optional maxSize); + bool isFullscreen(); + bool isEffectiveInternalFSMode(const eFullscreenMode) const; + int getRealBorderSize() const; + float getScrollMouse(); + float getScrollTouchpad(); + bool isScrollMouseOverridden(); + bool isScrollTouchpadOverridden(); + void updateWindowData(); + void updateWindowData(const SWorkspaceRule&); + void onBorderAngleAnimEnd(WP pav); + bool isInCurvedCorner(double x, double y); + bool hasPopupAt(const Vector2D& pos); + int popupsCount(); + void applyGroupRules(); + void createGroup(); + void destroyGroup(); + PHLWINDOW getGroupHead(); + PHLWINDOW getGroupTail(); + PHLWINDOW getGroupCurrent(); + PHLWINDOW getGroupPrevious(); + PHLWINDOW getGroupWindowByIndex(int); + bool hasInGroup(PHLWINDOW); + int getGroupSize(); + bool canBeGroupedInto(PHLWINDOW pWindow); + void setGroupCurrent(PHLWINDOW pWindow); + void insertWindowToGroup(PHLWINDOW pWindow); + void updateGroupOutputs(); + void switchWithWindowInGroup(PHLWINDOW pWindow); + void setAnimationsToMove(); + void onWorkspaceAnimUpdate(); + void onFocusAnimUpdate(); + void onUpdateState(); + void onUpdateMeta(); + void onX11ConfigureRequest(CBox box); + void onResourceChangeX11(); + std::string fetchTitle(); + std::string fetchClass(); + void warpCursor(bool force = false); + PHLWINDOW getSwallower(); + bool isX11OverrideRedirect(); + bool isModal(); + Vector2D requestedMinSize(); + Vector2D requestedMaxSize(); + Vector2D realToReportSize(); + Vector2D realToReportPosition(); + Vector2D xwaylandSizeToReal(Vector2D size); + Vector2D xwaylandPositionToReal(Vector2D size); + void updateX11SurfaceScale(); + void sendWindowSize(bool force = false); + NContentType::eContentType getContentType(); + void setContentType(NContentType::eContentType contentType); + void deactivateGroupMembers(); + bool isNotResponding(); + std::optional xdgTag(); + std::optional xdgDescription(); + PHLWINDOW parent(); + bool priorityFocus(); + SP getSolitaryResource(); + Vector2D getReportedSize(); + std::optional calculateExpression(const std::string& s); + + CBox getWindowMainSurfaceBox() const { + return {m_realPosition->value().x, m_realPosition->value().y, m_realSize->value().x, m_realSize->value().y}; + } + + // listeners + void onAck(uint32_t serial); + + // + std::unordered_map getEnv(); + + // + PHLWINDOWREF m_self; + + // make private once we move listeners to inside CWindow + struct { + CHyprSignalListener map; + CHyprSignalListener ack; + CHyprSignalListener unmap; + CHyprSignalListener commit; + CHyprSignalListener destroy; + CHyprSignalListener activate; + CHyprSignalListener configureRequest; + CHyprSignalListener setGeometry; + CHyprSignalListener updateState; + CHyprSignalListener updateMetadata; + CHyprSignalListener resourceChange; + } m_listeners; + + private: + std::optional calculateSingleExpr(const std::string& s); + void mapWindow(); + void unmapWindow(); + void commitWindow(); + void destroyWindow(); + void activateX11(); + void unmanagedSetGeometry(); + + // For hidden windows and stuff + bool m_hidden = false; + bool m_suspended = false; + WORKSPACEID m_lastWorkspace = WORKSPACE_INVALID; + }; + + inline bool valid(PHLWINDOW w) { + return w.get(); + } + + inline bool valid(PHLWINDOWREF w) { + return !w.expired(); + } + + inline bool validMapped(PHLWINDOW w) { + if (!valid(w)) + return false; + return w->m_isMapped; + } + + inline bool validMapped(PHLWINDOWREF w) { + if (!valid(w)) + return false; + return w->m_isMapped; + } +} + +/** + format specification + - 'x', only address, equivalent of (uintpr_t)CWindow* + - 'm', with monitor id + - 'w', with workspace id + - 'c', with application class +*/ + +template +struct std::formatter : std::formatter { + bool formatAddressOnly = false; + bool formatWorkspace = false; + bool formatMonitor = false; + bool formatClass = false; + FORMAT_PARSE( // + FORMAT_FLAG('x', formatAddressOnly) // + FORMAT_FLAG('m', formatMonitor) // + FORMAT_FLAG('w', formatWorkspace) // + FORMAT_FLAG('c', formatClass), + PHLWINDOW) + + template + auto format(PHLWINDOW const& w, FormatContext& ctx) const { + auto&& out = ctx.out(); + if (formatAddressOnly) + return std::format_to(out, "{:x}", rc(w.get())); + if (!w) + return std::format_to(out, "[Window nullptr]"); + + std::format_to(out, "["); + std::format_to(out, "Window {:x}: title: \"{}\"", rc(w.get()), w->m_title); + if (formatWorkspace) + std::format_to(out, ", workspace: {}", w->m_workspace ? w->workspaceID() : WORKSPACE_INVALID); + if (formatMonitor) + std::format_to(out, ", monitor: {}", w->monitorID()); + if (formatClass) + std::format_to(out, ", class: {}", w->m_class); + return std::format_to(out, "]"); + } +}; diff --git a/src/events/Events.hpp b/src/events/Events.hpp deleted file mode 100644 index 2e564944c..000000000 --- a/src/events/Events.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "../defines.hpp" - -// NOLINTNEXTLINE(readability-identifier-naming) -namespace Events { - // Window events - DYNLISTENFUNC(commitWindow); - DYNLISTENFUNC(mapWindow); - DYNLISTENFUNC(unmapWindow); - DYNLISTENFUNC(destroyWindow); - DYNLISTENFUNC(setTitleWindow); - DYNLISTENFUNC(fullscreenWindow); - DYNLISTENFUNC(activateX11); - DYNLISTENFUNC(configureX11); - DYNLISTENFUNC(unmanagedSetGeometry); - DYNLISTENFUNC(requestMove); - DYNLISTENFUNC(requestResize); - DYNLISTENFUNC(requestMinimize); - DYNLISTENFUNC(requestMaximize); - DYNLISTENFUNC(setOverrideRedirect); - DYNLISTENFUNC(ackConfigure); -}; diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp deleted file mode 100644 index 6b9ba1b9b..000000000 --- a/src/events/Windows.cpp +++ /dev/null @@ -1,859 +0,0 @@ -#include "Events.hpp" - -#include "../Compositor.hpp" -#include "../helpers/WLClasses.hpp" -#include "../helpers/AsyncDialogBox.hpp" -#include "../managers/input/InputManager.hpp" -#include "../managers/TokenManager.hpp" -#include "../managers/SeatManager.hpp" -#include "../render/Renderer.hpp" -#include "../config/ConfigValue.hpp" -#include "../config/ConfigManager.hpp" -#include "../protocols/LayerShell.hpp" -#include "../protocols/XDGShell.hpp" -#include "../protocols/core/Compositor.hpp" -#include "../protocols/ToplevelExport.hpp" -#include "../protocols/types/ContentType.hpp" -#include "../xwayland/XSurface.hpp" -#include "desktop/DesktopTypes.hpp" -#include "managers/animation/AnimationManager.hpp" -#include "managers/animation/DesktopAnimationManager.hpp" -#include "managers/PointerManager.hpp" -#include "../desktop/LayerSurface.hpp" -#include "../desktop/state/FocusState.hpp" -#include "../managers/LayoutManager.hpp" -#include "../managers/EventManager.hpp" -#include "../managers/animation/AnimationManager.hpp" - -#include -using namespace Hyprutils::String; -using namespace Hyprutils::Animation; - -// ------------------------------------------------------------ // -// __ _______ _ _ _____ ______ _______ // -// \ \ / /_ _| \ | | __ \ / __ \ \ / / ____| // -// \ \ /\ / / | | | \| | | | | | | \ \ /\ / / (___ // -// \ \/ \/ / | | | . ` | | | | | | |\ \/ \/ / \___ \ // -// \ /\ / _| |_| |\ | |__| | |__| | \ /\ / ____) | // -// \/ \/ |_____|_| \_|_____/ \____/ \/ \/ |_____/ // -// // -// ------------------------------------------------------------ // - -static void setVector2DAnimToMove(WP pav) { - const auto PAV = pav.lock(); - if (!PAV) - return; - - CAnimatedVariable* animvar = dc*>(PAV.get()); - animvar->setConfig(g_pConfigManager->getAnimationPropertyConfig("windowsMove")); - - const auto PHLWINDOW = animvar->m_Context.pWindow.lock(); - if (PHLWINDOW) - PHLWINDOW->m_animatingIn = false; -} - -void Events::listener_mapWindow(void* owner, void* data) { - PHLWINDOW PWINDOW = sc(owner)->m_self.lock(); - - static auto PINACTIVEALPHA = CConfigValue("decoration:inactive_opacity"); - static auto PACTIVEALPHA = CConfigValue("decoration:active_opacity"); - static auto PDIMSTRENGTH = CConfigValue("decoration:dim_strength"); - static auto PNEWTAKESOVERFS = CConfigValue("misc:on_focus_under_fullscreen"); - static auto PINITIALWSTRACKING = CConfigValue("misc:initial_workspace_tracking"); - - auto PMONITOR = Desktop::focusState()->monitor(); - if (!Desktop::focusState()->monitor()) { - Desktop::focusState()->rawMonitorFocus(g_pCompositor->getMonitorFromVector({})); - PMONITOR = Desktop::focusState()->monitor(); - } - auto PWORKSPACE = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace; - PWINDOW->m_monitor = PMONITOR; - PWINDOW->m_workspace = PWORKSPACE; - PWINDOW->m_isMapped = true; - PWINDOW->m_readyToDelete = false; - PWINDOW->m_fadingOut = false; - PWINDOW->m_title = PWINDOW->fetchTitle(); - PWINDOW->m_firstMap = true; - PWINDOW->m_initialTitle = PWINDOW->m_title; - PWINDOW->m_initialClass = PWINDOW->fetchClass(); - - // check for token - std::string requestedWorkspace = ""; - bool workspaceSilent = false; - - if (*PINITIALWSTRACKING) { - const auto WINDOWENV = PWINDOW->getEnv(); - if (WINDOWENV.contains("HL_INITIAL_WORKSPACE_TOKEN")) { - const auto SZTOKEN = WINDOWENV.at("HL_INITIAL_WORKSPACE_TOKEN"); - Debug::log(LOG, "New window contains HL_INITIAL_WORKSPACE_TOKEN: {}", SZTOKEN); - const auto TOKEN = g_pTokenManager->getToken(SZTOKEN); - if (TOKEN) { - // find workspace and use it - SInitialWorkspaceToken WS = std::any_cast(TOKEN->m_data); - - Debug::log(LOG, "HL_INITIAL_WORKSPACE_TOKEN {} -> {}", SZTOKEN, WS.workspace); - - if (g_pCompositor->getWorkspaceByString(WS.workspace) != PWINDOW->m_workspace) { - requestedWorkspace = WS.workspace; - workspaceSilent = true; - } - - if (*PINITIALWSTRACKING == 1) // one-shot token - g_pTokenManager->removeToken(TOKEN); - else if (*PINITIALWSTRACKING == 2) { // persistent - if (WS.primaryOwner.expired()) { - WS.primaryOwner = PWINDOW; - TOKEN->m_data = WS; - } - - PWINDOW->m_initialWorkspaceToken = SZTOKEN; - } - } - } - } - - if (g_pInputManager->m_lastFocusOnLS) // waybar fix - g_pInputManager->releaseAllMouseButtons(); - - // checks if the window wants borders and sets the appropriate flag - g_pXWaylandManager->checkBorders(PWINDOW); - - // registers the animated vars and stuff - PWINDOW->onMap(); - - const auto PWINDOWSURFACE = PWINDOW->m_wlSurface->resource(); - - if (!PWINDOWSURFACE) { - g_pCompositor->removeWindowFromVectorSafe(PWINDOW); - return; - } - - if (g_pXWaylandManager->shouldBeFloated(PWINDOW)) { - PWINDOW->m_isFloating = true; - PWINDOW->m_requestsFloat = true; - } - - PWINDOW->m_X11ShouldntFocus = PWINDOW->m_X11ShouldntFocus || (PWINDOW->m_isX11 && PWINDOW->isX11OverrideRedirect() && !PWINDOW->m_xwaylandSurface->wantsFocus()); - - // window rules - std::optional requestedInternalFSMode, requestedClientFSMode; - std::optional requestedFSState; - if (PWINDOW->m_wantsInitialFullscreen || (PWINDOW->m_isX11 && PWINDOW->m_xwaylandSurface->m_fullscreen)) - requestedClientFSMode = FSMODE_FULLSCREEN; - MONITORID requestedFSMonitor = PWINDOW->m_wantsInitialFullscreenMonitor; - - PWINDOW->m_ruleApplicator->readStaticRules(); - { - if (!PWINDOW->m_ruleApplicator->static_.monitor.empty()) { - const auto& MONITORSTR = PWINDOW->m_ruleApplicator->static_.monitor; - if (MONITORSTR == "unset") - PWINDOW->m_monitor = PMONITOR; - else { - const auto MONITOR = g_pCompositor->getMonitorFromString(MONITORSTR); - - if (MONITOR) { - PWINDOW->m_monitor = MONITOR; - - const auto PMONITORFROMID = PWINDOW->m_monitor.lock(); - - if (PWINDOW->m_monitor != PMONITOR) { - g_pKeybindManager->m_dispatchers["focusmonitor"](std::to_string(PWINDOW->monitorID())); - PMONITOR = PMONITORFROMID; - } - PWINDOW->m_workspace = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace; - PWORKSPACE = PWINDOW->m_workspace; - - Debug::log(LOG, "Rule monitor, applying to {:mw}", PWINDOW); - requestedFSMonitor = MONITOR_INVALID; - } else - Debug::log(ERR, "No monitor in monitor {} rule", MONITORSTR); - } - } - - if (!PWINDOW->m_ruleApplicator->static_.workspace.empty()) { - const auto WORKSPACERQ = PWINDOW->m_ruleApplicator->static_.workspace; - - if (WORKSPACERQ == "unset") - requestedWorkspace = ""; - else - requestedWorkspace = WORKSPACERQ; - - const auto JUSTWORKSPACE = WORKSPACERQ.contains(' ') ? WORKSPACERQ.substr(0, WORKSPACERQ.find_first_of(' ')) : WORKSPACERQ; - - if (JUSTWORKSPACE == PWORKSPACE->m_name || JUSTWORKSPACE == "name:" + PWORKSPACE->m_name) - requestedWorkspace = ""; - - Debug::log(LOG, "Rule workspace matched by {}, {} applied.", PWINDOW, PWINDOW->m_ruleApplicator->static_.workspace); - requestedFSMonitor = MONITOR_INVALID; - } - - if (PWINDOW->m_ruleApplicator->static_.floating.has_value()) - PWINDOW->m_isFloating = PWINDOW->m_ruleApplicator->static_.floating.value(); - - if (PWINDOW->m_ruleApplicator->static_.pseudo) - PWINDOW->m_isPseudotiled = true; - - if (PWINDOW->m_ruleApplicator->static_.noInitialFocus) - PWINDOW->m_noInitialFocus = true; - - if (PWINDOW->m_ruleApplicator->static_.fullscreenStateClient || PWINDOW->m_ruleApplicator->static_.fullscreenStateInternal) { - requestedFSState = SFullscreenState{ - .internal = sc(PWINDOW->m_ruleApplicator->static_.fullscreenStateInternal.value_or(0)), - .client = sc(PWINDOW->m_ruleApplicator->static_.fullscreenStateClient.value_or(0)), - }; - } - - if (!PWINDOW->m_ruleApplicator->static_.suppressEvent.empty()) { - for (const auto& var : PWINDOW->m_ruleApplicator->static_.suppressEvent) { - if (var == "fullscreen") - PWINDOW->m_suppressedEvents |= SUPPRESS_FULLSCREEN; - else if (var == "maximize") - PWINDOW->m_suppressedEvents |= SUPPRESS_MAXIMIZE; - else if (var == "activate") - PWINDOW->m_suppressedEvents |= SUPPRESS_ACTIVATE; - else if (var == "activatefocus") - PWINDOW->m_suppressedEvents |= SUPPRESS_ACTIVATE_FOCUSONLY; - else if (var == "fullscreenoutput") - PWINDOW->m_suppressedEvents |= SUPPRESS_FULLSCREEN_OUTPUT; - else - Debug::log(ERR, "Error while parsing suppressevent windowrule: unknown event type {}", var); - } - } - - if (PWINDOW->m_ruleApplicator->static_.pin) - PWINDOW->m_pinned = true; - - if (PWINDOW->m_ruleApplicator->static_.fullscreen) - requestedInternalFSMode = FSMODE_FULLSCREEN; - - if (PWINDOW->m_ruleApplicator->static_.maximize) - requestedInternalFSMode = FSMODE_MAXIMIZED; - - if (!PWINDOW->m_ruleApplicator->static_.group.empty()) { - if (!(PWINDOW->m_groupRules & GROUP_OVERRIDE) && trim(PWINDOW->m_ruleApplicator->static_.group) != "group") { - CVarList2 vars(std::string{PWINDOW->m_ruleApplicator->static_.group}, 0, 's'); - std::string vPrev = ""; - - for (auto const& v : vars) { - if (v == "group") - continue; - - if (v == "set") { - PWINDOW->m_groupRules |= GROUP_SET; - } else if (v == "new") { - // shorthand for `group barred set` - PWINDOW->m_groupRules |= (GROUP_SET | GROUP_BARRED); - } else if (v == "lock") { - PWINDOW->m_groupRules |= GROUP_LOCK; - } else if (v == "invade") { - PWINDOW->m_groupRules |= GROUP_INVADE; - } else if (v == "barred") { - PWINDOW->m_groupRules |= GROUP_BARRED; - } else if (v == "deny") { - PWINDOW->m_groupData.deny = true; - } else if (v == "override") { - // Clear existing rules - PWINDOW->m_groupRules = GROUP_OVERRIDE; - } else if (v == "unset") { - // Clear existing rules and stop processing - PWINDOW->m_groupRules = GROUP_OVERRIDE; - break; - } else if (v == "always") { - if (vPrev == "set" || vPrev == "group") - PWINDOW->m_groupRules |= GROUP_SET_ALWAYS; - else if (vPrev == "lock") - PWINDOW->m_groupRules |= GROUP_LOCK_ALWAYS; - else - Debug::log(ERR, "windowrule `group` does not support `{} always`", vPrev); - } - vPrev = v; - } - } - } - - if (PWINDOW->m_ruleApplicator->static_.content) - PWINDOW->setContentType(sc(PWINDOW->m_ruleApplicator->static_.content.value())); - - if (PWINDOW->m_ruleApplicator->static_.noCloseFor) - PWINDOW->m_closeableSince = Time::steadyNow() + std::chrono::milliseconds(PWINDOW->m_ruleApplicator->static_.noCloseFor.value()); - } - - // make it uncloseable if it's a Hyprland dialog - // TODO: make some closeable? - if (CAsyncDialogBox::isAsyncDialogBox(PWINDOW->getPID())) - PWINDOW->m_closeableSince = Time::steadyNow() + std::chrono::years(10 /* Should be enough, no? */); - - // disallow tiled pinned - if (PWINDOW->m_pinned && !PWINDOW->m_isFloating) - PWINDOW->m_pinned = false; - - CVarList2 WORKSPACEARGS = CVarList2(std::move(requestedWorkspace), 0, ' ', false, false); - - if (!WORKSPACEARGS[0].empty()) { - WORKSPACEID requestedWorkspaceID; - std::string requestedWorkspaceName; - if (WORKSPACEARGS.contains("silent")) - workspaceSilent = true; - - if (WORKSPACEARGS.contains("empty") && PWORKSPACE->getWindows() <= 1) { - requestedWorkspaceID = PWORKSPACE->m_id; - requestedWorkspaceName = PWORKSPACE->m_name; - } else { - auto result = getWorkspaceIDNameFromString(WORKSPACEARGS.join(" ", 0, workspaceSilent ? WORKSPACEARGS.size() - 1 : 0)); - requestedWorkspaceID = result.id; - requestedWorkspaceName = result.name; - } - - if (requestedWorkspaceID != WORKSPACE_INVALID) { - auto pWorkspace = g_pCompositor->getWorkspaceByID(requestedWorkspaceID); - - if (!pWorkspace) - pWorkspace = g_pCompositor->createNewWorkspace(requestedWorkspaceID, PWINDOW->monitorID(), requestedWorkspaceName, false); - - PWORKSPACE = pWorkspace; - - PWINDOW->m_workspace = pWorkspace; - PWINDOW->m_monitor = pWorkspace->m_monitor; - - if (PWINDOW->m_monitor.lock()->m_activeSpecialWorkspace && !pWorkspace->m_isSpecialWorkspace) - workspaceSilent = true; - - if (!workspaceSilent) { - if (pWorkspace->m_isSpecialWorkspace) - pWorkspace->m_monitor->setSpecialWorkspace(pWorkspace); - else if (PMONITOR->activeWorkspaceID() != requestedWorkspaceID && !PWINDOW->m_noInitialFocus) - g_pKeybindManager->m_dispatchers["workspace"](requestedWorkspaceName); - - PMONITOR = Desktop::focusState()->monitor(); - } - - requestedFSMonitor = MONITOR_INVALID; - } else - workspaceSilent = false; - } - - if (PWINDOW->m_suppressedEvents & SUPPRESS_FULLSCREEN_OUTPUT) - requestedFSMonitor = MONITOR_INVALID; - else if (requestedFSMonitor != MONITOR_INVALID) { - if (const auto PM = g_pCompositor->getMonitorFromID(requestedFSMonitor); PM) - PWINDOW->m_monitor = PM; - - const auto PMONITORFROMID = PWINDOW->m_monitor.lock(); - - if (PWINDOW->m_monitor != PMONITOR) { - g_pKeybindManager->m_dispatchers["focusmonitor"](std::to_string(PWINDOW->monitorID())); - PMONITOR = PMONITORFROMID; - } - PWINDOW->m_workspace = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace; - PWORKSPACE = PWINDOW->m_workspace; - - Debug::log(LOG, "Requested monitor, applying to {:mw}", PWINDOW); - } - - if (PWORKSPACE->m_defaultFloating) - PWINDOW->m_isFloating = true; - - if (PWORKSPACE->m_defaultPseudo) { - PWINDOW->m_isPseudotiled = true; - CBox desiredGeometry = g_pXWaylandManager->getGeometryForWindow(PWINDOW); - PWINDOW->m_pseudoSize = Vector2D(desiredGeometry.width, desiredGeometry.height); - } - - PWINDOW->updateWindowData(); - - // Verify window swallowing. Get the swallower before calling onWindowCreated(PWINDOW) because getSwallower() wouldn't get it after if PWINDOW gets auto grouped. - const auto SWALLOWER = PWINDOW->getSwallower(); - PWINDOW->m_swallowed = SWALLOWER; - if (PWINDOW->m_swallowed) - PWINDOW->m_swallowed->m_currentlySwallowed = true; - - // emit the IPC event before the layout might focus the window to avoid a focus event first - g_pEventManager->postEvent(SHyprIPCEvent{"openwindow", std::format("{:x},{},{},{}", PWINDOW, PWORKSPACE->m_name, PWINDOW->m_class, PWINDOW->m_title)}); - EMIT_HOOK_EVENT("openWindowEarly", PWINDOW); - - if (PWINDOW->m_isFloating) { - g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); - PWINDOW->m_createdOverFullscreen = true; - - if (!PWINDOW->m_ruleApplicator->static_.size.empty()) { - const auto COMPUTED = PWINDOW->calculateExpression(PWINDOW->m_ruleApplicator->static_.size); - if (!COMPUTED) - Debug::log(ERR, "failed to parse {} as an expression", PWINDOW->m_ruleApplicator->static_.size); - else { - *PWINDOW->m_realSize = *COMPUTED; - PWINDOW->setHidden(false); - } - } - - if (!PWINDOW->m_ruleApplicator->static_.position.empty()) { - const auto COMPUTED = PWINDOW->calculateExpression(PWINDOW->m_ruleApplicator->static_.position); - if (!COMPUTED) - Debug::log(ERR, "failed to parse {} as an expression", PWINDOW->m_ruleApplicator->static_.position); - else { - *PWINDOW->m_realPosition = *COMPUTED + PMONITOR->m_position; - PWINDOW->setHidden(false); - } - } - - if (PWINDOW->m_ruleApplicator->static_.center) { - const auto WORKAREA = PMONITOR->logicalBoxMinusReserved(); - *PWINDOW->m_realPosition = WORKAREA.middle() - PWINDOW->m_realSize->goal() / 2.f; - } - - // set the pseudo size to the GOAL of our current size - // because the windows are animated on RealSize - PWINDOW->m_pseudoSize = PWINDOW->m_realSize->goal(); - - g_pCompositor->changeWindowZOrder(PWINDOW, true); - } else { - g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); - - bool setPseudo = false; - - if (!PWINDOW->m_ruleApplicator->static_.size.empty()) { - const auto COMPUTED = PWINDOW->calculateExpression(PWINDOW->m_ruleApplicator->static_.size); - if (!COMPUTED) - Debug::log(ERR, "failed to parse {} as an expression", PWINDOW->m_ruleApplicator->static_.size); - else { - setPseudo = true; - PWINDOW->m_pseudoSize = *COMPUTED; - PWINDOW->setHidden(false); - } - } - - if (!setPseudo) - PWINDOW->m_pseudoSize = PWINDOW->m_realSize->goal() - Vector2D(10, 10); - } - - const auto PFOCUSEDWINDOWPREV = Desktop::focusState()->window(); - - if (PWINDOW->m_ruleApplicator->allowsInput().valueOrDefault()) { // if default value wasn't set to false getPriority() would throw an exception - PWINDOW->m_ruleApplicator->noFocusOverride(Desktop::Types::COverridableVar(false, PWINDOW->m_ruleApplicator->allowsInput().getPriority())); - PWINDOW->m_noInitialFocus = false; - PWINDOW->m_X11ShouldntFocus = false; - } - - // check LS focus grab - const auto PFORCEFOCUS = g_pCompositor->getForceFocus(); - const auto PLSFROMFOCUS = g_pCompositor->getLayerSurfaceFromSurface(Desktop::focusState()->surface()); - if (PLSFROMFOCUS && PLSFROMFOCUS->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE) - PWINDOW->m_noInitialFocus = true; - - if (PWINDOW->m_workspace->m_hasFullscreenWindow && !requestedInternalFSMode.has_value() && !requestedClientFSMode.has_value() && !PWINDOW->m_isFloating) { - if (*PNEWTAKESOVERFS == 0) - PWINDOW->m_noInitialFocus = true; - else if (*PNEWTAKESOVERFS == 1) - requestedInternalFSMode = PWINDOW->m_workspace->m_fullscreenMode; - else if (*PNEWTAKESOVERFS == 2) - g_pCompositor->setWindowFullscreenInternal(PWINDOW->m_workspace->getFullscreenWindow(), FSMODE_NONE); - } - - if (!PWINDOW->m_ruleApplicator->noFocus().valueOrDefault() && !PWINDOW->m_noInitialFocus && - (!PWINDOW->isX11OverrideRedirect() || (PWINDOW->m_isX11 && PWINDOW->m_xwaylandSurface->wantsFocus())) && !workspaceSilent && (!PFORCEFOCUS || PFORCEFOCUS == PWINDOW) && - !g_pInputManager->isConstrained()) { - Desktop::focusState()->fullWindowFocus(PWINDOW); - PWINDOW->m_activeInactiveAlpha->setValueAndWarp(*PACTIVEALPHA); - PWINDOW->m_dimPercent->setValueAndWarp(PWINDOW->m_ruleApplicator->noDim().valueOrDefault() ? 0.f : *PDIMSTRENGTH); - } else { - PWINDOW->m_activeInactiveAlpha->setValueAndWarp(*PINACTIVEALPHA); - PWINDOW->m_dimPercent->setValueAndWarp(0); - } - - if (requestedClientFSMode.has_value() && (PWINDOW->m_suppressedEvents & SUPPRESS_FULLSCREEN)) - requestedClientFSMode = sc(sc(requestedClientFSMode.value_or(FSMODE_NONE)) & ~sc(FSMODE_FULLSCREEN)); - if (requestedClientFSMode.has_value() && (PWINDOW->m_suppressedEvents & SUPPRESS_MAXIMIZE)) - requestedClientFSMode = sc(sc(requestedClientFSMode.value_or(FSMODE_NONE)) & ~sc(FSMODE_MAXIMIZED)); - - if (!PWINDOW->m_noInitialFocus && (requestedInternalFSMode.has_value() || requestedClientFSMode.has_value() || requestedFSState.has_value())) { - // fix fullscreen on requested (basically do a switcheroo) - if (PWINDOW->m_workspace->m_hasFullscreenWindow) - g_pCompositor->setWindowFullscreenInternal(PWINDOW->m_workspace->getFullscreenWindow(), FSMODE_NONE); - - PWINDOW->m_realPosition->warp(); - PWINDOW->m_realSize->warp(); - if (requestedFSState.has_value()) { - PWINDOW->m_ruleApplicator->syncFullscreenOverride(Desktop::Types::COverridableVar(false, Desktop::Types::PRIORITY_WINDOW_RULE)); - g_pCompositor->setWindowFullscreenState(PWINDOW, requestedFSState.value()); - } else if (requestedInternalFSMode.has_value() && requestedClientFSMode.has_value() && !PWINDOW->m_ruleApplicator->syncFullscreen().valueOrDefault()) - g_pCompositor->setWindowFullscreenState(PWINDOW, SFullscreenState{.internal = requestedInternalFSMode.value(), .client = requestedClientFSMode.value()}); - else if (requestedInternalFSMode.has_value()) - g_pCompositor->setWindowFullscreenInternal(PWINDOW, requestedInternalFSMode.value()); - else if (requestedClientFSMode.has_value()) - g_pCompositor->setWindowFullscreenClient(PWINDOW, requestedClientFSMode.value()); - } - - // recheck idle inhibitors - g_pInputManager->recheckIdleInhibitorStatus(); - - PWINDOW->updateToplevel(); - PWINDOW->m_ruleApplicator->propertiesChanged(Desktop::Rule::RULE_PROP_ALL); - - if (workspaceSilent) { - if (validMapped(PFOCUSEDWINDOWPREV)) { - Desktop::focusState()->rawWindowFocus(PFOCUSEDWINDOWPREV); - PFOCUSEDWINDOWPREV->updateWindowDecos(); // need to for some reason i cba to find out why - } else if (!PFOCUSEDWINDOWPREV) - Desktop::focusState()->rawWindowFocus(nullptr); - } - - // swallow - if (SWALLOWER) { - g_pLayoutManager->getCurrentLayout()->onWindowRemoved(SWALLOWER); - g_pHyprRenderer->damageWindow(SWALLOWER); - SWALLOWER->setHidden(true); - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PWINDOW->monitorID()); - } - - PWINDOW->m_firstMap = false; - - Debug::log(LOG, "Map request dispatched, monitor {}, window pos: {:5j}, window size: {:5j}", PMONITOR->m_name, PWINDOW->m_realPosition->goal(), PWINDOW->m_realSize->goal()); - - // emit the hook event here after basic stuff has been initialized - EMIT_HOOK_EVENT("openWindow", PWINDOW); - - // apply data from default decos. Borders, shadows. - g_pDecorationPositioner->forceRecalcFor(PWINDOW); - PWINDOW->updateWindowDecos(); - g_pLayoutManager->getCurrentLayout()->recalculateWindow(PWINDOW); - - // do animations - g_pDesktopAnimationManager->startAnimation(PWINDOW, CDesktopAnimationManager::ANIMATION_TYPE_IN); - - PWINDOW->m_realPosition->setCallbackOnEnd(setVector2DAnimToMove); - PWINDOW->m_realSize->setCallbackOnEnd(setVector2DAnimToMove); - - // recalc the values for this window - PWINDOW->updateDecorationValues(); - // avoid this window being visible - if (PWORKSPACE->m_hasFullscreenWindow && !PWINDOW->isFullscreen() && !PWINDOW->m_isFloating) - PWINDOW->m_alpha->setValueAndWarp(0.f); - - g_pCompositor->setPreferredScaleForSurface(PWINDOW->m_wlSurface->resource(), PMONITOR->m_scale); - g_pCompositor->setPreferredTransformForSurface(PWINDOW->m_wlSurface->resource(), PMONITOR->m_transform); - - if (g_pSeatManager->m_mouse.expired() || !g_pInputManager->isConstrained()) - g_pInputManager->sendMotionEventsToFocused(); - - // fix some xwayland apps that don't behave nicely - PWINDOW->m_reportedSize = PWINDOW->m_pendingReportedSize; - - if (PWINDOW->m_workspace) - PWINDOW->m_workspace->updateWindows(); - - if (PMONITOR && PWINDOW->isX11OverrideRedirect()) - PWINDOW->m_X11SurfaceScaledBy = PMONITOR->m_scale; -} - -void Events::listener_unmapWindow(void* owner, void* data) { - PHLWINDOW PWINDOW = sc(owner)->m_self.lock(); - - Debug::log(LOG, "{:c} unmapped", PWINDOW); - - static auto PEXITRETAINSFS = CConfigValue("misc:exit_window_retains_fullscreen"); - - const auto CURRENTWINDOWFSSTATE = PWINDOW->isFullscreen(); - const auto CURRENTFSMODE = PWINDOW->m_fullscreenState.internal; - - if (!PWINDOW->m_wlSurface->exists() || !PWINDOW->m_isMapped) { - Debug::log(WARN, "{} unmapped without being mapped??", PWINDOW); - PWINDOW->m_fadingOut = false; - return; - } - - const auto PMONITOR = PWINDOW->m_monitor.lock(); - if (PMONITOR) { - PWINDOW->m_originalClosedPos = PWINDOW->m_realPosition->value() - PMONITOR->m_position; - PWINDOW->m_originalClosedSize = PWINDOW->m_realSize->value(); - PWINDOW->m_originalClosedExtents = PWINDOW->getFullWindowExtents(); - } - - g_pEventManager->postEvent(SHyprIPCEvent{"closewindow", std::format("{:x}", PWINDOW)}); - EMIT_HOOK_EVENT("closeWindow", PWINDOW); - - if (PWINDOW->m_isFloating && !PWINDOW->m_isX11 && PWINDOW->m_ruleApplicator->persistentSize().valueOrDefault()) { - Debug::log(LOG, "storing floating size {}x{} for window {}::{} on close", PWINDOW->m_realSize->value().x, PWINDOW->m_realSize->value().y, PWINDOW->m_class, - PWINDOW->m_title); - g_pConfigManager->storeFloatingSize(PWINDOW, PWINDOW->m_realSize->value()); - } - - PROTO::toplevelExport->onWindowUnmap(PWINDOW); - - if (PWINDOW->isFullscreen()) - g_pCompositor->setWindowFullscreenInternal(PWINDOW, FSMODE_NONE); - - // Allow the renderer to catch the last frame. - if (g_pHyprRenderer->shouldRenderWindow(PWINDOW)) - g_pHyprRenderer->makeSnapshot(PWINDOW); - - // swallowing - if (valid(PWINDOW->m_swallowed)) { - if (PWINDOW->m_swallowed->m_currentlySwallowed) { - PWINDOW->m_swallowed->m_currentlySwallowed = false; - PWINDOW->m_swallowed->setHidden(false); - - if (PWINDOW->m_groupData.pNextWindow.lock()) - PWINDOW->m_swallowed->m_groupSwallowed = true; // flag for the swallowed window to be created into the group where it belongs when auto_group = false. - - g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW->m_swallowed.lock()); - } - - PWINDOW->m_swallowed->m_groupSwallowed = false; - PWINDOW->m_swallowed.reset(); - } - - bool wasLastWindow = false; - - if (PWINDOW == Desktop::focusState()->window()) { - wasLastWindow = true; - Desktop::focusState()->window().reset(); - Desktop::focusState()->surface().reset(); - - g_pInputManager->releaseAllMouseButtons(); - } - - if (PWINDOW == g_pInputManager->m_currentlyDraggedWindow.lock()) - g_pKeybindManager->changeMouseBindMode(MBIND_INVALID); - - // remove the fullscreen window status from workspace if we closed it - const auto PWORKSPACE = PWINDOW->m_workspace; - - if (PWORKSPACE->m_hasFullscreenWindow && PWINDOW->isFullscreen()) - PWORKSPACE->m_hasFullscreenWindow = false; - - g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW); - - g_pHyprRenderer->damageWindow(PWINDOW); - - // do this after onWindowRemoved because otherwise it'll think the window is invalid - PWINDOW->m_isMapped = false; - - // refocus on a new window if needed - if (wasLastWindow) { - static auto FOCUSONCLOSE = CConfigValue("input:focus_on_close"); - PHLWINDOW PWINDOWCANDIDATE = nullptr; - if (*FOCUSONCLOSE) - PWINDOWCANDIDATE = (g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING)); - else - PWINDOWCANDIDATE = g_pLayoutManager->getCurrentLayout()->getNextWindowCandidate(PWINDOW); - - Debug::log(LOG, "On closed window, new focused candidate is {}", PWINDOWCANDIDATE); - - if (PWINDOWCANDIDATE != Desktop::focusState()->window() && PWINDOWCANDIDATE) { - Desktop::focusState()->fullWindowFocus(PWINDOWCANDIDATE); - if (*PEXITRETAINSFS && CURRENTWINDOWFSSTATE) - g_pCompositor->setWindowFullscreenInternal(PWINDOWCANDIDATE, CURRENTFSMODE); - } - - if (!PWINDOWCANDIDATE && PWINDOW->m_workspace && PWINDOW->m_workspace->getWindows() == 0) - g_pInputManager->refocus(); - - g_pInputManager->sendMotionEventsToFocused(); - - // CWindow::onUnmap will remove this window's active status, but we can't really do it above. - if (PWINDOW == Desktop::focusState()->window() || !Desktop::focusState()->window()) { - g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", ","}); - g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", ""}); - EMIT_HOOK_EVENT("activeWindow", PHLWINDOW{nullptr}); - } - } else { - Debug::log(LOG, "Unmapped was not focused, ignoring a refocus."); - } - - PWINDOW->m_fadingOut = true; - - g_pCompositor->addToFadingOutSafe(PWINDOW); - - if (!PWINDOW->m_X11DoesntWantBorders) // don't animate out if they weren't animated in. - *PWINDOW->m_realPosition = PWINDOW->m_realPosition->value() + Vector2D(0.01f, 0.01f); // it has to be animated, otherwise CesktopAnimationManager will ignore it - - // anims - g_pDesktopAnimationManager->startAnimation(PWINDOW, CDesktopAnimationManager::ANIMATION_TYPE_OUT); - - // recheck idle inhibitors - g_pInputManager->recheckIdleInhibitorStatus(); - - // force report all sizes (QT sometimes has an issue with this) - if (PWINDOW->m_workspace) - PWINDOW->m_workspace->forceReportSizesToWindows(); - - // update lastwindow after focus - PWINDOW->onUnmap(); -} - -void Events::listener_commitWindow(void* owner, void* data) { - PHLWINDOW PWINDOW = sc(owner)->m_self.lock(); - - if (!PWINDOW->m_isX11 && PWINDOW->m_xdgSurface->m_initialCommit) { - Vector2D predSize = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(PWINDOW); - - Debug::log(LOG, "Layout predicts size {} for {}", predSize, PWINDOW); - - PWINDOW->m_xdgSurface->m_toplevel->setSize(predSize); - return; - } - - if (!PWINDOW->m_isMapped || PWINDOW->isHidden()) - return; - - if (PWINDOW->m_isX11) - PWINDOW->m_reportedSize = PWINDOW->m_pendingReportedSize; - - if (!PWINDOW->m_isX11 && !PWINDOW->isFullscreen() && PWINDOW->m_isFloating) { - const auto MINSIZE = PWINDOW->m_xdgSurface->m_toplevel->layoutMinSize(); - const auto MAXSIZE = PWINDOW->m_xdgSurface->m_toplevel->layoutMaxSize(); - - PWINDOW->clampWindowSize(MINSIZE, MAXSIZE > Vector2D{1, 1} ? std::optional{MAXSIZE} : std::nullopt); - g_pHyprRenderer->damageWindow(PWINDOW); - } - - if (!PWINDOW->m_workspace->m_visible) - return; - - const auto PMONITOR = PWINDOW->m_monitor.lock(); - - if (PMONITOR) - PMONITOR->debugLastPresentation(g_pSeatManager->m_isPointerFrameCommit ? "listener_commitWindow skip" : "listener_commitWindow"); - - if (g_pSeatManager->m_isPointerFrameCommit) { - g_pSeatManager->m_isPointerFrameSkipped = false; - g_pSeatManager->m_isPointerFrameCommit = false; - } else - g_pHyprRenderer->damageSurface(PWINDOW->m_wlSurface->resource(), PWINDOW->m_realPosition->goal().x, PWINDOW->m_realPosition->goal().y, - PWINDOW->m_isX11 ? 1.0 / PWINDOW->m_X11SurfaceScaledBy : 1.0); - - if (g_pSeatManager->m_isPointerFrameSkipped) { - g_pPointerManager->sendStoredMovement(); - g_pSeatManager->sendPointerFrame(); - g_pSeatManager->m_isPointerFrameCommit = true; - } - - if (!PWINDOW->m_isX11) { - PWINDOW->m_subsurfaceHead->recheckDamageForSubsurfaces(); - PWINDOW->m_popupHead->recheckTree(); - } - - // tearing: if solitary, redraw it. This still might be a single surface window - if (PMONITOR && PMONITOR->m_solitaryClient.lock() == PWINDOW && PWINDOW->canBeTorn() && PMONITOR->m_tearingState.canTear && - PWINDOW->m_wlSurface->resource()->m_current.texture) { - CRegion damageBox{PWINDOW->m_wlSurface->resource()->m_current.accumulateBufferDamage()}; - - if (!damageBox.empty()) { - if (PMONITOR->m_tearingState.busy) { - PMONITOR->m_tearingState.frameScheduledWhileBusy = true; - } else { - PMONITOR->m_tearingState.nextRenderTorn = true; - g_pHyprRenderer->renderMonitor(PMONITOR); - } - } - } -} - -void Events::listener_destroyWindow(void* owner, void* data) { - PHLWINDOW PWINDOW = sc(owner)->m_self.lock(); - - Debug::log(LOG, "{:c} destroyed, queueing.", PWINDOW); - - if (PWINDOW == Desktop::focusState()->window()) { - Desktop::focusState()->window().reset(); - Desktop::focusState()->surface().reset(); - } - - PWINDOW->m_wlSurface->unassign(); - - PWINDOW->m_listeners = {}; - - g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW); - - PWINDOW->m_readyToDelete = true; - - PWINDOW->m_xdgSurface.reset(); - - if (!PWINDOW->m_fadingOut) { - Debug::log(LOG, "Unmapped {} removed instantly", PWINDOW); - g_pCompositor->removeWindowFromVectorSafe(PWINDOW); // most likely X11 unmanaged or sumn - } - - PWINDOW->m_listeners.unmap.reset(); - PWINDOW->m_listeners.destroy.reset(); - PWINDOW->m_listeners.map.reset(); - PWINDOW->m_listeners.commit.reset(); -} - -void Events::listener_activateX11(void* owner, void* data) { - PHLWINDOW PWINDOW = sc(owner)->m_self.lock(); - - Debug::log(LOG, "X11 Activate request for window {}", PWINDOW); - - if (PWINDOW->isX11OverrideRedirect()) { - - Debug::log(LOG, "Unmanaged X11 {} requests activate", PWINDOW); - - if (Desktop::focusState()->window() && Desktop::focusState()->window()->getPID() != PWINDOW->getPID()) - return; - - if (!PWINDOW->m_xwaylandSurface->wantsFocus()) - return; - - Desktop::focusState()->fullWindowFocus(PWINDOW); - return; - } - - if (PWINDOW == Desktop::focusState()->window() || (PWINDOW->m_suppressedEvents & SUPPRESS_ACTIVATE)) - return; - - PWINDOW->activate(); -} - -void Events::listener_unmanagedSetGeometry(void* owner, void* data) { - PHLWINDOW PWINDOW = sc(owner)->m_self.lock(); - - if (!PWINDOW->m_isMapped || !PWINDOW->m_xwaylandSurface || !PWINDOW->m_xwaylandSurface->m_overrideRedirect) - return; - - const auto POS = PWINDOW->m_realPosition->goal(); - const auto SIZ = PWINDOW->m_realSize->goal(); - - if (PWINDOW->m_xwaylandSurface->m_geometry.size() > Vector2D{1, 1}) - PWINDOW->setHidden(false); - else - PWINDOW->setHidden(true); - - if (PWINDOW->isFullscreen() || !PWINDOW->m_isFloating) { - PWINDOW->sendWindowSize(true); - g_pHyprRenderer->damageWindow(PWINDOW); - return; - } - - static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); - - const auto LOGICALPOS = g_pXWaylandManager->xwaylandToWaylandCoords(PWINDOW->m_xwaylandSurface->m_geometry.pos()); - - if (abs(std::floor(POS.x) - LOGICALPOS.x) > 2 || abs(std::floor(POS.y) - LOGICALPOS.y) > 2 || abs(std::floor(SIZ.x) - PWINDOW->m_xwaylandSurface->m_geometry.width) > 2 || - abs(std::floor(SIZ.y) - PWINDOW->m_xwaylandSurface->m_geometry.height) > 2) { - Debug::log(LOG, "Unmanaged window {} requests geometry update to {:j} {:j}", PWINDOW, LOGICALPOS, PWINDOW->m_xwaylandSurface->m_geometry.size()); - - g_pHyprRenderer->damageWindow(PWINDOW); - PWINDOW->m_realPosition->setValueAndWarp(Vector2D(LOGICALPOS.x, LOGICALPOS.y)); - - if (abs(std::floor(SIZ.x) - PWINDOW->m_xwaylandSurface->m_geometry.w) > 2 || abs(std::floor(SIZ.y) - PWINDOW->m_xwaylandSurface->m_geometry.h) > 2) - PWINDOW->m_realSize->setValueAndWarp(PWINDOW->m_xwaylandSurface->m_geometry.size()); - - if (*PXWLFORCESCALEZERO) { - if (const auto PMONITOR = PWINDOW->m_monitor.lock(); PMONITOR) { - PWINDOW->m_realSize->setValueAndWarp(PWINDOW->m_realSize->goal() / PMONITOR->m_scale); - } - } - - PWINDOW->m_position = PWINDOW->m_realPosition->goal(); - PWINDOW->m_size = PWINDOW->m_realSize->goal(); - - PWINDOW->m_workspace = g_pCompositor->getMonitorFromVector(PWINDOW->m_realPosition->value() + PWINDOW->m_realSize->value() / 2.f)->m_activeWorkspace; - - g_pCompositor->changeWindowZOrder(PWINDOW, true); - PWINDOW->updateWindowDecos(); - g_pHyprRenderer->damageWindow(PWINDOW); - - PWINDOW->m_reportedPosition = PWINDOW->m_realPosition->goal(); - PWINDOW->m_pendingReportedSize = PWINDOW->m_realSize->goal(); - } -} diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 52fa659c5..e80747be3 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -30,7 +30,7 @@ #include "../i18n/Engine.hpp" #include "sync/SyncTimeline.hpp" #include "time/Time.hpp" -#include "../desktop/LayerSurface.hpp" +#include "../desktop/view/LayerSurface.hpp" #include "../desktop/state/FocusState.hpp" #include #include "debug/Log.hpp" @@ -1295,7 +1295,8 @@ void CMonitor::changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal, bo if (!pWindow) { if (*PFOLLOWMOUSE == 1) - pWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + pWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), + Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); if (!pWindow) pWindow = pWorkspace->getTopLeftWindow(); @@ -2038,7 +2039,7 @@ std::optional CMonitor::getFSImageDescripti if (!FS_WINDOW) return {}; // should be unreachable - const auto ROOT_SURF = FS_WINDOW->m_wlSurface->resource(); + const auto ROOT_SURF = FS_WINDOW->wlSurface()->resource(); const auto SURF = ROOT_SURF->findWithCM(); return SURF ? SURF->m_colorManagement->imageDescription() : SImageDescription{}; } diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index fef392ca1..debf2ec74 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -335,8 +335,10 @@ class CMonitor { bool m_enabled = false; bool m_renderingInitPassed = false; - WP m_previousFSWindow; + + PHLWINDOWREF m_previousFSWindow; bool m_needsHDRupdate = false; + NColorManagement::SImageDescription m_imageDescription; bool m_noShaderCTM = false; // sets drm CTM, restore needed diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 9a22b77fb..ec0737876 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -1,9 +1,9 @@ #pragma once #include "../defines.hpp" -#include "../desktop/Subsurface.hpp" -#include "../desktop/Popup.hpp" -#include "../desktop/WLSurface.hpp" +#include "../desktop/view/Subsurface.hpp" +#include "../desktop/view/Popup.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../macros.hpp" #include "../desktop/DesktopTypes.hpp" #include "memory/Memory.hpp" diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index a12f90295..c78b6f281 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -296,7 +296,8 @@ void CHyprDwindleLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dir if (PMONITOR->m_id == MONFROMCURSOR->m_id && (PNODE->workspaceID == PMONITOR->activeWorkspaceID() || (g_pCompositor->isWorkspaceSpecial(PNODE->workspaceID) && PMONITOR->m_activeSpecialWorkspace)) && !*PUSEACTIVE) { - OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | SKIP_FULLSCREEN_PRIORITY)); + OPENINGON = getNodeFromWindow( + g_pCompositor->vectorToWindowUnified(MOUSECOORDS, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::SKIP_FULLSCREEN_PRIORITY)); if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR)) OPENINGON = getClosestNodeOnWorkspace(PNODE->workspaceID, MOUSECOORDS); @@ -306,7 +307,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dir Desktop::focusState()->window()->m_workspace == pWindow->m_workspace && Desktop::focusState()->window()->m_isMapped) { OPENINGON = getNodeFromWindow(Desktop::focusState()->window()); } else { - OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS)); + OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS)); } if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR)) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index e86f00bcd..73f9d8532 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -4,7 +4,7 @@ #include "../render/decorations/CHyprGroupBarDecoration.hpp" #include "../config/ConfigValue.hpp" #include "../config/ConfigManager.hpp" -#include "../desktop/Window.hpp" +#include "../desktop/view/Window.hpp" #include "../desktop/state/FocusState.hpp" #include "../protocols/XDGShell.hpp" #include "../protocols/core/Compositor.hpp" @@ -122,7 +122,7 @@ void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) { } if (desiredGeometry.width <= 5 || desiredGeometry.height <= 5) { - const auto PWINDOWSURFACE = pWindow->m_wlSurface->resource(); + const auto PWINDOWSURFACE = pWindow->wlSurface()->resource(); *pWindow->m_realSize = PWINDOWSURFACE->m_current.size; if ((desiredGeometry.width <= 1 || desiredGeometry.height <= 1) && pWindow->m_isX11 && @@ -329,7 +329,8 @@ void IHyprLayout::onEndDragWindow() { if (g_pInputManager->m_dragMode == MBIND_MOVE) { g_pHyprRenderer->damageWindow(DRAGGINGWINDOW); const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); - PHLWINDOW pWindow = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING, DRAGGINGWINDOW); + PHLWINDOW pWindow = + g_pCompositor->vectorToWindowUnified(MOUSECOORDS, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING, DRAGGINGWINDOW); if (pWindow) { if (pWindow->checkInputOnDecos(INPUT_TYPE_DRAG_END, MOUSECOORDS, DRAGGINGWINDOW)) @@ -371,8 +372,9 @@ void IHyprLayout::onEndDragWindow() { if (*PPRECISEMOUSE) { eDirection direction = DIRECTION_DEFAULT; - const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); - const PHLWINDOW pReferenceWindow = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING, DRAGGINGWINDOW); + const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); + const PHLWINDOW pReferenceWindow = + g_pCompositor->vectorToWindowUnified(MOUSECOORDS, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING, DRAGGINGWINDOW); if (pReferenceWindow && pReferenceWindow != DRAGGINGWINDOW) { const Vector2D draggedCenter = DRAGGINGWINDOW->m_realPosition->goal() + DRAGGINGWINDOW->m_realSize->goal() / 2.f; @@ -432,7 +434,7 @@ void IHyprLayout::performSnap(Vector2D& sourcePos, Vector2D& sourceSize, PHLWIND double start = 0; double end = 0; }; - const auto EXTENTS = DRAGGINGWINDOW->getWindowExtentsUnified(RESERVED_EXTENTS | INPUT_EXTENTS); + const auto EXTENTS = DRAGGINGWINDOW->getWindowExtentsUnified(Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS); SRange sourceX = {sourcePos.x - EXTENTS.topLeft.x, sourcePos.x + sourceSize.x + EXTENTS.bottomRight.x}; SRange sourceY = {sourcePos.y - EXTENTS.topLeft.y, sourcePos.y + sourceSize.y + EXTENTS.bottomRight.y}; @@ -450,7 +452,7 @@ void IHyprLayout::performSnap(Vector2D& sourcePos, Vector2D& sourceSize, PHLWIND other->isX11OverrideRedirect()) continue; - const CBox SURF = other->getWindowBoxUnified(RESERVED_EXTENTS); + const CBox SURF = other->getWindowBoxUnified(Desktop::View::RESERVED_EXTENTS); const SRange SURFBX = {SURF.x - GAPSX, SURF.x + SURF.w + GAPSX}; const SRange SURFBY = {SURF.y - GAPSY, SURF.y + SURF.h + GAPSY}; @@ -833,7 +835,7 @@ void IHyprLayout::fitFloatingWindowOnMonitor(PHLWINDOW w, std::optional tb if (!PMONITOR) return; - const auto EXTENTS = w->getWindowExtentsUnified(RESERVED_EXTENTS | INPUT_EXTENTS); + const auto EXTENTS = w->getWindowExtentsUnified(Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS); CBox targetBoxMonLocal = tb.value_or(w->getWindowMainSurfaceBox()).translate(-PMONITOR->m_position).addExtents(EXTENTS); const auto MONITOR_LOCAL_BOX = PMONITOR->logicalBoxMinusReserved().translate(-PMONITOR->m_position); @@ -906,7 +908,8 @@ PHLWINDOW IHyprLayout::getNextWindowCandidate(PHLWINDOW pWindow) { return m_lastTiledWindow.lock(); // if we don't, let's try to find any window that is in the middle - if (const auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowUnified(pWindow->middle(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + if (const auto PWINDOWCANDIDATE = + g_pCompositor->vectorToWindowUnified(pWindow->middle(), Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); PWINDOWCANDIDATE && PWINDOWCANDIDATE != pWindow) return PWINDOWCANDIDATE; @@ -922,7 +925,7 @@ PHLWINDOW IHyprLayout::getNextWindowCandidate(PHLWINDOW pWindow) { } // if it was a tiled window, we first try to find the window that will replace it. - auto pWindowCandidate = g_pCompositor->vectorToWindowUnified(pWindow->middle(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + auto pWindowCandidate = g_pCompositor->vectorToWindowUnified(pWindow->middle(), Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); if (!pWindowCandidate) pWindowCandidate = PWORKSPACE->getTopLeftWindow(); diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index ad19700d0..0b23bc3b3 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -4,7 +4,6 @@ #include "../managers/input/InputManager.hpp" #include -class CWindow; class CGradientValueData; struct SWindowRenderLayoutHints { diff --git a/src/macros.hpp b/src/macros.hpp index 7fa25cfb3..8a37d6ddb 100644 --- a/src/macros.hpp +++ b/src/macros.hpp @@ -34,13 +34,6 @@ // max value 32 because killed is a int uniform #define POINTER_PRESSED_HISTORY_LENGTH 32 -#define LISTENER(name) \ - void listener_##name(wl_listener*, void*); \ - inline wl_listener listen_##name = {.notify = listener_##name} -#define DYNLISTENFUNC(name) void listener_##name(void*, void*) -#define DYNLISTENER(name) CHyprWLListener hyprListener_##name -#define DYNMULTILISTENER(name) wl_listener listen_##name - #define VECINRECT(vec, x1, y1, x2, y2) ((vec).x >= (x1) && (vec).x < (x2) && (vec).y >= (y1) && (vec).y < (y2)) #define VECNOTINRECT(vec, x1, y1, x2, y2) ((vec).x < (x1) || (vec).x >= (x2) || (vec).y < (y1) || (vec).y >= (y2)) diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index d2905a1e3..d3c263391 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -128,7 +128,7 @@ SP CCursorManager::getCursorBuffer() { return !m_cursorBuffers.empty() ? m_cursorBuffers.back() : nullptr; } -void CCursorManager::setCursorSurface(SP surf, const Vector2D& hotspot) { +void CCursorManager::setCursorSurface(SP surf, const Vector2D& hotspot) { if (!surf || !surf->resource()) g_pPointerManager->resetCursorImage(); else diff --git a/src/managers/CursorManager.hpp b/src/managers/CursorManager.hpp index dd3238af4..f4c42d30d 100644 --- a/src/managers/CursorManager.hpp +++ b/src/managers/CursorManager.hpp @@ -3,6 +3,7 @@ #include #include #include "../includes.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../helpers/math/Math.hpp" #include "../helpers/memory/Memory.hpp" #include "../macros.hpp" @@ -10,8 +11,6 @@ #include "managers/XCursorManager.hpp" #include -class CWLSurface; - AQUAMARINE_FORWARD(IBuffer); class CCursorBuffer : public Aquamarine::IBuffer { @@ -43,7 +42,7 @@ class CCursorManager { SP getCursorBuffer(); void setCursorFromName(const std::string& name); - void setCursorSurface(SP surf, const Vector2D& hotspot); + void setCursorSurface(SP surf, const Vector2D& hotspot); void setCursorBuffer(SP buf, const Vector2D& hotspot, const float& scale); void setAnimationTimer(const int& frame, const int& delay); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 46f97d1f4..bda1ff5a3 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -68,7 +68,7 @@ static std::vector> getHyprlandLaunchEnv(PHL } result.push_back(std::make_pair<>("HL_INITIAL_WORKSPACE_TOKEN", - g_pTokenManager->registerNewToken(SInitialWorkspaceToken{{}, pInitialWorkspace->getConfigName()}, std::chrono::months(1337)))); + g_pTokenManager->registerNewToken(Desktop::View::SInitialWorkspaceToken{{}, pInitialWorkspace->getConfigName()}, std::chrono::months(1337)))); return result; } @@ -1294,9 +1294,9 @@ SDispatchResult CKeybindManager::changeworkspace(std::string args) { if (*PWARPONWORKSPACECHANGE > 0) { auto PLAST = pWorkspaceToChangeTo->getLastFocusedWindow(); - auto HLSurface = CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); + auto HLSurface = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); - if (PLAST && (!HLSurface || HLSurface->getWindow())) + if (PLAST && (!HLSurface || HLSurface->view()->type() == Desktop::View::VIEW_TYPE_WINDOW)) PLAST->warpCursor(*PWARPONWORKSPACECHANGE == 2); } @@ -1344,16 +1344,17 @@ SDispatchResult CKeybindManager::fullscreenStateActive(std::string args) { clientMode = std::stoi(ARGS[1]); } catch (std::exception& e) { clientMode = -1; } - const SFullscreenState STATE = SFullscreenState{.internal = (internalMode != -1 ? sc(internalMode) : PWINDOW->m_fullscreenState.internal), - .client = (clientMode != -1 ? sc(clientMode) : PWINDOW->m_fullscreenState.client)}; + const Desktop::View::SFullscreenState STATE = + Desktop::View::SFullscreenState{.internal = (internalMode != -1 ? sc(internalMode) : PWINDOW->m_fullscreenState.internal), + .client = (clientMode != -1 ? sc(clientMode) : PWINDOW->m_fullscreenState.client)}; if (ARGS.size() <= 2 || ARGS[2] == "toggle") { if (internalMode != -1 && clientMode != -1 && PWINDOW->m_fullscreenState.internal == STATE.internal && PWINDOW->m_fullscreenState.client == STATE.client) - g_pCompositor->setWindowFullscreenState(PWINDOW, SFullscreenState{.internal = FSMODE_NONE, .client = FSMODE_NONE}); + g_pCompositor->setWindowFullscreenState(PWINDOW, Desktop::View::SFullscreenState{.internal = FSMODE_NONE, .client = FSMODE_NONE}); else if (internalMode != -1 && clientMode == -1 && PWINDOW->m_fullscreenState.internal == STATE.internal) - g_pCompositor->setWindowFullscreenState(PWINDOW, SFullscreenState{.internal = FSMODE_NONE, .client = PWINDOW->m_fullscreenState.client}); + g_pCompositor->setWindowFullscreenState(PWINDOW, Desktop::View::SFullscreenState{.internal = FSMODE_NONE, .client = PWINDOW->m_fullscreenState.client}); else if (internalMode == -1 && clientMode != -1 && PWINDOW->m_fullscreenState.client == STATE.client) - g_pCompositor->setWindowFullscreenState(PWINDOW, SFullscreenState{.internal = PWINDOW->m_fullscreenState.internal, .client = FSMODE_NONE}); + g_pCompositor->setWindowFullscreenState(PWINDOW, Desktop::View::SFullscreenState{.internal = PWINDOW->m_fullscreenState.internal, .client = FSMODE_NONE}); else g_pCompositor->setWindowFullscreenState(PWINDOW, STATE); } else if (ARGS[2] == "set") { @@ -1463,7 +1464,9 @@ SDispatchResult CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { } if (PWINDOW == Desktop::focusState()->window()) { - if (const auto PATCOORDS = g_pCompositor->vectorToWindowUnified(OLDMIDDLE, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING, PWINDOW); PATCOORDS) + if (const auto PATCOORDS = + g_pCompositor->vectorToWindowUnified(OLDMIDDLE, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING, PWINDOW); + PATCOORDS) Desktop::focusState()->fullWindowFocus(PATCOORDS); else g_pInputManager->refocus(); @@ -2135,9 +2138,9 @@ SDispatchResult CKeybindManager::toggleSpecialWorkspace(std::string args) { if (*PWARPONTOGGLESPECIAL > 0) { auto PLAST = focusedWorkspace->getLastFocusedWindow(); - auto HLSurface = CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); + auto HLSurface = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); - if (PLAST && (!HLSurface || HLSurface->getWindow())) + if (PLAST && (!HLSurface || HLSurface->view()->type() == Desktop::View::VIEW_TYPE_WINDOW)) PLAST->warpCursor(*PWARPONTOGGLESPECIAL == 2); } @@ -2398,9 +2401,9 @@ SDispatchResult CKeybindManager::pass(std::string regexp) { // pass all mf shit if (!XWTOXW) { if (g_pKeybindManager->m_lastCode != 0) - g_pSeatManager->setKeyboardFocus(PWINDOW->m_wlSurface->resource()); + g_pSeatManager->setKeyboardFocus(PWINDOW->wlSurface()->resource()); else - g_pSeatManager->setPointerFocus(PWINDOW->m_wlSurface->resource(), {1, 1}); + g_pSeatManager->setPointerFocus(PWINDOW->wlSurface()->resource(), {1, 1}); } g_pSeatManager->sendKeyboardMods(g_pInputManager->getModsFromAllKBs(), 0, 0, 0); @@ -2546,15 +2549,15 @@ SDispatchResult CKeybindManager::sendshortcut(std::string args) { } if (!isMouse) - g_pSeatManager->setKeyboardFocus(PWINDOW->m_wlSurface->resource()); + g_pSeatManager->setKeyboardFocus(PWINDOW->wlSurface()->resource()); else - g_pSeatManager->setPointerFocus(PWINDOW->m_wlSurface->resource(), {1, 1}); + g_pSeatManager->setPointerFocus(PWINDOW->wlSurface()->resource(), {1, 1}); } //copied the rest from pass and modified it // if wl -> xwl, activate destination if (PWINDOW && PWINDOW->m_isX11 && Desktop::focusState()->window() && !Desktop::focusState()->window()->m_isX11) - g_pXWaylandManager->activateSurface(PWINDOW->m_wlSurface->resource(), true); + g_pXWaylandManager->activateSurface(PWINDOW->wlSurface()->resource(), true); // if xwl -> xwl, send to current. Timing issues make this not work. if (PWINDOW && PWINDOW->m_isX11 && Desktop::focusState()->window() && Desktop::focusState()->window()->m_isX11) PWINDOW = nullptr; @@ -2723,7 +2726,8 @@ SDispatchResult CKeybindManager::pinActive(std::string args) { const auto PWORKSPACE = PWINDOW->m_workspace; - PWORKSPACE->m_lastFocusedWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS); + PWORKSPACE->m_lastFocusedWindow = + g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS); g_pEventManager->postEvent(SHyprIPCEvent{"pin", std::format("{:x},{}", rc(PWINDOW.get()), sc(PWINDOW->m_pinned))}); EMIT_HOOK_EVENT("pin", PWINDOW); @@ -2758,7 +2762,7 @@ SDispatchResult CKeybindManager::changeMouseBindMode(const eMouseBindMode MODE) return {}; const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); - const PHLWINDOW PWINDOW = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + const PHLWINDOW PWINDOW = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); if (!PWINDOW) return SDispatchResult{.passEvent = true}; @@ -3014,7 +3018,7 @@ SDispatchResult CKeybindManager::moveWindowOrGroup(std::string args) { } else moveWindowIntoGroup(PWINDOW, PWINDOWINDIR); } else if (PWINDOWINDIR) { // target is regular window - if ((!*PIGNOREGROUPLOCK && ISWINDOWGROUPLOCKED) || !ISWINDOWGROUP || (ISWINDOWGROUPSINGLE && PWINDOW->m_groupRules & GROUP_SET_ALWAYS)) { + if ((!*PIGNOREGROUPLOCK && ISWINDOWGROUPLOCKED) || !ISWINDOWGROUP || (ISWINDOWGROUPSINGLE && PWINDOW->m_groupRules & Desktop::View::GROUP_SET_ALWAYS)) { g_pLayoutManager->getCurrentLayout()->moveWindowTo(PWINDOW, args); PWINDOW->warpCursor(); } else diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index 5d2672f33..f949e6ce6 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -126,7 +126,7 @@ void CPointerManager::setCursorBuffer(SP buf, const Vector2 damageIfSoftware(); } -void CPointerManager::setCursorSurface(SP surf, const Vector2D& hotspot) { +void CPointerManager::setCursorSurface(SP surf, const Vector2D& hotspot) { damageIfSoftware(); if (surf == m_currentCursorImage.surface) { diff --git a/src/managers/PointerManager.hpp b/src/managers/PointerManager.hpp index 62a5d18f2..e7294fd40 100644 --- a/src/managers/PointerManager.hpp +++ b/src/managers/PointerManager.hpp @@ -4,7 +4,7 @@ #include "../devices/ITouch.hpp" #include "../devices/Tablet.hpp" #include "../helpers/math/Math.hpp" -#include "../desktop/WLSurface.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../helpers/sync/SyncTimeline.hpp" #include "../helpers/time/Time.hpp" #include @@ -40,7 +40,7 @@ class CPointerManager { void warpAbsolute(Vector2D abs, SP dev); void setCursorBuffer(SP buf, const Vector2D& hotspot, const float& scale); - void setCursorSurface(SP buf, const Vector2D& hotspot); + void setCursorSurface(SP buf, const Vector2D& hotspot); void resetCursorImage(bool apply = true); void lockSoftwareForMonitor(PHLMONITOR pMonitor); @@ -140,16 +140,16 @@ class CPointerManager { } m_currentMonitorLayout; struct { - SP pBuffer; - SP bufferTex; - WP surface; + SP pBuffer; + SP bufferTex; + WP surface; - Vector2D hotspot; - Vector2D size; - float scale = 1.F; + Vector2D hotspot; + Vector2D size; + float scale = 1.F; - CHyprSignalListener destroySurface; - CHyprSignalListener commitSurface; + CHyprSignalListener destroySurface; + CHyprSignalListener commitSurface; } m_currentCursorImage; // TODO: support various sizes per-output so we can have pixel-perfect cursors Vector2D m_pointerPos = {0, 0}; diff --git a/src/managers/SeatManager.cpp b/src/managers/SeatManager.cpp index 6d49c97eb..0f4ea93ce 100644 --- a/src/managers/SeatManager.cpp +++ b/src/managers/SeatManager.cpp @@ -8,7 +8,7 @@ #include "../Compositor.hpp" #include "../desktop/state/FocusState.hpp" #include "../devices/IKeyboard.hpp" -#include "../desktop/LayerSurface.hpp" +#include "../desktop/view/LayerSurface.hpp" #include "../managers/input/InputManager.hpp" #include "../managers/HookSystemManager.hpp" #include "wlr-layer-shell-unstable-v1.hpp" @@ -517,7 +517,7 @@ void CSeatManager::refocusGrab() { // try to find a surf in focus first const auto MOUSE = g_pInputManager->getMouseCoordsInternal(); for (auto const& s : m_seatGrab->m_surfs) { - auto hlSurf = CWLSurface::fromResource(s.lock()); + auto hlSurf = Desktop::View::CWLSurface::fromResource(s.lock()); if (!hlSurf) continue; @@ -640,13 +640,13 @@ void CSeatManager::setGrab(SP grab) { focusedSurf = oldGrab->m_surfs.front().lock(); if (focusedSurf) { - auto hlSurface = CWLSurface::fromResource(focusedSurf); + auto hlSurface = Desktop::View::CWLSurface::fromResource(focusedSurf); if (hlSurface) { - auto popup = hlSurface->getPopup(); + auto popup = Desktop::View::CPopup::fromView(hlSurface->view()); if (popup) { auto t1Owner = popup->getT1Owner(); if (t1Owner) - parentWindow = t1Owner->getWindow(); + parentWindow = Desktop::View::CWindow::fromView(t1Owner->view()); } } } @@ -667,22 +667,22 @@ void CSeatManager::setGrab(SP grab) { } else g_pInputManager->refocus(); - auto currentFocus = m_state.keyboardFocus.lock(); - auto refocus = !currentFocus; + auto currentFocus = m_state.keyboardFocus.lock(); + auto refocus = !currentFocus; - SP surf; - PHLLS layer; + SP surf; + PHLLS layer; if (!refocus) { - surf = CWLSurface::fromResource(currentFocus); - layer = surf ? surf->getLayer() : nullptr; + surf = Desktop::View::CWLSurface::fromResource(currentFocus); + layer = surf ? Desktop::View::CLayerSurface::fromView(surf->view()) : nullptr; } if (!refocus && !layer) { - auto popup = surf ? surf->getPopup() : nullptr; + auto popup = surf ? Desktop::View::CPopup::fromView(surf->view()) : nullptr; if (popup) { auto parent = popup->getT1Owner(); - layer = parent->getLayer(); + layer = Desktop::View::CLayerSurface::fromView(parent->view()); } } diff --git a/src/managers/SessionLockManager.cpp b/src/managers/SessionLockManager.cpp index f460e17e7..1b0ec0bde 100644 --- a/src/managers/SessionLockManager.cpp +++ b/src/managers/SessionLockManager.cpp @@ -5,6 +5,7 @@ #include "../protocols/SessionLock.hpp" #include "../render/Renderer.hpp" #include "../desktop/state/FocusState.hpp" +#include "../desktop/view/SessionLock.hpp" #include "./managers/SeatManager.hpp" #include "./managers/input/InputManager.hpp" #include "./managers/eventLoop/EventLoopManager.hpp" @@ -68,9 +69,11 @@ void CSessionLockManager::onNewSessionLock(SP pLock) { m_sessionLock->listeners.newSurface = pLock->m_events.newLockSurface.listen([this](const SP& surface) { const auto PMONITOR = surface->monitor(); - const auto NEWSURFACE = m_sessionLock->vSessionLockSurfaces.emplace_back(makeUnique(surface)).get(); + const auto NEWSURFACE = m_sessionLock->vSessionLockSurfaces.emplace_back(makeShared(surface)); NEWSURFACE->iMonitorID = PMONITOR->m_id; PROTO::fractional->sendScale(surface->surface(), PMONITOR->m_scale); + + g_pCompositor->m_otherViews.emplace_back(Desktop::View::CSessionLock::create(surface)); }); m_sessionLock->listeners.unlock = pLock->m_events.unlockAndDestroy.listen([this] { diff --git a/src/managers/SessionLockManager.hpp b/src/managers/SessionLockManager.hpp index 2938a851a..efcaf09a7 100644 --- a/src/managers/SessionLockManager.hpp +++ b/src/managers/SessionLockManager.hpp @@ -33,7 +33,7 @@ struct SSessionLock { CTimer lockTimer; SP sendDeniedTimer; - std::vector> vSessionLockSurfaces; + std::vector> vSessionLockSurfaces; struct { CHyprSignalListener newSurface; diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 38afe4acc..d0cdc6dba 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -1,7 +1,6 @@ #include "XWaylandManager.hpp" #include "../Compositor.hpp" #include "../desktop/state/FocusState.hpp" -#include "../events/Events.hpp" #include "../config/ConfigValue.hpp" #include "../helpers/Monitor.hpp" #include "../protocols/XDGShell.hpp" @@ -22,20 +21,20 @@ CHyprXWaylandManager::~CHyprXWaylandManager() { } SP CHyprXWaylandManager::getWindowSurface(PHLWINDOW pWindow) { - return pWindow ? pWindow->m_wlSurface->resource() : nullptr; + return pWindow ? pWindow->wlSurface()->resource() : nullptr; } void CHyprXWaylandManager::activateSurface(SP pSurface, bool activate) { if (!pSurface) return; - auto HLSurface = CWLSurface::fromResource(pSurface); + auto HLSurface = Desktop::View::CWLSurface::fromResource(pSurface); if (!HLSurface) { Debug::log(TRACE, "CHyprXWaylandManager::activateSurface on non-desktop surface, ignoring"); return; } - const auto PWINDOW = HLSurface->getWindow(); + const auto PWINDOW = Desktop::View::CWindow::fromView(HLSurface->view()); if (!PWINDOW) { Debug::log(TRACE, "CHyprXWaylandManager::activateSurface on non-window surface, ignoring"); return; diff --git a/src/managers/XWaylandManager.hpp b/src/managers/XWaylandManager.hpp index 59eee4c58..a26b7b684 100644 --- a/src/managers/XWaylandManager.hpp +++ b/src/managers/XWaylandManager.hpp @@ -1,10 +1,9 @@ #pragma once #include "../defines.hpp" +#include "../desktop/DesktopTypes.hpp" #include -class CWindow; // because clangd -using PHLWINDOW = SP; class CWLSurfaceResource; class CHyprXWaylandManager { diff --git a/src/managers/animation/AnimationManager.cpp b/src/managers/animation/AnimationManager.cpp index c304fc56a..a09f391b0 100644 --- a/src/managers/animation/AnimationManager.cpp +++ b/src/managers/animation/AnimationManager.cpp @@ -6,8 +6,8 @@ #include "../../helpers/AnimatedVariable.hpp" #include "../../macros.hpp" #include "../../config/ConfigValue.hpp" -#include "../../desktop/Window.hpp" -#include "../../desktop/LayerSurface.hpp" +#include "../../desktop/view/Window.hpp" +#include "../../desktop/view/LayerSurface.hpp" #include "../eventLoop/EventLoopManager.hpp" #include "../../helpers/varlist/VarList.hpp" #include "../../render/Renderer.hpp" diff --git a/src/managers/animation/DesktopAnimationManager.cpp b/src/managers/animation/DesktopAnimationManager.cpp index a56aa2f91..16f70f9a6 100644 --- a/src/managers/animation/DesktopAnimationManager.cpp +++ b/src/managers/animation/DesktopAnimationManager.cpp @@ -1,7 +1,7 @@ #include "DesktopAnimationManager.hpp" -#include "../../desktop/LayerSurface.hpp" -#include "../../desktop/Window.hpp" +#include "../../desktop/view/LayerSurface.hpp" +#include "../../desktop/view/Window.hpp" #include "../../desktop/Workspace.hpp" #include "../../config/ConfigManager.hpp" diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp index 851e917a6..0034a10fa 100644 --- a/src/managers/input/IdleInhibitor.cpp +++ b/src/managers/input/IdleInhibitor.cpp @@ -15,7 +15,7 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) { recheckIdleInhibitorStatus(); }); - auto WLSurface = CWLSurface::fromResource(PINHIBIT->inhibitor->m_surface.lock()); + auto WLSurface = Desktop::View::CWLSurface::fromResource(PINHIBIT->inhibitor->m_surface.lock()); if (!WLSurface) { Debug::log(LOG, "Inhibitor has no HL Surface attached to it, likely meaning it's a non-desktop element. Assuming it's visible."); @@ -38,7 +38,7 @@ void CInputManager::recheckIdleInhibitorStatus() { return; } - auto WLSurface = CWLSurface::fromResource(ii->inhibitor->m_surface.lock()); + auto WLSurface = Desktop::View::CWLSurface::fromResource(ii->inhibitor->m_surface.lock()); if (!WLSurface) continue; @@ -78,12 +78,12 @@ bool CInputManager::isWindowInhibiting(const PHLWINDOW& w, bool onlyHl) { continue; bool isInhibiting = false; - w->m_wlSurface->resource()->breadthfirst( + w->wlSurface()->resource()->breadthfirst( [&ii](SP surf, const Vector2D& pos, void* data) { if (ii->inhibitor->m_surface != surf) return; - auto WLSurface = CWLSurface::fromResource(surf); + auto WLSurface = Desktop::View::CWLSurface::fromResource(surf); if (!WLSurface) return; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index bc631ecd8..98662d120 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -7,8 +7,8 @@ #include #include "../../config/ConfigValue.hpp" #include "../../config/ConfigManager.hpp" -#include "../../desktop/Window.hpp" -#include "../../desktop/LayerSurface.hpp" +#include "../../desktop/view/Window.hpp" +#include "../../desktop/view/LayerSurface.hpp" #include "../../desktop/state/FocusState.hpp" #include "../../protocols/CursorShape.hpp" #include "../../protocols/IdleInhibit.hpp" @@ -95,7 +95,7 @@ CInputManager::CInputManager() { g_pHyprRenderer->setCursorFromName(shape); }); - m_cursorSurfaceInfo.wlSurface = CWLSurface::create(); + m_cursorSurfaceInfo.wlSurface = Desktop::View::CWLSurface::create(); } CInputManager::~CInputManager() { @@ -240,7 +240,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st // constraints if (!g_pSeatManager->m_mouse.expired() && isConstrained()) { - const auto SURF = CWLSurface::fromResource(Desktop::focusState()->surface()); + const auto SURF = Desktop::View::CWLSurface::fromResource(Desktop::focusState()->surface()); const auto CONSTRAINT = SURF ? SURF->constraint() : nullptr; if (CONSTRAINT) { @@ -251,7 +251,8 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st const auto RG = CONSTRAINT->logicConstraintRegion(); const auto CLOSEST = RG.closestPoint(mouseCoords); const auto BOX = SURF->getSurfaceBoxGlobal(); - const auto CLOSESTLOCAL = (CLOSEST - (BOX.has_value() ? BOX->pos() : Vector2D{})) * (SURF->getWindow() ? SURF->getWindow()->m_X11SurfaceScaledBy : 1.0); + const auto WINDOW = Desktop::View::CWindow::fromView(SURF->view()); + const auto CLOSESTLOCAL = (CLOSEST - (BOX.has_value() ? BOX->pos() : Vector2D{})) * (WINDOW ? WINDOW->m_X11SurfaceScaledBy : 1.0); g_pCompositor->warpCursorTo(CLOSEST, true); g_pSeatManager->sendPointerMotion(time, CLOSESTLOCAL); @@ -268,7 +269,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st Desktop::focusState()->rawMonitorFocus(PMONITOR); // check for windows that have focus priority like our permission popups - pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, FOCUS_PRIORITY); + pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, Desktop::View::FOCUS_PRIORITY); if (pFoundWindow) foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); @@ -313,7 +314,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st if (forcedFocus && !foundSurface) { pFoundWindow = forcedFocus; surfacePos = pFoundWindow->m_realPosition->value(); - foundSurface = pFoundWindow->m_wlSurface->resource(); + foundSurface = pFoundWindow->wlSurface()->resource(); } // if we are holding a pointer button, @@ -330,15 +331,16 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st m_focusHeldByButtons = true; m_refocusHeldByButtons = refocus; } else { - auto HLSurface = CWLSurface::fromResource(foundSurface); + auto HLSurface = Desktop::View::CWLSurface::fromResource(foundSurface); if (HLSurface) { const auto BOX = HLSurface->getSurfaceBoxGlobal(); if (BOX) { - const auto PWINDOW = HLSurface->getWindow(); + const auto PWINDOW = HLSurface->view()->type() == Desktop::View::VIEW_TYPE_WINDOW ? dynamicPointerCast(HLSurface->view()) : nullptr; surfacePos = BOX->pos(); - pFoundLayerSurface = HLSurface->getLayer(); + pFoundLayerSurface = + HLSurface->view()->type() == Desktop::View::VIEW_TYPE_LAYER_SURFACE ? dynamicPointerCast(HLSurface->view()) : nullptr; if (!pFoundLayerSurface) pFoundWindow = !PWINDOW || PWINDOW->isHidden() ? Desktop::focusState()->window() : PWINDOW; } else // reset foundSurface, find one normally @@ -356,7 +358,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &g_pInputManager->m_exclusiveLSes, &surfaceCoords, &pFoundLayerSurface); if (!foundSurface) { - foundSurface = (*g_pInputManager->m_exclusiveLSes.begin())->m_surface->resource(); + foundSurface = (*g_pInputManager->m_exclusiveLSes.begin())->wlSurface()->resource(); surfacePos = (*g_pInputManager->m_exclusiveLSes.begin())->m_realPosition->goal(); } } @@ -383,7 +385,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st // then, we check if the workspace doesn't have a fullscreen window const auto PWORKSPACE = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace; - const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowUnified(mouseCoords, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); if (PWORKSPACE->m_hasFullscreenWindow && !foundSurface && PWORKSPACE->m_fullscreenMode == FSMODE_FULLSCREEN) { pFoundWindow = PWORKSPACE->getFullscreenWindow(); @@ -402,7 +404,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); surfacePos = Vector2D(-1337, -1337); } else { - foundSurface = pFoundWindow->m_wlSurface->resource(); + foundSurface = pFoundWindow->wlSurface()->resource(); surfacePos = pFoundWindow->m_realPosition->value(); } } @@ -413,7 +415,8 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st if (!foundSurface) { if (PMONITOR->m_activeSpecialWorkspace) { if (pFoundWindow != PWINDOWIDEAL) - pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + pFoundWindow = + g_pCompositor->vectorToWindowUnified(mouseCoords, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); if (pFoundWindow && !pFoundWindow->onSpecialWorkspace()) { pFoundWindow = PWORKSPACE->getFullscreenWindow(); @@ -427,7 +430,8 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st if (!foundSurface) { if (pFoundWindow != PWINDOWIDEAL) - pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + pFoundWindow = + g_pCompositor->vectorToWindowUnified(mouseCoords, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); if (!(pFoundWindow && (pFoundWindow->m_isFloating && (pFoundWindow->m_createdOverFullscreen || pFoundWindow->m_pinned)))) pFoundWindow = PWORKSPACE->getFullscreenWindow(); @@ -437,18 +441,18 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st } else { if (pFoundWindow != PWINDOWIDEAL) - pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); } if (pFoundWindow) { if (!pFoundWindow->m_isX11) { foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); if (!foundSurface) { - foundSurface = pFoundWindow->m_wlSurface->resource(); + foundSurface = pFoundWindow->wlSurface()->resource(); surfacePos = pFoundWindow->m_realPosition->value(); } } else { - foundSurface = pFoundWindow->m_wlSurface->resource(); + foundSurface = pFoundWindow->wlSurface()->resource(); surfacePos = pFoundWindow->m_realPosition->value(); } } @@ -474,7 +478,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st // we need to grab the last surface. foundSurface = g_pSeatManager->m_state.pointerFocus.lock(); - auto HLSurface = CWLSurface::fromResource(foundSurface); + auto HLSurface = Desktop::View::CWLSurface::fromResource(foundSurface); if (HLSurface) { const auto BOX = HLSurface->getSurfaceBoxGlobal(); @@ -534,7 +538,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st return; } - if (pFoundWindow && foundSurface == pFoundWindow->m_wlSurface->resource() && !m_cursorImageOverridden) { + if (pFoundWindow && foundSurface == pFoundWindow->wlSurface()->resource() && !m_cursorImageOverridden) { const auto BOX = pFoundWindow->getWindowMainSurfaceBox(); if (VECNOTINRECT(mouseCoords, BOX.x, BOX.y, BOX.x + BOX.width, BOX.y + BOX.height)) g_pHyprRenderer->setCursorFromName("left_ptr"); @@ -738,7 +742,7 @@ void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e) { return; const auto mouseCoords = g_pInputManager->getMouseCoordsInternal(); - const auto w = g_pCompositor->vectorToWindowUnified(mouseCoords, ALLOW_FLOATING | RESERVED_EXTENTS | INPUT_EXTENTS); + const auto w = g_pCompositor->vectorToWindowUnified(mouseCoords, Desktop::View::ALLOW_FLOATING | Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS); if (w && !m_lastFocusOnLS && !g_pSessionLockManager->isSessionLocked() && w->checkInputOnDecos(INPUT_TYPE_BUTTON, mouseCoords, e)) return; @@ -779,10 +783,10 @@ void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e) { if (!g_pSeatManager->m_state.pointerFocus) break; - auto HLSurf = CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); + auto HLSurf = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); - if (HLSurf && HLSurf->getWindow()) - g_pCompositor->changeWindowZOrder(HLSurf->getWindow(), true); + if (HLSurf && HLSurf->view()->type() == Desktop::View::VIEW_TYPE_WINDOW) + g_pCompositor->changeWindowZOrder(dynamicPointerCast(HLSurf->view()), true); break; } @@ -805,7 +809,8 @@ void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e) { void CInputManager::processMouseDownKill(const IPointer::SButtonEvent& e) { switch (e.state) { case WL_POINTER_BUTTON_STATE_PRESSED: { - const auto PWINDOW = g_pCompositor->vectorToWindowUnified(getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + const auto PWINDOW = + g_pCompositor->vectorToWindowUnified(getMouseCoordsInternal(), Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); if (!PWINDOW) { Debug::log(ERR, "Cannot kill invalid window!"); @@ -851,7 +856,7 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e, SP pointer) { if (!m_lastFocusOnLS) { const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); - const auto PWINDOW = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + const auto PWINDOW = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING); if (PWINDOW) { if (PWINDOW->checkInputOnDecos(INPUT_TYPE_AXIS, MOUSECOORDS, e)) @@ -1624,7 +1629,7 @@ bool CInputManager::isLocked() { if (!isConstrained()) return false; - const auto SURF = CWLSurface::fromResource(Desktop::focusState()->surface()); + const auto SURF = Desktop::View::CWLSurface::fromResource(Desktop::focusState()->surface()); const auto CONSTRAINT = SURF ? SURF->constraint() : nullptr; return CONSTRAINT && CONSTRAINT->isLocked(); diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 9fbf68b45..c3d6ac2f5 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -7,6 +7,7 @@ #include "../../helpers/time/Timer.hpp" #include "InputMethodRelay.hpp" #include "../../helpers/signal/Signal.hpp" +#include "../../desktop/view/WLSurface.hpp" #include "../../devices/IPointer.hpp" #include "../../devices/ITouch.hpp" #include "../../devices/IKeyboard.hpp" @@ -15,7 +16,6 @@ #include "../SeatManager.hpp" class CPointerConstraint; -class CWindow; class CIdleInhibitor; class CVirtualKeyboardV1Resource; class CVirtualPointerV1Resource; @@ -281,10 +281,10 @@ class CInputManager { // cursor surface struct { - bool hidden = false; // null surface = hidden - SP wlSurface; - Vector2D vHotspot; - std::string name; // if not empty, means set by name. + bool hidden = false; // null surface = hidden + SP wlSurface; + Vector2D vHotspot; + std::string name; // if not empty, means set by name. } m_cursorSurfaceInfo; void restoreCursorIconToApp(); // no-op if restored @@ -303,7 +303,7 @@ class CInputManager { uint32_t m_lastMods = 0; friend class CKeybindManager; - friend class CWLSurface; + friend class Desktop::View::CWLSurface; friend class CWorkspaceSwipeGesture; }; diff --git a/src/managers/input/InputMethodPopup.cpp b/src/managers/input/InputMethodPopup.cpp index 3c4731b53..41a1ccad6 100644 --- a/src/managers/input/InputMethodPopup.cpp +++ b/src/managers/input/InputMethodPopup.cpp @@ -12,17 +12,17 @@ CInputPopup::CInputPopup(SP popup_) : m_popup(popup_) { m_listeners.map = popup_->m_events.map.listen([this] { onMap(); }); m_listeners.unmap = popup_->m_events.unmap.listen([this] { onUnmap(); }); m_listeners.destroy = popup_->m_events.destroy.listen([this] { onDestroy(); }); - m_surface = CWLSurface::create(); + m_surface = Desktop::View::CWLSurface::create(); m_surface->assign(popup_->surface()); } -SP CInputPopup::queryOwner() { +SP CInputPopup::queryOwner() { const auto FOCUSED = g_pInputManager->m_relay.getFocusedTextInput(); if (!FOCUSED) return nullptr; - return CWLSurface::fromResource(FOCUSED->focusedSurface()); + return Desktop::View::CWLSurface::fromResource(FOCUSED->focusedSurface()); } void CInputPopup::onDestroy() { diff --git a/src/managers/input/InputMethodPopup.hpp b/src/managers/input/InputMethodPopup.hpp index 20767963d..a7014973f 100644 --- a/src/managers/input/InputMethodPopup.hpp +++ b/src/managers/input/InputMethodPopup.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../desktop/WLSurface.hpp" +#include "../../desktop/view/WLSurface.hpp" #include "../../macros.hpp" #include "../../helpers/math/Math.hpp" #include "../../helpers/signal/Signal.hpp" @@ -22,17 +22,17 @@ class CInputPopup { void onCommit(); private: - SP queryOwner(); - void updateBox(); + SP queryOwner(); + void updateBox(); - void onDestroy(); - void onMap(); - void onUnmap(); + void onDestroy(); + void onMap(); + void onUnmap(); - WP m_popup; - SP m_surface; - CBox m_lastBoxLocal; - MONITORID m_lastMonitor = MONITOR_INVALID; + WP m_popup; + SP m_surface; + CBox m_lastBoxLocal; + MONITORID m_lastMonitor = MONITOR_INVALID; struct { CHyprSignalListener map; diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index 7a9c359ae..058d6ac11 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -1,5 +1,5 @@ #include "InputManager.hpp" -#include "../../desktop/Window.hpp" +#include "../../desktop/view/Window.hpp" #include "../../protocols/Tablet.hpp" #include "../../devices/Tablet.hpp" #include "../../managers/HookSystemManager.hpp" @@ -38,7 +38,7 @@ static void focusTool(SP tool, SP tablet, SP tab, SP tool, bool motion = false) { - const auto LASTHLSURFACE = CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); + const auto LASTHLSURFACE = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); if (!LASTHLSURFACE || !tool->m_active) { if (tool->getSurface()) @@ -63,6 +63,8 @@ static void refocusTablet(SP tab, SP tool, bool motion = f if (!motion) return; + const auto WINDOW = Desktop::View::CWindow::fromView(LASTHLSURFACE->view()); + if (LASTHLSURFACE->constraint() && tool->aq()->type != Aquamarine::ITabletTool::AQ_TABLET_TOOL_TYPE_MOUSE) { // cursor logic will completely break here as the cursor will be locked. // let's just "map" the desired position to the constraint area. @@ -70,13 +72,13 @@ static void refocusTablet(SP tab, SP tool, bool motion = f Vector2D local; // yes, this technically ignores any regions set by the app. Too bad! - if (LASTHLSURFACE->getWindow()) - local = tool->m_absolutePos * LASTHLSURFACE->getWindow()->m_realSize->goal(); + if (WINDOW) + local = tool->m_absolutePos * WINDOW->m_realSize->goal(); else local = tool->m_absolutePos * BOX->size(); - if (LASTHLSURFACE->getWindow() && LASTHLSURFACE->getWindow()->m_isX11) - local = local * LASTHLSURFACE->getWindow()->m_X11SurfaceScaledBy; + if (WINDOW && WINDOW->m_isX11) + local = local * WINDOW->m_X11SurfaceScaledBy; PROTO::tablet->motion(tool, local); return; @@ -84,8 +86,8 @@ static void refocusTablet(SP tab, SP tool, bool motion = f auto local = CURSORPOS - BOX->pos(); - if (LASTHLSURFACE->getWindow() && LASTHLSURFACE->getWindow()->m_isX11) - local = local * LASTHLSURFACE->getWindow()->m_X11SurfaceScaledBy; + if (WINDOW && WINDOW->m_isX11) + local = local * WINDOW->m_X11SurfaceScaledBy; PROTO::tablet->motion(tool, local); } diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index e008b50c4..196300a2d 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -2,7 +2,7 @@ #include "../SessionLockManager.hpp" #include "../../protocols/SessionLock.hpp" #include "../../Compositor.hpp" -#include "../../desktop/LayerSurface.hpp" +#include "../../desktop/view/LayerSurface.hpp" #include "../../desktop/state/FocusState.hpp" #include "../../config/ConfigValue.hpp" #include "../../helpers/Monitor.hpp" diff --git a/src/managers/input/trackpad/gestures/FloatGesture.cpp b/src/managers/input/trackpad/gestures/FloatGesture.cpp index ea3307504..b2f451f1a 100644 --- a/src/managers/input/trackpad/gestures/FloatGesture.cpp +++ b/src/managers/input/trackpad/gestures/FloatGesture.cpp @@ -3,7 +3,7 @@ #include "../../../../managers/LayoutManager.hpp" #include "../../../../render/Renderer.hpp" #include "../../../../desktop/state/FocusState.hpp" -#include "../../../../desktop/Window.hpp" +#include "../../../../desktop/view/Window.hpp" constexpr const float MAX_DISTANCE = 250.F; diff --git a/src/managers/input/trackpad/gestures/MoveGesture.cpp b/src/managers/input/trackpad/gestures/MoveGesture.cpp index e9338e8af..034d88fbd 100644 --- a/src/managers/input/trackpad/gestures/MoveGesture.cpp +++ b/src/managers/input/trackpad/gestures/MoveGesture.cpp @@ -1,7 +1,7 @@ #include "MoveGesture.hpp" #include "../../../../desktop/state/FocusState.hpp" -#include "../../../../desktop/Window.hpp" +#include "../../../../desktop/view/Window.hpp" #include "../../../../managers/LayoutManager.hpp" #include "../../../../render/Renderer.hpp" diff --git a/src/managers/input/trackpad/gestures/ResizeGesture.cpp b/src/managers/input/trackpad/gestures/ResizeGesture.cpp index 066ebe2a6..33f018cd5 100644 --- a/src/managers/input/trackpad/gestures/ResizeGesture.cpp +++ b/src/managers/input/trackpad/gestures/ResizeGesture.cpp @@ -1,7 +1,7 @@ #include "ResizeGesture.hpp" #include "../../../../desktop/state/FocusState.hpp" -#include "../../../../desktop/Window.hpp" +#include "../../../../desktop/view/Window.hpp" #include "../../../../managers/LayoutManager.hpp" #include "../../../../render/Renderer.hpp" diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index c88fe5869..47a695db7 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -68,10 +68,8 @@ struct SVersionInfo { #endif class IHyprLayout; -class CWindow; class IHyprWindowDecoration; struct SConfigValue; -class CWindow; /* These methods are for the plugin to implement diff --git a/src/protocols/AlphaModifier.cpp b/src/protocols/AlphaModifier.cpp index a9c09d979..167abe53d 100644 --- a/src/protocols/AlphaModifier.cpp +++ b/src/protocols/AlphaModifier.cpp @@ -1,5 +1,5 @@ #include "AlphaModifier.hpp" -#include "../desktop/WLSurface.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../render/Renderer.hpp" #include "alpha-modifier-v1.hpp" #include "core/Compositor.hpp" @@ -31,7 +31,7 @@ void CAlphaModifier::setResource(UP&& resource) { }); m_listeners.surfaceCommitted = m_surface->m_events.commit.listen([this] { - auto surface = CWLSurface::fromResource(m_surface.lock()); + auto surface = Desktop::View::CWLSurface::fromResource(m_surface.lock()); if (surface && surface->m_alphaModifier != m_alpha) { surface->m_alphaModifier = m_alpha; diff --git a/src/protocols/ForeignToplevel.hpp b/src/protocols/ForeignToplevel.hpp index 355117e79..f0188292a 100644 --- a/src/protocols/ForeignToplevel.hpp +++ b/src/protocols/ForeignToplevel.hpp @@ -3,7 +3,7 @@ #include #include #include "WaylandProtocol.hpp" -#include "desktop/DesktopTypes.hpp" +#include "../desktop/DesktopTypes.hpp" #include "ext-foreign-toplevel-list-v1.hpp" class CForeignToplevelHandle { diff --git a/src/protocols/ForeignToplevelWlr.cpp b/src/protocols/ForeignToplevelWlr.cpp index ebe8163a1..46cd5f1b2 100644 --- a/src/protocols/ForeignToplevelWlr.cpp +++ b/src/protocols/ForeignToplevelWlr.cpp @@ -35,7 +35,7 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPm_suppressedEvents & SUPPRESS_FULLSCREEN) + if UNLIKELY (PWINDOW->m_suppressedEvents & Desktop::View::SUPPRESS_FULLSCREEN) return; if UNLIKELY (!PWINDOW->m_isMapped) { @@ -66,7 +66,7 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPm_suppressedEvents & SUPPRESS_FULLSCREEN) + if UNLIKELY (PWINDOW->m_suppressedEvents & Desktop::View::SUPPRESS_FULLSCREEN) return; g_pCompositor->changeWindowFullscreenModeClient(PWINDOW, FSMODE_FULLSCREEN, false); @@ -78,7 +78,7 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPm_suppressedEvents & SUPPRESS_MAXIMIZE) + if UNLIKELY (PWINDOW->m_suppressedEvents & Desktop::View::SUPPRESS_MAXIMIZE) return; if UNLIKELY (!PWINDOW->m_isMapped) { @@ -95,7 +95,7 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPm_suppressedEvents & SUPPRESS_MAXIMIZE) + if UNLIKELY (PWINDOW->m_suppressedEvents & Desktop::View::SUPPRESS_MAXIMIZE) return; g_pCompositor->changeWindowFullscreenModeClient(PWINDOW, FSMODE_MAXIMIZED, false); diff --git a/src/protocols/ForeignToplevelWlr.hpp b/src/protocols/ForeignToplevelWlr.hpp index abfadf599..444cbe0de 100644 --- a/src/protocols/ForeignToplevelWlr.hpp +++ b/src/protocols/ForeignToplevelWlr.hpp @@ -4,7 +4,6 @@ #include "WaylandProtocol.hpp" #include "wlr-foreign-toplevel-management-unstable-v1.hpp" -class CWindow; class CMonitor; class CForeignToplevelHandleWlr { diff --git a/src/protocols/HyprlandSurface.cpp b/src/protocols/HyprlandSurface.cpp index b2692d1f6..38b9c9f85 100644 --- a/src/protocols/HyprlandSurface.cpp +++ b/src/protocols/HyprlandSurface.cpp @@ -1,5 +1,5 @@ #include "HyprlandSurface.hpp" -#include "../desktop/WLSurface.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../render/Renderer.hpp" #include "core/Compositor.hpp" #include "hyprland-surface-v1.hpp" @@ -52,7 +52,7 @@ void CHyprlandSurface::setResource(SP resource) { }); m_listeners.surfaceCommitted = m_surface->m_events.commit.listen([this] { - auto surface = CWLSurface::fromResource(m_surface.lock()); + auto surface = Desktop::View::CWLSurface::fromResource(m_surface.lock()); if (surface && (surface->m_overallOpacity != m_opacity || m_visibleRegionChanged)) { surface->m_overallOpacity = m_opacity; diff --git a/src/protocols/InputMethodV2.hpp b/src/protocols/InputMethodV2.hpp index 4ee579ec1..b948d6099 100644 --- a/src/protocols/InputMethodV2.hpp +++ b/src/protocols/InputMethodV2.hpp @@ -6,7 +6,7 @@ #include "input-method-unstable-v2.hpp" #include "text-input-unstable-v3.hpp" #include "../helpers/signal/Signal.hpp" -#include "../desktop/WLSurface.hpp" +#include "../desktop/view/WLSurface.hpp" class CInputMethodKeyboardGrabV2; class CInputMethodPopupV2; diff --git a/src/protocols/LayerShell.cpp b/src/protocols/LayerShell.cpp index 2ed4bfb1c..32e915985 100644 --- a/src/protocols/LayerShell.cpp +++ b/src/protocols/LayerShell.cpp @@ -1,6 +1,6 @@ #include "LayerShell.hpp" #include "../Compositor.hpp" -#include "../desktop/LayerSurface.hpp" +#include "../desktop/view/LayerSurface.hpp" #include "XDGShell.hpp" #include "core/Compositor.hpp" #include "core/Output.hpp" @@ -247,7 +247,7 @@ void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id } SURF->m_role = makeShared(RESOURCE); - g_pCompositor->m_layers.emplace_back(CLayerSurface::create(RESOURCE)); + g_pCompositor->m_layers.emplace_back(Desktop::View::CLayerSurface::create(RESOURCE)); LOGM(LOG, "New wlr_layer_surface {:x}", (uintptr_t)RESOURCE.get()); } diff --git a/src/protocols/LinuxDMABUF.cpp b/src/protocols/LinuxDMABUF.cpp index 4e90d870c..a95a7a529 100644 --- a/src/protocols/LinuxDMABUF.cpp +++ b/src/protocols/LinuxDMABUF.cpp @@ -509,12 +509,12 @@ void CLinuxDMABufV1Protocol::resetFormatTable() { feedback->m_resource->sendFormatTable(newFormatTable->m_tableFD.get(), newFormatTable->m_tableSize); if (feedback->m_lastFeedbackWasScanout) { PHLMONITOR mon; - auto HLSurface = CWLSurface::fromResource(feedback->m_surface); + auto HLSurface = Desktop::View::CWLSurface::fromResource(feedback->m_surface); if (!HLSurface) { feedback->sendDefaultFeedback(); continue; } - if (auto w = HLSurface->getWindow(); w) + if (auto w = Desktop::View::CWindow::fromView(HLSurface->view()); w) if (auto m = w->m_monitor.lock(); m) mon = m->m_self.lock(); diff --git a/src/protocols/PointerConstraints.cpp b/src/protocols/PointerConstraints.cpp index 5ecaa43bc..1277ba124 100644 --- a/src/protocols/PointerConstraints.cpp +++ b/src/protocols/PointerConstraints.cpp @@ -1,7 +1,7 @@ #include "PointerConstraints.hpp" -#include "../desktop/WLSurface.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../desktop/state/FocusState.hpp" -#include "../desktop/Window.hpp" +#include "../desktop/view/Window.hpp" #include "../config/ConfigValue.hpp" #include "../managers/SeatManager.hpp" #include "core/Compositor.hpp" @@ -17,7 +17,7 @@ CPointerConstraint::CPointerConstraint(SP resource_, SPsetOnDestroy([this](CZwpLockedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); }); resource_->setDestroy([this](CZwpLockedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); }); - m_hlSurface = CWLSurface::fromResource(surf); + m_hlSurface = Desktop::View::CWLSurface::fromResource(surf); if (!m_hlSurface) return; @@ -35,7 +35,7 @@ CPointerConstraint::CPointerConstraint(SP resource_, SPgetWindow(); + const auto PWINDOW = Desktop::View::CWindow::fromView(m_hlSurface->view()); if (PWINDOW) { const auto ISXWL = PWINDOW->m_isX11; scale = ISXWL && *PXWLFORCESCALEZERO ? PWINDOW->m_X11SurfaceScaledBy : 1.f; @@ -56,7 +56,7 @@ CPointerConstraint::CPointerConstraint(SP resource_, SPsetOnDestroy([this](CZwpConfinedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); }); resource_->setDestroy([this](CZwpConfinedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); }); - m_hlSurface = CWLSurface::fromResource(surf); + m_hlSurface = Desktop::View::CWLSurface::fromResource(surf); if (!m_hlSurface) return; @@ -159,7 +159,7 @@ void CPointerConstraint::onSetRegion(wl_resource* wlRegion) { g_pInputManager->simulateMouseMovement(); // to warp the cursor if anything's amiss } -SP CPointerConstraint::owner() { +SP CPointerConstraint::owner() { return m_hlSurface.lock(); } diff --git a/src/protocols/PointerConstraints.hpp b/src/protocols/PointerConstraints.hpp index 1691b7c02..b190c0419 100644 --- a/src/protocols/PointerConstraints.hpp +++ b/src/protocols/PointerConstraints.hpp @@ -6,10 +6,10 @@ #include #include "WaylandProtocol.hpp" #include "pointer-constraints-unstable-v1.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../helpers/math/Math.hpp" #include "../helpers/signal/Signal.hpp" -class CWLSurface; class CWLSurfaceResource; class CPointerConstraint { @@ -18,23 +18,23 @@ class CPointerConstraint { CPointerConstraint(SP resource_, SP surf, wl_resource* region, zwpPointerConstraintsV1Lifetime lifetime_); ~CPointerConstraint(); - bool good(); + bool good(); - void deactivate(); - void activate(); - bool isActive(); + void deactivate(); + void activate(); + bool isActive(); - SP owner(); + SP owner(); - CRegion logicConstraintRegion(); - bool isLocked(); - Vector2D logicPositionHint(); + CRegion logicConstraintRegion(); + bool isLocked(); + Vector2D logicPositionHint(); private: SP m_resourceLocked; SP m_resourceConfined; - WP m_hlSurface; + WP m_hlSurface; CRegion m_region; bool m_hintSet = false; diff --git a/src/protocols/PointerWarp.cpp b/src/protocols/PointerWarp.cpp index bde0b9132..83be492e4 100644 --- a/src/protocols/PointerWarp.cpp +++ b/src/protocols/PointerWarp.cpp @@ -1,10 +1,10 @@ #include "PointerWarp.hpp" #include "core/Compositor.hpp" #include "core/Seat.hpp" -#include "../desktop/WLSurface.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../managers/SeatManager.hpp" #include "../managers/PointerManager.hpp" -#include "../desktop/Window.hpp" +#include "../desktop/view/Window.hpp" CPointerWarpProtocol::CPointerWarpProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { ; @@ -27,11 +27,11 @@ void CPointerWarpProtocol::bindManager(wl_client* client, void* data, uint32_t v if (g_pSeatManager->m_state.pointerFocus != PSURFACE) return; - auto SURFBOXV = CWLSurface::fromResource(PSURFACE)->getSurfaceBoxGlobal(); - if (!SURFBOXV.has_value()) + auto WINDOW = Desktop::View::CWindow::fromView(Desktop::View::CWLSurface::fromResource(PSURFACE)->view()); + if (!WINDOW) return; - const auto SURFBOX = SURFBOXV->expand(1); + const auto SURFBOX = WINDOW->getWindowMainSurfaceBox().expand(1); const auto LOCALPOS = Vector2D{wl_fixed_to_double(x), wl_fixed_to_double(y)}; const auto GLOBALPOS = LOCALPOS + SURFBOX.pos(); if (!SURFBOX.containsPoint(GLOBALPOS)) diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp index 84487a187..36b112987 100644 --- a/src/protocols/Screencopy.cpp +++ b/src/protocols/Screencopy.cpp @@ -212,12 +212,12 @@ void CScreencopyFrame::renderMon() { g_pHyprOpenGL->popMonitorTransformEnabled(); auto hidePopups = [&](Vector2D popupBaseOffset) { - return [&, popupBaseOffset](WP popup, void*) { - if (!popup->m_wlSurface || !popup->m_wlSurface->resource() || !popup->m_mapped) + return [&, popupBaseOffset](WP popup, void*) { + if (!popup->wlSurface() || !popup->wlSurface()->resource() || !popup->visible()) return; const auto popRel = popup->coordsRelativeToParent(); - popup->m_wlSurface->resource()->breadthfirst( + popup->wlSurface()->resource()->breadthfirst( [&](SP surf, const Vector2D& localOff, void*) { const auto size = surf->m_current.size; const auto surfBox = CBox{popupBaseOffset + popRel + localOff, size}.translate(m_monitor->m_position).scale(m_monitor->m_scale).translate(-m_box.pos()); @@ -233,7 +233,7 @@ void CScreencopyFrame::renderMon() { if (!l->m_ruleApplicator->noScreenShare().valueOrDefault()) continue; - if UNLIKELY ((!l->m_mapped && !l->m_fadingOut) || l->m_alpha->value() == 0.f) + if UNLIKELY (!l->visible()) continue; const auto REALPOS = l->m_realPosition->value(); diff --git a/src/protocols/SinglePixel.cpp b/src/protocols/SinglePixel.cpp index 6ca48a356..e291711d4 100644 --- a/src/protocols/SinglePixel.cpp +++ b/src/protocols/SinglePixel.cpp @@ -1,5 +1,5 @@ #include "SinglePixel.hpp" -#include "../desktop/LayerSurface.hpp" +#include "../desktop/view/LayerSurface.hpp" #include #include "render/Renderer.hpp" diff --git a/src/protocols/TearingControl.cpp b/src/protocols/TearingControl.cpp index ee65cc9e3..685c84a76 100644 --- a/src/protocols/TearingControl.cpp +++ b/src/protocols/TearingControl.cpp @@ -1,6 +1,6 @@ #include "TearingControl.hpp" #include "../managers/ProtocolManager.hpp" -#include "../desktop/Window.hpp" +#include "../desktop/view/Window.hpp" #include "../Compositor.hpp" #include "core/Compositor.hpp" #include "../managers/HookSystemManager.hpp" @@ -54,7 +54,7 @@ CTearingControl::CTearingControl(SP resource_, SPsetSetPresentationHint([this](CWpTearingControlV1* res, wpTearingControlV1PresentationHint hint) { this->onHint(hint); }); for (auto const& w : g_pCompositor->m_windows) { - if (w->m_wlSurface->resource() == surf_) { + if (w->wlSurface()->resource() == surf_) { m_window = w; break; } diff --git a/src/protocols/TearingControl.hpp b/src/protocols/TearingControl.hpp index b58ec8e3b..ec31b6f65 100644 --- a/src/protocols/TearingControl.hpp +++ b/src/protocols/TearingControl.hpp @@ -3,7 +3,6 @@ #include "WaylandProtocol.hpp" #include "tearing-control-v1.hpp" -class CWindow; class CTearingControlProtocol; class CWLSurfaceResource; diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp index c66c1f2b7..9d9d16bef 100644 --- a/src/protocols/ToplevelExport.cpp +++ b/src/protocols/ToplevelExport.cpp @@ -372,9 +372,9 @@ bool CToplevelExportFrame::shouldOverlayCursor() const { if (!pointerSurfaceResource) return false; - auto pointerSurface = CWLSurface::fromResource(pointerSurfaceResource); + auto pointerSurface = Desktop::View::CWLSurface::fromResource(pointerSurfaceResource); - return pointerSurface && pointerSurface->getWindow() == m_window; + return pointerSurface && Desktop::View::CWindow::fromView(pointerSurface->view()) == m_window; } bool CToplevelExportFrame::good() { @@ -382,7 +382,11 @@ bool CToplevelExportFrame::good() { } CToplevelExportProtocol::CToplevelExportProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { - ; + static auto P1 = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any data) { + auto window = std::any_cast(data); + + onWindowUnmap(window); + }); } void CToplevelExportProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { diff --git a/src/protocols/ToplevelExport.hpp b/src/protocols/ToplevelExport.hpp index 8ccd881bf..44704d844 100644 --- a/src/protocols/ToplevelExport.hpp +++ b/src/protocols/ToplevelExport.hpp @@ -9,7 +9,6 @@ #include class CMonitor; -class CWindow; class CToplevelExportClient { public: @@ -78,7 +77,6 @@ class CToplevelExportProtocol : IWaylandProtocol { void destroyResource(CToplevelExportClient* client); void destroyResource(CToplevelExportFrame* frame); - void onWindowUnmap(PHLWINDOW pWindow); void onOutputCommit(PHLMONITOR pMonitor); private: @@ -86,6 +84,8 @@ class CToplevelExportProtocol : IWaylandProtocol { std::vector> m_frames; std::vector> m_framesAwaitingWrite; + void onWindowUnmap(PHLWINDOW pWindow); + void shareFrame(CToplevelExportFrame* frame); bool copyFrameDmabuf(CToplevelExportFrame* frame, const Time::steady_tp& now); bool copyFrameShm(CToplevelExportFrame* frame, const Time::steady_tp& now); diff --git a/src/protocols/XDGBell.cpp b/src/protocols/XDGBell.cpp index 884564735..b53621d51 100644 --- a/src/protocols/XDGBell.cpp +++ b/src/protocols/XDGBell.cpp @@ -1,6 +1,6 @@ #include "XDGBell.hpp" #include "core/Compositor.hpp" -#include "../desktop/Window.hpp" +#include "../desktop/view/Window.hpp" #include "../managers/EventManager.hpp" #include "../Compositor.hpp" @@ -31,10 +31,10 @@ CXDGSystemBellManagerResource::CXDGSystemBellManagerResource(UPm_windows) { - if (!w->m_isMapped || w->m_isX11 || !w->m_xdgSurface || !w->m_wlSurface) + if (!w->m_isMapped || w->m_isX11 || !w->m_xdgSurface || !w->wlSurface()) continue; - if (w->m_wlSurface->resource() == SURFACE) { + if (w->wlSurface()->resource() == SURFACE) { g_pEventManager->postEvent(SHyprIPCEvent{ .event = "bell", .data = std::format("{:x}", rc(w.get())), diff --git a/src/protocols/XDGDialog.cpp b/src/protocols/XDGDialog.cpp index c64a8379c..ad6b3eeb8 100644 --- a/src/protocols/XDGDialog.cpp +++ b/src/protocols/XDGDialog.cpp @@ -1,6 +1,6 @@ #include "XDGDialog.hpp" #include "XDGShell.hpp" -#include "../desktop/WLSurface.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../Compositor.hpp" #include @@ -26,11 +26,16 @@ void CXDGDialogV1Resource::updateWindow() { if UNLIKELY (!m_toplevel || !m_toplevel->m_parent || !m_toplevel->m_parent->m_owner) return; - auto HLSurface = CWLSurface::fromResource(m_toplevel->m_parent->m_owner->m_surface.lock()); - if UNLIKELY (!HLSurface || !HLSurface->getWindow()) + const auto HLSURFACE = Desktop::View::CWLSurface::fromResource(m_toplevel->m_parent->m_owner->m_surface.lock()); + if UNLIKELY (!HLSURFACE) return; - HLSurface->getWindow()->m_ruleApplicator->propertiesChanged(Desktop::Rule::RULE_PROP_MODAL); + const auto WINDOW = Desktop::View::CWindow::fromView(HLSURFACE->view()); + + if UNLIKELY (!WINDOW) + return; + + WINDOW->m_ruleApplicator->propertiesChanged(Desktop::Rule::RULE_PROP_MODAL); } bool CXDGDialogV1Resource::good() { diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index 58f297b99..cbac46b57 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -460,7 +460,7 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP resource_, SPm_windows.emplace_back(CWindow::create(m_self.lock())); + g_pCompositor->m_windows.emplace_back(Desktop::View::CWindow::create(m_self.lock())); for (auto const& p : m_popups) { if (!p) diff --git a/src/protocols/XDGTag.cpp b/src/protocols/XDGTag.cpp index 98c8651f3..84415d718 100644 --- a/src/protocols/XDGTag.cpp +++ b/src/protocols/XDGTag.cpp @@ -1,6 +1,6 @@ #include "XDGTag.hpp" #include "XDGShell.hpp" -#include "../desktop/Window.hpp" +#include "../desktop/view/Window.hpp" CXDGToplevelTagManagerResource::CXDGToplevelTagManagerResource(UP&& resource) : m_resource(std::move(resource)) { if UNLIKELY (!good()) diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp index efdbff50d..44f959430 100644 --- a/src/protocols/core/Compositor.cpp +++ b/src/protocols/core/Compositor.cpp @@ -356,7 +356,7 @@ void CWLSurfaceResource::bfHelper(std::vector> const& nod break; if (c->m_surface.expired()) continue; - nodes2.push_back(c->m_surface.lock()); + nodes2.emplace_back(c->m_surface.lock()); } } @@ -381,7 +381,7 @@ void CWLSurfaceResource::bfHelper(std::vector> const& nod continue; if (c->m_surface.expired()) continue; - nodes2.push_back(c->m_surface.lock()); + nodes2.emplace_back(c->m_surface.lock()); } } @@ -391,7 +391,7 @@ void CWLSurfaceResource::bfHelper(std::vector> const& nod void CWLSurfaceResource::breadthfirst(std::function, const Vector2D&, void*)> fn, void* data) { std::vector> surfs; - surfs.push_back(m_self.lock()); + surfs.emplace_back(m_self.lock()); bfHelper(surfs, fn, data); } @@ -558,7 +558,9 @@ void CWLSurfaceResource::commitState(SSurfaceState& state) { SImageDescription CWLSurfaceResource::getPreferredImageDescription() { static const auto PFORCE_HDR = CConfigValue("quirks:prefer_hdr"); - if (*PFORCE_HDR == 1 || (*PFORCE_HDR == 2 && m_hlSurface && m_hlSurface->getWindow() && m_hlSurface->getWindow()->m_class == "gamescope")) + const auto WINDOW = Desktop::View::CWindow::fromView(m_hlSurface->view()); + + if (*PFORCE_HDR == 1 || (*PFORCE_HDR == 2 && m_hlSurface && WINDOW && WINDOW->m_class == "gamescope")) return g_pCompositor->getHDRImageDescription(); auto parent = m_self; @@ -569,8 +571,8 @@ SImageDescription CWLSurfaceResource::getPreferredImageDescription() { WP monitor; if (parent->m_enteredOutputs.size() == 1) monitor = parent->m_enteredOutputs[0]; - else if (m_hlSurface.valid() && m_hlSurface->getWindow()) - monitor = m_hlSurface->getWindow()->m_monitor; + else if (m_hlSurface.valid() && WINDOW) + monitor = WINDOW->m_monitor; return monitor ? monitor->m_imageDescription : g_pCompositor->getPreferredImageDescription(); } diff --git a/src/protocols/core/Compositor.hpp b/src/protocols/core/Compositor.hpp index 0dc03cf47..7b295aa71 100644 --- a/src/protocols/core/Compositor.hpp +++ b/src/protocols/core/Compositor.hpp @@ -15,6 +15,7 @@ #include "../../render/Texture.hpp" #include "../types/SurfaceStateQueue.hpp" #include "wayland.hpp" +#include "../../desktop/view/WLSurface.hpp" #include "../../helpers/signal/Signal.hpp" #include "../../helpers/math/Math.hpp" #include "../../helpers/time/Time.hpp" @@ -25,7 +26,6 @@ class CWLOutputResource; class CMonitor; -class CWLSurface; class CWLSurfaceResource; class CWLSubsurfaceResource; class CViewportResource; @@ -109,7 +109,7 @@ class CWLSurfaceResource { CSurfaceStateQueue m_stateQueue; WP m_self; - WP m_hlSurface; + WP m_hlSurface; std::vector m_enteredOutputs; bool m_mapped = false; std::vector> m_subsurfaces; diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp index b3239cf1a..a42933ed8 100644 --- a/src/protocols/core/DataDevice.cpp +++ b/src/protocols/core/DataDevice.cpp @@ -603,7 +603,7 @@ void CWLDataDeviceProtocol::initiateDrag(WP currentSource m_dnd.mouseMove = g_pHookSystem->hookDynamic("mouseMove", [this](void* self, SCallbackInfo& info, std::any e) { auto V = std::any_cast(e); if (m_dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) { - auto surf = CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock()); + auto surf = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock()); if (!surf) return; @@ -621,7 +621,7 @@ void CWLDataDeviceProtocol::initiateDrag(WP currentSource m_dnd.touchMove = g_pHookSystem->hookDynamic("touchMove", [this](void* self, SCallbackInfo& info, std::any e) { auto E = std::any_cast(e); if (m_dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) { - auto surf = CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock()); + auto surf = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock()); if (!surf) return; diff --git a/src/protocols/core/Output.cpp b/src/protocols/core/Output.cpp index d0f057e3d..61c4acf86 100644 --- a/src/protocols/core/Output.cpp +++ b/src/protocols/core/Output.cpp @@ -31,7 +31,7 @@ CWLOutputResource::CWLOutputResource(SP resource_, PHLMONITOR pMonito updateState(); PROTO::compositor->forEachSurface([](SP surf) { - auto HLSurf = CWLSurface::fromResource(surf); + auto HLSurf = Desktop::View::CWLSurface::fromResource(surf); if (!HLSurf) return; diff --git a/src/protocols/types/DMABuffer.cpp b/src/protocols/types/DMABuffer.cpp index f04665abe..7116aa400 100644 --- a/src/protocols/types/DMABuffer.cpp +++ b/src/protocols/types/DMABuffer.cpp @@ -1,6 +1,6 @@ #include "DMABuffer.hpp" #include "WLBuffer.hpp" -#include "../../desktop/LayerSurface.hpp" +#include "../../desktop/view/LayerSurface.hpp" #include "../../render/Renderer.hpp" #include "../../helpers/Format.hpp" diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 2f1bccb2b..ae01d2a11 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -13,7 +13,7 @@ #include "../config/ConfigValue.hpp" #include "../config/ConfigManager.hpp" #include "../managers/PointerManager.hpp" -#include "../desktop/LayerSurface.hpp" +#include "../desktop/view/LayerSurface.hpp" #include "../desktop/state/FocusState.hpp" #include "../protocols/LayerShell.hpp" #include "../protocols/core/Compositor.hpp" @@ -2211,10 +2211,10 @@ void CHyprOpenGLImpl::preRender(PHLMONITOR pMonitor) { if (pWindow->m_ruleApplicator->noBlur().valueOrDefault()) return false; - if (pWindow->m_wlSurface->small() && !pWindow->m_wlSurface->m_fillIgnoreSmall) + if (pWindow->wlSurface()->small() && !pWindow->wlSurface()->m_fillIgnoreSmall) return true; - const auto PSURFACE = pWindow->m_wlSurface->resource(); + const auto PSURFACE = pWindow->wlSurface()->resource(); const auto PWORKSPACE = pWindow->m_workspace; const float A = pWindow->m_alpha->value() * pWindow->m_activeInactiveAlpha->value() * PWORKSPACE->m_alpha->value(); diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 45ed28dd4..8d0c48aa1 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -269,38 +269,38 @@ class CHyprOpenGLImpl { void setDamage(const CRegion& damage, std::optional finalDamage = {}); uint32_t getPreferredReadFormat(PHLMONITOR pMonitor); - std::vector getDRMFormats(); - EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs); + std::vector getDRMFormats(); + EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs); - bool initShaders(); + bool initShaders(); - GLuint createProgram(const std::string&, const std::string&, bool dynamic = false, bool silent = false); - GLuint compileShader(const GLuint&, std::string, bool dynamic = false, bool silent = false); - void useProgram(GLuint prog); + GLuint createProgram(const std::string&, const std::string&, bool dynamic = false, bool silent = false); + GLuint compileShader(const GLuint&, std::string, bool dynamic = false, bool silent = false); + void useProgram(GLuint prog); - void ensureLockTexturesRendered(bool load); + void ensureLockTexturesRendered(bool load); - bool explicitSyncSupported(); + bool explicitSyncSupported(); - bool m_shadersInitialized = false; - SP m_shaders; + bool m_shadersInitialized = false; + SP m_shaders; - SCurrentRenderData m_renderData; + SCurrentRenderData m_renderData; - Hyprutils::OS::CFileDescriptor m_gbmFD; - gbm_device* m_gbmDevice = nullptr; - EGLContext m_eglContext = nullptr; - EGLDisplay m_eglDisplay = nullptr; - EGLDeviceEXT m_eglDevice = nullptr; - uint m_failedAssetsNo = 0; + Hyprutils::OS::CFileDescriptor m_gbmFD; + gbm_device* m_gbmDevice = nullptr; + EGLContext m_eglContext = nullptr; + EGLDisplay m_eglDisplay = nullptr; + EGLDeviceEXT m_eglDevice = nullptr; + uint m_failedAssetsNo = 0; - bool m_reloadScreenShader = true; // at launch it can be set + bool m_reloadScreenShader = true; // at launch it can be set - std::map m_windowFramebuffers; - std::map m_layerFramebuffers; - std::map, CFramebuffer> m_popupFramebuffers; - std::map m_monitorRenderResources; - std::map m_monitorBGFBs; + std::map m_windowFramebuffers; + std::map m_layerFramebuffers; + std::map, CFramebuffer> m_popupFramebuffers; + std::map m_monitorRenderResources; + std::map m_monitorBGFBs; struct { PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES = nullptr; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 2c8130004..38cd951d9 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -12,8 +12,9 @@ #include "../managers/HookSystemManager.hpp" #include "../managers/animation/AnimationManager.hpp" #include "../managers/LayoutManager.hpp" -#include "../desktop/Window.hpp" -#include "../desktop/LayerSurface.hpp" +#include "../desktop/view/Window.hpp" +#include "../desktop/view/LayerSurface.hpp" +#include "../desktop/view/GlobalViewMethods.hpp" #include "../desktop/state/FocusState.hpp" #include "../protocols/SessionLock.hpp" #include "../protocols/LayerShell.hpp" @@ -164,11 +165,11 @@ CHyprRenderer::CHyprRenderer() { continue; } - if (!w->m_wlSurface || !w->m_wlSurface->resource() || shouldRenderWindow(w.lock())) + if (!w->wlSurface() || !w->wlSurface()->resource() || shouldRenderWindow(w.lock())) continue; - w->m_wlSurface->resource()->frame(Time::steadyNow()); - auto FEEDBACK = makeUnique(w->m_wlSurface->resource()); + w->wlSurface()->resource()->frame(Time::steadyNow()); + auto FEEDBACK = makeUnique(w->wlSurface()->resource()); FEEDBACK->attachMonitor(Desktop::focusState()->monitor()); FEEDBACK->discarded(); PROTO::presentation->queueData(std::move(FEEDBACK)); @@ -516,7 +517,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T // whether to use m_fMovingToWorkspaceAlpha, only if fading out into an invisible ws const bool USE_WORKSPACE_FADE_ALPHA = pWindow->m_monitorMovedFrom != -1 && (!PWORKSPACE || !PWORKSPACE->isVisible()); - renderdata.surface = pWindow->m_wlSurface->resource(); + renderdata.surface = pWindow->wlSurface()->resource(); renderdata.dontRound = pWindow->isEffectiveInternalFSMode(FSMODE_FULLSCREEN); renderdata.fadeAlpha = pWindow->m_alpha->value() * (pWindow->m_pinned || USE_WORKSPACE_FADE_ALPHA ? 1.f : PWORKSPACE->m_alpha->value()) * (USE_WORKSPACE_FADE_ALPHA ? pWindow->m_movingToWorkspaceAlpha->value() : 1.F) * pWindow->m_movingFromWorkspaceAlpha->value(); @@ -596,7 +597,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T if ((pWindow->m_isX11 && *PXWLUSENN) || pWindow->m_ruleApplicator->nearestNeighbor().valueOrDefault()) renderdata.useNearestNeighbor = true; - if (pWindow->m_wlSurface->small() && !pWindow->m_wlSurface->m_fillIgnoreSmall && renderdata.blur) { + if (pWindow->wlSurface()->small() && !pWindow->wlSurface()->m_fillIgnoreSmall && renderdata.blur) { CBox wb = {renderdata.pos.x - pMonitor->m_position.x, renderdata.pos.y - pMonitor->m_position.y, renderdata.w, renderdata.h}; wb.scale(pMonitor->m_scale).round(); CRectPassElement::SRectData data; @@ -611,7 +612,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T } renderdata.surfaceCounter = 0; - pWindow->m_wlSurface->resource()->breadthfirst( + pWindow->wlSurface()->resource()->breadthfirst( [this, &renderdata, &pWindow](SP s, const Vector2D& offset, void* data) { if (!s->m_current.texture) return; @@ -622,7 +623,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T renderdata.localPos = offset; renderdata.texture = s->m_current.texture; renderdata.surface = s; - renderdata.mainSurface = s == pWindow->m_wlSurface->resource(); + renderdata.mainSurface = s == pWindow->wlSurface()->resource(); m_renderPass.add(makeUnique(renderdata)); renderdata.surfaceCounter++; }, @@ -677,20 +678,20 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T renderdata.surfaceCounter = 0; pWindow->m_popupHead->breadthfirst( - [this, &renderdata](WP popup, void* data) { + [this, &renderdata](WP popup, void* data) { if (popup->m_fadingOut) { renderSnapshot(popup); return; } - if (!popup->m_wlSurface || !popup->m_wlSurface->resource() || !popup->m_mapped) + if (!popup->visible()) return; const auto pos = popup->coordsRelativeToParent(); const Vector2D oldPos = renderdata.pos; renderdata.pos += pos; renderdata.fadeAlpha = popup->m_alpha->value(); - popup->m_wlSurface->resource()->breadthfirst( + popup->wlSurface()->resource()->breadthfirst( [this, &renderdata](SP s, const Vector2D& offset, void* data) { if (!s->m_current.texture) return; @@ -761,7 +762,7 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, const Time::s CSurfacePassElement::SRenderData renderdata = {pMonitor, time, REALPOS}; renderdata.fadeAlpha = pLayer->m_alpha->value(); renderdata.blur = shouldBlur(pLayer); - renderdata.surface = pLayer->m_surface->resource(); + renderdata.surface = pLayer->wlSurface()->resource(); renderdata.decorate = false; renderdata.w = REALSIZ.x; renderdata.h = REALSIZ.y; @@ -776,7 +777,7 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, const Time::s } if (!popups) - pLayer->m_surface->resource()->breadthfirst( + pLayer->wlSurface()->resource()->breadthfirst( [this, &renderdata, &pLayer](SP s, const Vector2D& offset, void* data) { if (!s->m_current.texture) return; @@ -787,7 +788,7 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, const Time::s renderdata.localPos = offset; renderdata.texture = s->m_current.texture; renderdata.surface = s; - renderdata.mainSurface = s == pLayer->m_surface->resource(); + renderdata.mainSurface = s == pLayer->wlSurface()->resource(); m_renderPass.add(makeUnique(renderdata)); renderdata.surfaceCounter++; }, @@ -800,11 +801,11 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, const Time::s renderdata.surfaceCounter = 0; if (popups) { pLayer->m_popupHead->breadthfirst( - [this, &renderdata](WP popup, void* data) { - if (!popup->m_wlSurface || !popup->m_wlSurface->resource() || !popup->m_mapped) + [this, &renderdata](WP popup, void* data) { + if (!popup->visible()) return; - const auto SURF = popup->m_wlSurface->resource(); + const auto SURF = popup->wlSurface()->resource(); if (!SURF->m_current.texture) return; @@ -1138,7 +1139,7 @@ void CHyprRenderer::renderSessionLockMissing(PHLMONITOR pMonitor) { static std::optional getSurfaceExpectedSize(PHLWINDOW pWindow, SP pSurface, PHLMONITOR pMonitor, bool main) { const auto CAN_USE_WINDOW = pWindow && main; - const auto WINDOW_SIZE_MISALIGN = CAN_USE_WINDOW && pWindow->getReportedSize() != pWindow->m_wlSurface->resource()->m_current.size; + const auto WINDOW_SIZE_MISALIGN = CAN_USE_WINDOW && pWindow->getReportedSize() != pWindow->wlSurface()->resource()->m_current.size; if (pSurface->m_current.viewport.hasDestination) return (pSurface->m_current.viewport.destination * pMonitor->m_scale).round(); @@ -1577,7 +1578,7 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) { bool hdrIsHandled = false; if (FS_WINDOW) { - const auto ROOT_SURF = FS_WINDOW->m_wlSurface->resource(); + const auto ROOT_SURF = FS_WINDOW->wlSurface()->resource(); const auto SURF = ROOT_SURF->findWithCM(); // we have a surface with image description @@ -1706,23 +1707,11 @@ void CHyprRenderer::renderWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace } void CHyprRenderer::sendFrameEventsToWorkspace(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, const Time::steady_tp& now) { - for (auto const& w : g_pCompositor->m_windows) { - if (w->isHidden() || !w->m_isMapped || w->m_fadingOut || !w->m_wlSurface->resource()) + for (const auto& view : Desktop::View::getViewsForWorkspace(pWorkspace)) { + if (!view->visible()) continue; - if (!shouldRenderWindow(w, pMonitor)) - continue; - - w->m_wlSurface->resource()->breadthfirst([now](SP r, const Vector2D& offset, void* d) { r->frame(now); }, nullptr); - } - - for (auto const& lsl : pMonitor->m_layerSurfaceLayers) { - for (auto const& ls : lsl) { - if (ls->m_fadingOut || !ls->m_surface->resource()) - continue; - - ls->m_surface->resource()->breadthfirst([now](SP r, const Vector2D& offset, void* d) { r->frame(now); }, nullptr); - } + view->wlSurface()->resource()->frame(now); } } @@ -1918,7 +1907,7 @@ void CHyprRenderer::damageSurface(SP pSurface, double x, dou if (g_pCompositor->m_unsafeState) return; - const auto WLSURF = CWLSurface::fromResource(pSurface); + const auto WLSURF = Desktop::View::CWLSurface::fromResource(pSurface); CRegion damageBox = WLSURF ? WLSURF->computeDamage() : CRegion{}; if (!WLSURF) { Debug::log(ERR, "BUG THIS: No CWLSurface for surface in damageSurface!!!"); @@ -2052,7 +2041,7 @@ void CHyprRenderer::renderDragIcon(PHLMONITOR pMonitor, const Time::steady_tp& t PROTO::data->renderDND(pMonitor, time); } -void CHyprRenderer::setCursorSurface(SP surf, int hotspotX, int hotspotY, bool force) { +void CHyprRenderer::setCursorSurface(SP surf, int hotspotX, int hotspotY, bool force) { m_cursorHasSurface = surf; m_lastCursorData.name = ""; @@ -2509,14 +2498,14 @@ void CHyprRenderer::makeSnapshot(PHLLS pLayer) { m_bRenderingSnapshot = false; } -void CHyprRenderer::makeSnapshot(WP popup) { +void CHyprRenderer::makeSnapshot(WP popup) { // we trust the window is valid. const auto PMONITOR = popup->getMonitor(); if (!PMONITOR || !PMONITOR->m_output || PMONITOR->m_pixelSize.x <= 0 || PMONITOR->m_pixelSize.y <= 0) return; - if (!popup->m_wlSurface || !popup->m_wlSurface->resource() || !popup->m_mapped) + if (!popup->visible()) return; Debug::log(LOG, "renderer: making a snapshot of {:x}", rc(popup.get())); @@ -2544,7 +2533,7 @@ void CHyprRenderer::makeSnapshot(WP popup) { renderdata.popup = true; renderdata.blur = false; - popup->m_wlSurface->resource()->breadthfirst( + popup->wlSurface()->resource()->breadthfirst( [this, &renderdata](SP s, const Vector2D& offset, void* data) { if (!s->m_current.texture) return; @@ -2668,7 +2657,7 @@ void CHyprRenderer::renderSnapshot(PHLLS pLayer) { m_renderPass.add(makeUnique(std::move(data))); } -void CHyprRenderer::renderSnapshot(WP popup) { +void CHyprRenderer::renderSnapshot(WP popup) { if (!g_pHyprOpenGL->m_popupFramebuffers.contains(popup)) return; @@ -2720,7 +2709,7 @@ bool CHyprRenderer::shouldBlur(PHLWINDOW w) { return *PBLUR && !DONT_BLUR; } -bool CHyprRenderer::shouldBlur(WP p) { +bool CHyprRenderer::shouldBlur(WP p) { static CConfigValue PBLURPOPUPS = CConfigValue("decoration:blur:popups"); static CConfigValue PBLUR = CConfigValue("decoration:blur:enabled"); diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 1980984d2..6e0c69fad 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -3,7 +3,7 @@ #include "../defines.hpp" #include #include "../helpers/Monitor.hpp" -#include "../desktop/LayerSurface.hpp" +#include "../desktop/view/LayerSurface.hpp" #include "OpenGL.hpp" #include "Renderbuffer.hpp" #include "../helpers/time/Timer.hpp" @@ -13,7 +13,6 @@ struct SMonitorRule; class CWorkspace; -class CWindow; class CInputPopup; class IHLBuffer; class CEventLoopTimer; @@ -70,7 +69,7 @@ class CHyprRenderer { bool fixMisalignedFSV1 = false); std::tuple getRenderTimes(PHLMONITOR pMonitor); // avg max min void renderLockscreen(PHLMONITOR pMonitor, const Time::steady_tp& now, const CBox& geometry); - void setCursorSurface(SP surf, int hotspotX, int hotspotY, bool force = false); + void setCursorSurface(SP surf, int hotspotX, int hotspotY, bool force = false); void setCursorFromName(const std::string& name, bool force = false); void onRenderbufferDestroy(CRenderbuffer* rb); SP getCurrentRBO(); @@ -83,10 +82,10 @@ class CHyprRenderer { void addWindowToRenderUnfocused(PHLWINDOW window); void makeSnapshot(PHLWINDOW); void makeSnapshot(PHLLS); - void makeSnapshot(WP); + void makeSnapshot(WP); void renderSnapshot(PHLWINDOW); void renderSnapshot(PHLLS); - void renderSnapshot(WP); + void renderSnapshot(WP); // if RENDER_MODE_NORMAL, provided damage will be written to. // otherwise, it will be the one used. @@ -109,13 +108,13 @@ class CHyprRenderer { std::vector m_usedAsyncBuffers; struct { - int hotspotX = 0; - int hotspotY = 0; - wpCursorShapeDeviceV1Shape shape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT; - wpCursorShapeDeviceV1Shape shapePrevious = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT; - CTimer switchedTimer; - std::optional> surf; - std::string name; + int hotspotX = 0; + int hotspotY = 0; + wpCursorShapeDeviceV1Shape shape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT; + wpCursorShapeDeviceV1Shape shapePrevious = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT; + CTimer switchedTimer; + std::optional> surf; + std::string name; } m_lastCursorData; CRenderPass m_renderPass = {}; @@ -140,7 +139,7 @@ class CHyprRenderer { bool shouldBlur(PHLLS ls); bool shouldBlur(PHLWINDOW w); - bool shouldBlur(WP p); + bool shouldBlur(WP p); bool m_cursorHidden = false; bool m_cursorHiddenByCondition = false; diff --git a/src/render/decorations/DecorationPositioner.cpp b/src/render/decorations/DecorationPositioner.cpp index 1082812f9..561d366d8 100644 --- a/src/render/decorations/DecorationPositioner.cpp +++ b/src/render/decorations/DecorationPositioner.cpp @@ -1,5 +1,5 @@ #include "DecorationPositioner.hpp" -#include "../../desktop/Window.hpp" +#include "../../desktop/view/Window.hpp" #include "../../managers/HookSystemManager.hpp" #include "../../managers/LayoutManager.hpp" diff --git a/src/render/decorations/DecorationPositioner.hpp b/src/render/decorations/DecorationPositioner.hpp index 8048c7ade..8fbb44c7f 100644 --- a/src/render/decorations/DecorationPositioner.hpp +++ b/src/render/decorations/DecorationPositioner.hpp @@ -6,7 +6,6 @@ #include "../../helpers/math/Math.hpp" #include "../../desktop/DesktopTypes.hpp" -class CWindow; class IHyprWindowDecoration; enum eDecorationPositioningPolicy : uint8_t { diff --git a/src/render/decorations/IHyprWindowDecoration.cpp b/src/render/decorations/IHyprWindowDecoration.cpp index 0dd118671..267820985 100644 --- a/src/render/decorations/IHyprWindowDecoration.cpp +++ b/src/render/decorations/IHyprWindowDecoration.cpp @@ -1,7 +1,5 @@ #include "IHyprWindowDecoration.hpp" -class CWindow; - IHyprWindowDecoration::IHyprWindowDecoration(PHLWINDOW pWindow) : m_window(pWindow) { ; } diff --git a/src/render/decorations/IHyprWindowDecoration.hpp b/src/render/decorations/IHyprWindowDecoration.hpp index 26bfcb455..9916d3922 100644 --- a/src/render/decorations/IHyprWindowDecoration.hpp +++ b/src/render/decorations/IHyprWindowDecoration.hpp @@ -26,7 +26,6 @@ enum eDecorationFlags : uint8_t { DECORATION_NON_SOLID = 1 << 2, /* this decoration is not solid. Other decorations should draw on top of it. Example: shadow */ }; -class CWindow; class CMonitor; class CDecorationPositioner; diff --git a/src/render/pass/Pass.cpp b/src/render/pass/Pass.cpp index 8970e2af4..3910e6a76 100644 --- a/src/render/pass/Pass.cpp +++ b/src/render/pass/Pass.cpp @@ -4,7 +4,7 @@ #include #include "../../Compositor.hpp" #include "../../config/ConfigValue.hpp" -#include "../../desktop/WLSurface.hpp" +#include "../../desktop/view/WLSurface.hpp" #include "../../managers/SeatManager.hpp" #include "../../managers/eventLoop/EventLoopManager.hpp" #include "../../render/Renderer.hpp" @@ -211,7 +211,7 @@ void CRenderPass::renderDebugData() { if (!surface || !texture) return; - auto hlSurface = CWLSurface::fromResource(surface); + auto hlSurface = Desktop::View::CWLSurface::fromResource(surface); if (!hlSurface) return; @@ -244,12 +244,12 @@ void CRenderPass::renderDebugData() { renderHLSurface(m_debugData.keyboardFocusText, g_pSeatManager->m_state.keyboardFocus.lock(), Colors::PURPLE.modifyA(0.1F)); renderHLSurface(m_debugData.pointerFocusText, g_pSeatManager->m_state.pointerFocus.lock(), Colors::ORANGE.modifyA(0.1F)); if (Desktop::focusState()->window()) - renderHLSurface(m_debugData.lastWindowText, Desktop::focusState()->window()->m_wlSurface->resource(), Colors::LIGHT_BLUE.modifyA(0.1F)); + renderHLSurface(m_debugData.lastWindowText, Desktop::focusState()->window()->wlSurface()->resource(), Colors::LIGHT_BLUE.modifyA(0.1F)); if (g_pSeatManager->m_state.pointerFocus) { if (g_pSeatManager->m_state.pointerFocus->m_current.input.intersect(CBox{{}, g_pSeatManager->m_state.pointerFocus->m_current.size}).getExtents().size() != g_pSeatManager->m_state.pointerFocus->m_current.size) { - auto hlSurface = CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); + auto hlSurface = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock()); if (hlSurface) { auto BOX = hlSurface->getSurfaceBoxGlobal(); if (BOX) { diff --git a/src/render/pass/SurfacePassElement.cpp b/src/render/pass/SurfacePassElement.cpp index 36b9e5f9e..b5c42310b 100644 --- a/src/render/pass/SurfacePassElement.cpp +++ b/src/render/pass/SurfacePassElement.cpp @@ -1,7 +1,7 @@ #include "SurfacePassElement.hpp" #include "../OpenGL.hpp" -#include "../../desktop/WLSurface.hpp" -#include "../../desktop/Window.hpp" +#include "../../desktop/view/WLSurface.hpp" +#include "../../desktop/view/Window.hpp" #include "../../protocols/core/Compositor.hpp" #include "../../protocols/DRMSyncobj.hpp" #include "../../managers/input/InputManager.hpp" @@ -54,7 +54,7 @@ void CSurfacePassElement::draw(const CRegion& damage) { const auto INTERACTIVERESIZEINPROGRESS = m_data.pWindow && g_pInputManager->m_currentlyDraggedWindow && g_pInputManager->m_dragMode == MBIND_RESIZE; TRACY_GPU_ZONE("RenderSurface"); - auto PSURFACE = CWLSurface::fromResource(m_data.surface); + auto PSURFACE = Desktop::View::CWLSurface::fromResource(m_data.surface); const float ALPHA = m_data.alpha * m_data.fadeAlpha * (PSURFACE ? PSURFACE->m_alphaModifier : 1.F); const float OVERALL_ALPHA = PSURFACE ? PSURFACE->m_overallOpacity : 1.F; @@ -102,7 +102,7 @@ void CSurfacePassElement::draw(const CRegion& damage) { roundingPower = 2.0f; } - const bool WINDOWOPAQUE = m_data.pWindow && m_data.pWindow->m_wlSurface->resource() == m_data.surface ? m_data.pWindow->opaque() : false; + const bool WINDOWOPAQUE = m_data.pWindow && m_data.pWindow->wlSurface()->resource() == m_data.surface ? m_data.pWindow->opaque() : false; const bool CANDISABLEBLEND = ALPHA >= 1.f && OVERALL_ALPHA >= 1.f && rounding == 0 && WINDOWOPAQUE; if (CANDISABLEBLEND) @@ -164,14 +164,14 @@ CBox CSurfacePassElement::getTexBox() { const double outputX = -m_data.pMonitor->m_position.x, outputY = -m_data.pMonitor->m_position.y; const auto INTERACTIVERESIZEINPROGRESS = m_data.pWindow && g_pInputManager->m_currentlyDraggedWindow && g_pInputManager->m_dragMode == MBIND_RESIZE; - auto PSURFACE = CWLSurface::fromResource(m_data.surface); + auto PSURFACE = Desktop::View::CWLSurface::fromResource(m_data.surface); CBox windowBox; if (m_data.surface && m_data.mainSurface) { windowBox = {sc(outputX) + m_data.pos.x + m_data.localPos.x, sc(outputY) + m_data.pos.y + m_data.localPos.y, m_data.w, m_data.h}; // however, if surface buffer w / h < box, we need to adjust them - const auto PWINDOW = PSURFACE ? PSURFACE->getWindow() : nullptr; + const auto PWINDOW = PSURFACE ? Desktop::View::CWindow::fromView(PSURFACE->view()) : nullptr; // center the surface if it's smaller than the viewport we assign it if (PSURFACE && !PSURFACE->m_fillIgnoreSmall && PSURFACE->small() /* guarantees PWINDOW */) { @@ -216,7 +216,7 @@ CBox CSurfacePassElement::getTexBox() { } bool CSurfacePassElement::needsLiveBlur() { - auto PSURFACE = CWLSurface::fromResource(m_data.surface); + auto PSURFACE = Desktop::View::CWLSurface::fromResource(m_data.surface); const float ALPHA = m_data.alpha * m_data.fadeAlpha * (PSURFACE ? PSURFACE->m_alphaModifier * PSURFACE->m_overallOpacity : 1.F); const bool BLUR = m_data.blur && (!m_data.texture || !m_data.texture->m_opaque || ALPHA < 1.F); @@ -233,7 +233,7 @@ bool CSurfacePassElement::needsLiveBlur() { } bool CSurfacePassElement::needsPrecomputeBlur() { - auto PSURFACE = CWLSurface::fromResource(m_data.surface); + auto PSURFACE = Desktop::View::CWLSurface::fromResource(m_data.surface); const float ALPHA = m_data.alpha * m_data.fadeAlpha * (PSURFACE ? PSURFACE->m_alphaModifier * PSURFACE->m_overallOpacity : 1.F); const bool BLUR = m_data.blur && (!m_data.texture || !m_data.texture->m_opaque || ALPHA < 1.F); @@ -254,7 +254,7 @@ std::optional CSurfacePassElement::boundingBox() { } CRegion CSurfacePassElement::opaqueRegion() { - auto PSURFACE = CWLSurface::fromResource(m_data.surface); + auto PSURFACE = Desktop::View::CWLSurface::fromResource(m_data.surface); const float ALPHA = m_data.alpha * m_data.fadeAlpha * (PSURFACE ? PSURFACE->m_alphaModifier * PSURFACE->m_overallOpacity : 1.F); @@ -272,7 +272,7 @@ CRegion CSurfacePassElement::opaqueRegion() { } CRegion CSurfacePassElement::visibleRegion(bool& cancel) { - auto PSURFACE = CWLSurface::fromResource(m_data.surface); + auto PSURFACE = Desktop::View::CWLSurface::fromResource(m_data.surface); if (!PSURFACE) return {}; diff --git a/src/xwayland/Dnd.cpp b/src/xwayland/Dnd.cpp index 2967c1895..924df6b54 100644 --- a/src/xwayland/Dnd.cpp +++ b/src/xwayland/Dnd.cpp @@ -5,7 +5,7 @@ #include "Server.hpp" #endif #include "../managers/XWaylandManager.hpp" -#include "../desktop/WLSurface.hpp" +#include "../desktop/view/WLSurface.hpp" #include "../protocols/core/Compositor.hpp" using namespace Hyprutils::OS; diff --git a/src/xwayland/XWM.cpp b/src/xwayland/XWM.cpp index 316a97880..48afe3aba 100644 --- a/src/xwayland/XWM.cpp +++ b/src/xwayland/XWM.cpp @@ -58,7 +58,7 @@ void CXWM::handleCreate(xcb_create_notify_event_t* e) { XSURF->m_self = XSURF; Debug::log(LOG, "[xwm] New XSurface at {:x} with xid of {}", rc(XSURF.get()), e->window); - const auto WINDOW = CWindow::create(XSURF); + const auto WINDOW = Desktop::View::CWindow::create(XSURF); g_pCompositor->m_windows.emplace_back(WINDOW); WINDOW->m_self = WINDOW; Debug::log(LOG, "[xwm] New XWayland window at {:x} for surf {:x}", rc(WINDOW.get()), rc(XSURF.get()));