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
|
#include "FloatGesture.hpp"
#include "../../../../render/Renderer.hpp"
#include "../../../../desktop/state/FocusState.hpp"
#include "../../../../desktop/view/Window.hpp"
#include "../../../../layout/LayoutManager.hpp"
#include "../../../../layout/target/WindowTarget.hpp"
constexpr const float MAX_DISTANCE = 250.F;
//
static Vector2D lerpVal(const Vector2D& from, const Vector2D& to, const float& t) {
return Vector2D{
from.x + ((to.x - from.x) * t),
from.y + ((to.y - from.y) * t),
};
}
CFloatTrackpadGesture::CFloatTrackpadGesture(const std::string_view& data) {
std::string lc = std::string{data};
std::ranges::transform(lc, lc.begin(), ::tolower);
if (lc.starts_with("float"))
m_mode = FLOAT_MODE_FLOAT;
else if (lc.starts_with("tile"))
m_mode = FLOAT_MODE_TILE;
else
m_mode = FLOAT_MODE_TOGGLE;
}
void CFloatTrackpadGesture::begin(const ITrackpadGesture::STrackpadGestureBegin& e) {
ITrackpadGesture::begin(e);
m_window = Desktop::focusState()->window();
if (!m_window)
return;
if ((m_window->m_isFloating && m_mode == FLOAT_MODE_FLOAT) || (!m_window->m_isFloating && m_mode == FLOAT_MODE_TILE)) {
m_window.reset();
return;
}
g_layoutManager->changeFloatingMode(m_window->layoutTarget());
m_posFrom = m_window->m_realPosition->begun();
m_sizeFrom = m_window->m_realSize->begun();
m_posTo = m_window->m_realPosition->goal();
m_sizeTo = m_window->m_realSize->goal();
m_lastDelta = 0.F;
}
void CFloatTrackpadGesture::update(const ITrackpadGesture::STrackpadGestureUpdate& e) {
if (!m_window)
return;
g_pHyprRenderer->damageWindow(m_window.lock());
m_lastDelta += distance(e);
const auto FADEPERCENT = std::clamp(m_lastDelta / MAX_DISTANCE, 0.F, 1.F);
m_window->m_realPosition->setValueAndWarp(lerpVal(m_posFrom, m_posTo, FADEPERCENT));
m_window->m_realSize->setValueAndWarp(lerpVal(m_sizeFrom, m_sizeTo, FADEPERCENT));
g_pDecorationPositioner->onWindowUpdate(m_window.lock());
g_pHyprRenderer->damageWindow(m_window.lock());
}
void CFloatTrackpadGesture::end(const ITrackpadGesture::STrackpadGestureEnd& e) {
if (!m_window)
return;
const auto COMPLETION = std::clamp(m_lastDelta / MAX_DISTANCE, 0.F, 1.F);
if (COMPLETION < 0.2F) {
// revert the animation
g_pHyprRenderer->damageWindow(m_window.lock());
g_layoutManager->changeFloatingMode(m_window->layoutTarget());
return;
}
*m_window->m_realPosition = m_posTo;
*m_window->m_realSize = m_sizeTo;
}
|