From 723870337f299d4c80aa0048144f3a1ca1c885bd Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 21 Feb 2026 21:30:39 +0000 Subject: layout: rethonk layouts from the ground up (#12890) Rewrites layouts to be much smaller, and deal with much less annoying BS. Improves the overall architecture, unifies handling of pseudotiling, and various other improvements. --- src/layout/LayoutManager.hpp | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/layout/LayoutManager.hpp (limited to 'src/layout/LayoutManager.hpp') diff --git a/src/layout/LayoutManager.hpp b/src/layout/LayoutManager.hpp new file mode 100644 index 00000000..638c9f4c --- /dev/null +++ b/src/layout/LayoutManager.hpp @@ -0,0 +1,86 @@ +#pragma once + +#include "../helpers/memory/Memory.hpp" +#include "../helpers/math/Math.hpp" +#include "../managers/input/InputManager.hpp" + +#include "supplementary/DragController.hpp" + +#include +#include + +enum eFullscreenMode : int8_t; + +namespace Layout { + class ITarget; + class CSpace; + + enum eRectCorner : uint8_t { + CORNER_NONE = 0, + CORNER_TOPLEFT = (1 << 0), + CORNER_TOPRIGHT = (1 << 1), + CORNER_BOTTOMRIGHT = (1 << 2), + CORNER_BOTTOMLEFT = (1 << 3), + }; + + inline eRectCorner cornerFromBox(const CBox& box, const Vector2D& pos) { + const auto CENTER = box.middle(); + + if (pos.x < CENTER.x) + return pos.y < CENTER.y ? CORNER_TOPLEFT : CORNER_BOTTOMLEFT; + return pos.y < CENTER.y ? CORNER_TOPRIGHT : CORNER_BOTTOMRIGHT; + } + + enum eSnapEdge : uint8_t { + SNAP_INVALID = 0, + SNAP_UP = (1 << 0), + SNAP_DOWN = (1 << 1), + SNAP_LEFT = (1 << 2), + SNAP_RIGHT = (1 << 3), + }; + + class CLayoutManager { + public: + CLayoutManager(); + ~CLayoutManager() = default; + + void newTarget(SP target, SP space); + void removeTarget(SP target); + + void changeFloatingMode(SP target); + + void beginDragTarget(SP target, eMouseBindMode mode); + void moveMouse(const Vector2D& mousePos); + void resizeTarget(const Vector2D& Δ, SP target, eRectCorner corner = CORNER_NONE); + void moveTarget(const Vector2D& Δ, SP target); + void endDragTarget(); + + std::expected layoutMsg(const std::string_view& sv); + + void fullscreenRequestForTarget(SP target, eFullscreenMode currentEffectiveMode, eFullscreenMode effectiveMode); + + void switchTargets(SP a, SP b, bool preserveFocus = true); + + void moveInDirection(SP target, const std::string& direction, bool silent = false); + + SP getNextCandidate(SP space, SP from); + + bool isReachable(SP target); + + void bringTargetToTop(SP target); + + std::optional predictSizeForNewTiledTarget(); + + void performSnap(Vector2D& sourcePos, Vector2D& sourceSize, SP target, eMouseBindMode mode, int corner, const Vector2D& beginSize); + + void invalidateMonitorGeometries(PHLMONITOR); + void recalculateMonitor(PHLMONITOR); + + const UP& dragController(); + + private: + UP m_dragStateController = makeUnique(); + }; +} + +inline UP g_layoutManager; \ No newline at end of file -- cgit v1.2.3