Hyprland/src/layout/DwindleLayout.hpp

106 lines
4.3 KiB
C++
Raw Normal View History

#pragma once
#include "IHyprLayout.hpp"
#include <list>
#include <deque>
#include <array>
#include <optional>
#include <format>
2022-03-19 20:30:21 +01:00
class CHyprDwindleLayout;
enum eFullscreenMode : int8_t;
2022-03-19 20:30:21 +01:00
struct SDwindleNodeData {
SDwindleNodeData* pParent = nullptr;
bool isNode = false;
CWindow* pWindow = nullptr;
std::array<SDwindleNodeData*, 2> children = {nullptr, nullptr};
bool splitTop = false; // for preserve_split
2022-05-16 17:27:55 +02:00
CBox box = {0};
int workspaceID = -1;
float splitRatio = 1.f;
bool valid = true;
2022-08-01 12:51:52 +02:00
bool ignoreFullscreenChecks = false;
// For list lookup
2023-01-31 01:03:23 +01:00
bool operator==(const SDwindleNodeData& rhs) const {
return pWindow == rhs.pWindow && workspaceID == rhs.workspaceID && box == rhs.box && pParent == rhs.pParent && children[0] == rhs.children[0] &&
children[1] == rhs.children[1];
}
2023-05-06 02:02:18 +02:00
void recalcSizePosRecursive(bool force = false, bool horizontalOverride = false, bool verticalOverride = false);
void getAllChildrenRecursive(std::deque<SDwindleNodeData*>*);
2022-03-19 20:30:21 +01:00
CHyprDwindleLayout* layout = nullptr;
};
class CHyprDwindleLayout : public IHyprLayout {
public:
virtual void onWindowCreatedTiling(CWindow*, eDirection direction = DIRECTION_DEFAULT);
virtual void onWindowRemovedTiling(CWindow*);
virtual bool isWindowTiled(CWindow*);
virtual void recalculateMonitor(const int&);
virtual void recalculateWindow(CWindow*);
virtual void onBeginDragWindow();
virtual void resizeActiveWindow(const Vector2D&, eRectCorner corner = CORNER_NONE, CWindow* pWindow = nullptr);
virtual void fullscreenRequestForWindow(CWindow*, eFullscreenMode, bool);
virtual std::any layoutMessage(SLayoutMessageHeader, std::string);
virtual SWindowRenderLayoutHints requestRenderHints(CWindow*);
virtual void switchWindows(CWindow*, CWindow*);
virtual void moveWindowTo(CWindow*, const std::string& dir);
virtual void alterSplitRatio(CWindow*, float, bool);
virtual std::string getLayoutName();
2023-02-19 22:07:32 +01:00
virtual void replaceWindowDataWith(CWindow* from, CWindow* to);
virtual Vector2D predictSizeForNewWindow();
virtual void onEnable();
virtual void onDisable();
private:
std::list<SDwindleNodeData> m_lDwindleNodesData;
struct {
bool started = false;
bool pseudo = false;
bool xExtent = false;
bool yExtent = false;
} m_PseudoDragFlags;
std::optional<Vector2D> m_vOverrideFocalPoint; // for onWindowCreatedTiling.
int getNodesOnWorkspace(const int&);
void applyNodeDataToWindow(SDwindleNodeData*, bool force = false);
SDwindleNodeData* getNodeFromWindow(CWindow*);
SDwindleNodeData* getFirstNodeOnWorkspace(const int&);
SDwindleNodeData* getClosestNodeOnWorkspace(const int&, const Vector2D&);
SDwindleNodeData* getMasterNodeOnWorkspace(const int&);
2022-05-16 17:37:46 +02:00
void toggleSplit(CWindow*);
void swapSplit(CWindow*);
eDirection overrideDirection = DIRECTION_DEFAULT;
2023-05-06 02:02:18 +02:00
2022-03-19 20:30:21 +01:00
friend struct SDwindleNodeData;
};
template <typename CharT>
struct std::formatter<SDwindleNodeData*, CharT> : std::formatter<CharT> {
template <typename FormatContext>
auto format(const SDwindleNodeData* const& node, FormatContext& ctx) const {
auto out = ctx.out();
if (!node)
return std::format_to(out, "[Node nullptr]");
std::format_to(out, "[Node {:x}: workspace: {}, pos: {:j2}, size: {:j2}", (uintptr_t)node, node->workspaceID, node->box.pos(), node->box.size());
if (!node->isNode && node->pWindow)
std::format_to(out, ", window: {:x}", node->pWindow);
return std::format_to(out, "]");
}
};