summaryrefslogtreecommitdiff
path: root/src/layout/target/Target.cpp
blob: e8ce48bd7409b61f899a2b73362ce1f94244dee1 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "Target.hpp"
#include "../space/Space.hpp"
#include "../../debug/log/Logger.hpp"

#include <hyprutils/utils/ScopeGuard.hpp>

using namespace Layout;
using namespace Hyprutils::Utils;

void ITarget::setPositionGlobal(const STargetBox& box) {
    m_box = box;
    m_box.logicalBox.round();
    m_box.visualBox.round();
}

void ITarget::setPositionGlobal(const CBox& box) {
    setPositionGlobal({.logicalBox = box});
}

void ITarget::assignToSpace(const SP<CSpace>& space, std::optional<Vector2D> focalPoint) {
    if (m_space == space && !m_ghostSpace)
        return;

    const bool HAD_SPACE = !!m_space;

    if (m_space && !m_ghostSpace)
        m_space->remove(m_self.lock());

    m_space = space;

    if (space && HAD_SPACE)
        space->move(m_self.lock(), focalPoint);
    else if (space)
        space->add(m_self.lock());

    if (!space)
        Log::logger->log(Log::WARN, "ITarget: assignToSpace with a null space?");

    m_ghostSpace = false;

    onUpdateSpace();
}

void ITarget::setSpaceGhost(const SP<CSpace>& space) {
    if (m_space)
        assignToSpace(nullptr);

    m_space = space;

    m_ghostSpace = true;
}

SP<CSpace> ITarget::space() const {
    return m_space;
}

PHLWORKSPACE ITarget::workspace() const {
    if (!m_space)
        return nullptr;

    return m_space->workspace();
}

CBox ITarget::position() const {
    return m_box.logicalBox;
}

void ITarget::rememberFloatingSize(const Vector2D& size) {
    m_floatingSize = size;
}

Vector2D ITarget::lastFloatingSize() const {
    return m_floatingSize;
}

void ITarget::recalc() {
    setPositionGlobal(m_box);
}

void ITarget::setPseudo(bool x) {
    if (m_pseudo == x)
        return;

    m_pseudo = x;

    recalc();
}

bool ITarget::isPseudo() const {
    return m_pseudo;
}

void ITarget::setPseudoSize(const Vector2D& size) {
    m_pseudoSize = size;

    recalc();
}

Vector2D ITarget::pseudoSize() {
    return m_pseudoSize;
}

void ITarget::swap(SP<ITarget> b) {
    const auto IS_FLOATING   = floating();
    const auto IS_FLOATING_B = b->floating();

    // Keep workspaces alive during a swap: moving one window will unref the ws

    // NOLINTNEXTLINE
    const auto PWS1 = workspace();
    // NOLINTNEXTLINE
    const auto  PWS2 = b->workspace();

    CScopeGuard x([&] {
        b->setFloating(IS_FLOATING);
        setFloating(IS_FLOATING_B);

        // update the spaces
        b->onUpdateSpace();
        onUpdateSpace();
    });

    if (b->space() == m_space) {
        // simplest
        m_space->swap(m_self.lock(), b);
        m_space->recalculate();
        return;
    }

    // spaces differ
    if (m_space)
        m_space->swap(m_self.lock(), b);
    if (b->space())
        b->space()->swap(b, m_self.lock());

    std::swap(m_space, b->m_space);

    // recalc both
    if (m_space)
        m_space->recalculate();
    if (b->space())
        b->space()->recalculate();
}

bool ITarget::wasTiling() const {
    return m_wasTiling;
}

void ITarget::setWasTiling(bool x) {
    m_wasTiling = x;
}