summaryrefslogtreecommitdiff
path: root/src/layout/algorithm/Algorithm.hpp
blob: 61c40285cea1183815b524655adfaaccafcf1511 (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
#pragma once

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

#include "../LayoutManager.hpp"

#include <expected>
#include <optional>

namespace Layout {
    class ITarget;
    class IFloatingAlgorithm;
    class ITiledAlgorithm;
    class CSpace;

    class CAlgorithm {
      public:
        static SP<CAlgorithm> create(UP<ITiledAlgorithm>&& tiled, UP<IFloatingAlgorithm>&& floating, SP<CSpace> space);
        ~CAlgorithm() = default;

        void                          addTarget(SP<ITarget> target);
        void                          moveTarget(SP<ITarget> target, std::optional<Vector2D> focalPoint = std::nullopt, bool reposition = false);
        void                          removeTarget(SP<ITarget> target);

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

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

        void                          setFloating(SP<ITarget> target, bool floating, bool reposition = false);

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

        void                          recalculate();
        void                          recenter(SP<ITarget> t);

        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

        eFullscreenRequestResult      requestFullscreen(SP<ITarget> target, eFullscreenMode currentEffectiveMode, eFullscreenMode effectiveMode);
        SP<ITarget>                   layoutFullscreenTarget() const;
        bool                          layoutFullscreenCoversMonitor() const;

        void                          updateFloatingAlgo(UP<IFloatingAlgorithm>&& algo);
        void                          updateTiledAlgo(UP<ITiledAlgorithm>&& algo);

        const UP<ITiledAlgorithm>&    tiledAlgo() const;
        const UP<IFloatingAlgorithm>& floatingAlgo() const;

        SP<CSpace>                    space() const;

        size_t                        tiledTargets() const;
        size_t                        floatingTargets() const;

      private:
        CAlgorithm(UP<ITiledAlgorithm>&& tiled, UP<IFloatingAlgorithm>&& floating, SP<CSpace> space);

        UP<ITiledAlgorithm>      m_tiled;
        UP<IFloatingAlgorithm>   m_floating;
        WP<CSpace>               m_space;
        WP<CAlgorithm>           m_self;

        std::vector<WP<ITarget>> m_tiledTargets, m_floatingTargets;
    };
}