summaryrefslogtreecommitdiff
path: root/src/layout/space/Space.hpp
blob: af731a50666095efa201936e77462c8aa10eab24 (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
#pragma once

#include "../../helpers/math/Math.hpp"
#include "../../helpers/math/Direction.hpp"
#include "../../helpers/memory/Memory.hpp"

#include "../../desktop/DesktopTypes.hpp"

#include "../LayoutManager.hpp"

#include <optional>
#include <expected>

namespace Layout {

    enum eRecalculateReason : uint8_t {
        RECALCULATE_REASON_UNKNOWN, // when the recalculate reason is unknown or not important to preserve
        RECALCULATE_REASON_WORKSPACE_CHANGE,
        RECALCULATE_REASON_SPECIAL_WORKSPACE_TOGGLE,
        RECALCULATE_REASON_TOGGLE_FULLSCREEN,
        RECALCULATE_REASON_INVALIDATE_MONITOR_GEOMETRIES,
        RECALCULATE_REASON_RENDER_MOINTOR,
    };

    eRecalculateReason recalcMonitorReasonToRecalcReason(CLayoutManager::eRecalculateMonitorReason reason);

    class ITarget;
    class CAlgorithm;

    class CSpace {
      public:
        static SP<CSpace> create(PHLWORKSPACE w);
        ~CSpace() = default;

        void                            add(SP<ITarget> t);
        void                            remove(SP<ITarget> t);
        void                            move(SP<ITarget> t, std::optional<Vector2D> focalPoint = std::nullopt);

        void                            swap(SP<ITarget> a, SP<ITarget> b);

        SP<ITarget>                     getNextCandidate(SP<ITarget> old);

        void                            setAlgorithmProvider(SP<CAlgorithm> algo);
        void                            recheckWorkArea();
        eFullscreenRequestResult        setFullscreen(SP<ITarget> t, eFullscreenMode currentEffectiveMode, eFullscreenMode mode);

        void                            moveTargetInDirection(SP<ITarget> t, Math::eDirection dir, bool silent);

        void                            recalculate(eRecalculateReason reason = RECALCULATE_REASON_UNKNOWN);

        void                            toggleTargetFloating(SP<ITarget> t);

        Config::ErrorResult             layoutMsg(const std::string_view& sv);
        std::optional<Vector2D>         predictSizeForNewTiledTarget();

        const CBox&                     workArea(bool floating = false) const;
        PHLWORKSPACE                    workspace() const;
        CBox                            targetPositionLocal(SP<ITarget> t) const;

        void                            resizeTarget(const Vector2D& Δ, SP<ITarget> target, eRectCorner corner = CORNER_NONE);
        void                            moveTarget(const Vector2D& Δ, SP<ITarget> target);
        void                            setTargetGeom(const CBox& box, SP<ITarget> target); // only for float

        SP<CAlgorithm>                  algorithm() const;

        const std::vector<WP<ITarget>>& targets() const;

      private:
        CSpace(PHLWORKSPACE parent);

        WP<CSpace>               m_self;

        std::vector<WP<ITarget>> m_targets;
        SP<CAlgorithm>           m_algorithm;
        PHLWORKSPACEREF          m_parent;

        // work area is in global coords
        CBox m_workArea, m_floatingWorkArea;

        // for recalc
        CHyprSignalListener m_geomUpdateCallback;
    };

    bool isHardRecalculateReason(eRecalculateReason reason);
};