summaryrefslogtreecommitdiff
path: root/src/managers/input/trackpad/gestures/MoveGesture.cpp
blob: 0dcc310fec38c069f8494dc204bad09cd20fec39 (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
#include "MoveGesture.hpp"

#include "../../../../desktop/state/FocusState.hpp"
#include "../../../../desktop/view/Window.hpp"
#include "../../../../render/Renderer.hpp"
#include "../../../../layout/LayoutManager.hpp"

void CMoveTrackpadGesture::begin(const ITrackpadGesture::STrackpadGestureBegin& e) {
    ITrackpadGesture::begin(e);

    m_window    = Desktop::focusState()->window();
    m_lastDelta = {};
}

void CMoveTrackpadGesture::update(const ITrackpadGesture::STrackpadGestureUpdate& e) {
    if (!m_window)
        return;

    const auto DELTA = e.swipe ? e.swipe->delta : e.pinch->delta;

    if (m_window->m_isFloating) {
        g_layoutManager->moveTarget(DELTA, m_window->layoutTarget());
        m_window->m_realSize->warp();
        m_window->m_realPosition->warp();
        return;
    }

    // tiled window -> displace, then execute a move dispatcher on end.

    g_pHyprRenderer->damageWindow(m_window.lock());

    // funny name but works on tiled too lmao
    m_lastDelta += DELTA;
    m_window->m_floatingOffset = (m_lastDelta * 0.5F).clamp(Vector2D{-100.F, -100.F}, Vector2D{100.F, 100.F});

    g_pHyprRenderer->damageWindow(m_window.lock());
}

void CMoveTrackpadGesture::end(const ITrackpadGesture::STrackpadGestureEnd& e) {

    if (!m_window)
        return;

    if (m_window->m_isFloating || m_lastDelta.size() < 0.1F)
        return;

    // tiled: attempt to move window in the given direction

    const auto WINDOWPOS = m_window->m_realPosition->goal() + m_window->m_floatingOffset;

    m_window->m_floatingOffset = {};

    if (std::abs(m_lastDelta.x) > std::abs(m_lastDelta.y)) {
        // horizontal
        g_layoutManager->moveInDirection(m_window->layoutTarget(), m_lastDelta.x > 0 ? "r" : "l");
    } else {
        // vertical
        g_layoutManager->moveInDirection(m_window->layoutTarget(), m_lastDelta.y > 0 ? "b" : "t");
    }

    const auto GOAL = m_window->m_realPosition->goal();

    m_window->m_realPosition->setValueAndWarp(WINDOWPOS);
    *m_window->m_realPosition = GOAL;

    m_window.reset();
}