-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathOverviewGesture.cpp
More file actions
64 lines (48 loc) · 1.7 KB
/
Copy pathOverviewGesture.cpp
File metadata and controls
64 lines (48 loc) · 1.7 KB
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
#include "OverviewGesture.hpp"
#include "scrollOverview.hpp"
#include <algorithm>
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/desktop/state/FocusState.hpp>
#include <hyprland/src/output/Monitor.hpp>
void COverviewGesture::begin(const ITrackpadGesture::STrackpadGestureBegin& e) {
ITrackpadGesture::begin(e);
m_lastDelta = 0.F;
m_firstUpdate = true;
const auto MONITOR = Desktop::focusState()->monitor();
if (!MONITOR)
return;
auto overview = scrollOverviewForMonitor(MONITOR);
if (!overview) {
if (!ensureScrollOverviewHooks())
return;
overview = makeShared<CScrollOverview>(MONITOR->m_activeWorkspace, true, MONITOR);
registerScrollOverview(overview);
} else {
overview->selectHoveredWorkspace();
overview->setClosing(true);
}
m_overview = overview;
g_pScrollOverview = overview;
}
void COverviewGesture::update(const ITrackpadGesture::STrackpadGestureUpdate& e) {
const auto OVERVIEW = m_overview.lock();
if (!OVERVIEW)
return;
if (m_firstUpdate) {
m_firstUpdate = false;
return;
}
m_lastDelta += distance(e);
if (m_lastDelta <= 0.01) // plugin will crash if swipe ends at <= 0
m_lastDelta = 0.01;
OVERVIEW->onSwipeUpdate(m_lastDelta);
}
void COverviewGesture::end(const ITrackpadGesture::STrackpadGestureEnd& e) {
const auto OVERVIEW = m_overview.lock();
if (OVERVIEW)
OVERVIEW->onSwipeEnd();
// Re-check the same instance since onSwipeEnd can finish its close.
if (std::ranges::find(scrollOverviews(), OVERVIEW) != scrollOverviews().end())
OVERVIEW->resetSwipe();
m_overview.reset();
}