aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/layout/MasterLayout.hpp
blob: e316556af5d9510c4d5256c2d55488ee606b481c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once

#include "IHyprLayout.hpp"
#include "../config/ConfigManager.hpp"
#include <vector>
#include <list>
#include <deque>
#include <any>

enum eFullscreenMode : int8_t;

//orientation determines which side of the screen the master area resides
enum eOrientation : uint8_t {
    ORIENTATION_LEFT = 0,
    ORIENTATION_TOP,
    ORIENTATION_RIGHT,
    ORIENTATION_BOTTOM,
    ORIENTATION_CENTER
};

struct SMasterNodeData {
    bool     isMaster   = false;
    float    percMaster = 0.5f;

    CWindow* pWindow = nullptr;

    Vector2D position;
    Vector2D size;

    float    percSize = 1.f; // size multiplier for resizing children

    int      workspaceID = -1;

    bool     ignoreFullscreenChecks = false;

    //
    bool operator==(const SMasterNodeData& rhs) const {
        return pWindow == rhs.pWindow;
    }
};

struct SMasterWorkspaceData {
    int          workspaceID = -1;
    eOrientation orientation = ORIENTATION_LEFT;

    //
    bool operator==(const SMasterWorkspaceData& rhs) const {
        return workspaceID == rhs.workspaceID;
    }
};

class CHyprMasterLayout : 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                     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();
    virtual void                     replaceWindowDataWith(CWindow* from, CWindow* to);

    virtual void                     onEnable();
    virtual void                     onDisable();

  private:
    std::list<SMasterNodeData>        m_lMasterNodesData;
    std::vector<SMasterWorkspaceData> m_lMasterWorkspacesData;

    bool                              m_bForceWarps = false;

    void                              buildOrientationCycleVectorFromVars(std::vector<eOrientation>& cycle, CVarList& vars);
    void                              buildOrientationCycleVectorFromEOperation(std::vector<eOrientation>& cycle);
    void                              runOrientationCycle(SLayoutMessageHeader& header, CVarList* vars, int next);
    int                               getNodesOnWorkspace(const int&);
    void                              applyNodeDataToWindow(SMasterNodeData*);
    SMasterNodeData*                  getNodeFromWindow(CWindow*);
    SMasterNodeData*                  getMasterNodeOnWorkspace(const int&);
    SMasterWorkspaceData*             getMasterWorkspaceData(const int&);
    void                              calculateWorkspace(const int&);
    CWindow*                          getNextWindow(CWindow*, bool);
    int                               getMastersOnWorkspace(const int&);
    bool                              prepareLoseFocus(CWindow*);
    void                              prepareNewFocus(CWindow*, bool inherit_fullscreen);

    friend struct SMasterNodeData;
    friend struct SMasterWorkspaceData;
};

template <typename CharT>
struct std::formatter<SMasterNodeData*, CharT> : std::formatter<CharT> {
    template <typename FormatContext>
    auto format(const SMasterNodeData* 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->position, node->size);
        if (node->isMaster)
            std::format_to(out, ", master");
        if (node->pWindow)
            std::format_to(out, ", window: {:x}", node->pWindow);
        return std::format_to(out, "]");
    }
};