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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
#include "UnifiedWorkspaceSwipeGesture.hpp"
#include "../../Compositor.hpp"
#include "../../desktop/state/FocusState.hpp"
#include "../../render/Renderer.hpp"
#include "InputManager.hpp"
bool CUnifiedWorkspaceSwipeGesture::isGestureInProgress() {
return m_workspaceBegin;
}
void CUnifiedWorkspaceSwipeGesture::begin() {
if (isGestureInProgress())
return;
const auto PWORKSPACE = Desktop::focusState()->monitor()->m_activeWorkspace;
Log::logger->log(Log::DEBUG, "CUnifiedWorkspaceSwipeGesture::begin: Starting a swipe from {}", PWORKSPACE->m_name);
m_workspaceBegin = PWORKSPACE;
m_delta = 0;
m_monitor = Desktop::focusState()->monitor();
m_avgSpeed = 0;
m_speedPoints = 0;
if (PWORKSPACE->m_hasFullscreenWindow) {
for (auto const& ls : Desktop::focusState()->monitor()->m_layerSurfaceLayers[2]) {
*ls->m_alpha = 1.f;
}
}
}
void CUnifiedWorkspaceSwipeGesture::update(double delta) {
if (!isGestureInProgress())
return;
static auto PSWIPEDIST = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_distance");
static auto PSWIPENEW = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_create_new");
static auto PSWIPEDIRLOCK = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_direction_lock");
static auto PSWIPEDIRLOCKTHRESHOLD = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_direction_lock_threshold");
static auto PSWIPEFOREVER = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_forever");
static auto PSWIPEUSER = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_use_r");
static auto PWORKSPACEGAP = CConfigValue<Config::INTEGER>("general:gaps_workspaces");
const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, sc<int64_t>(1LL), sc<int64_t>(UINT32_MAX));
const auto XDISTANCE = m_monitor->m_size.x + *PWORKSPACEGAP;
const auto YDISTANCE = m_monitor->m_size.y + *PWORKSPACEGAP;
const auto ANIMSTYLE = m_workspaceBegin->m_renderOffset->getStyle();
const bool VERTANIMS = ANIMSTYLE == "slidevert" || ANIMSTYLE.starts_with("slidefadevert");
const double d = m_delta - delta;
m_delta = delta;
m_avgSpeed = (m_avgSpeed * m_speedPoints + abs(d)) / (m_speedPoints + 1);
m_speedPoints++;
auto workspaceIDLeft = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r-1" : "m-1")).id;
auto workspaceIDRight = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r+1" : "m+1")).id;
if ((workspaceIDLeft == WORKSPACE_INVALID || workspaceIDRight == WORKSPACE_INVALID || workspaceIDLeft == m_workspaceBegin->m_id) && !*PSWIPENEW) {
m_workspaceBegin = nullptr; // invalidate the swipe
return;
}
m_workspaceBegin->m_forceRendering = true;
m_delta = std::clamp(m_delta, sc<double>(-SWIPEDISTANCE), sc<double>(SWIPEDISTANCE));
if ((m_workspaceBegin->m_id == workspaceIDLeft && *PSWIPENEW && (m_delta < 0)) ||
(m_delta > 0 && m_workspaceBegin->getWindows() == 0 && workspaceIDRight <= m_workspaceBegin->m_id) || (m_delta < 0 && m_workspaceBegin->m_id <= workspaceIDLeft)) {
m_delta = 0;
g_pHyprRenderer->damageMonitor(m_monitor.lock());
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(0.0, 0.0));
return;
}
if (*PSWIPEDIRLOCK) {
if (m_initialDirection != 0 && m_initialDirection != (m_delta < 0 ? -1 : 1))
m_delta = 0;
else if (m_initialDirection == 0 && abs(m_delta) > *PSWIPEDIRLOCKTHRESHOLD)
m_initialDirection = m_delta < 0 ? -1 : 1;
}
if (m_delta < 0) {
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceIDLeft);
if (workspaceIDLeft > m_workspaceBegin->m_id || !PWORKSPACE) {
if (*PSWIPENEW) {
g_pHyprRenderer->damageMonitor(m_monitor.lock());
if (VERTANIMS)
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(0.0, ((-m_delta) / SWIPEDISTANCE) * YDISTANCE));
else
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(((-m_delta) / SWIPEDISTANCE) * XDISTANCE, 0.0));
m_workspaceBegin->updateWindowDecos();
return;
}
m_delta = 0;
return;
}
PWORKSPACE->m_forceRendering = true;
PWORKSPACE->m_alpha->setValueAndWarp(1.f);
if (workspaceIDLeft != workspaceIDRight && workspaceIDRight != m_workspaceBegin->m_id) {
const auto PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight);
if (PWORKSPACER) {
PWORKSPACER->m_forceRendering = false;
PWORKSPACER->m_alpha->setValueAndWarp(0.f);
}
}
if (VERTANIMS) {
PWORKSPACE->m_renderOffset->setValueAndWarp(Vector2D(0.0, ((-m_delta) / SWIPEDISTANCE) * YDISTANCE - YDISTANCE));
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(0.0, ((-m_delta) / SWIPEDISTANCE) * YDISTANCE));
} else {
PWORKSPACE->m_renderOffset->setValueAndWarp(Vector2D(((-m_delta) / SWIPEDISTANCE) * XDISTANCE - XDISTANCE, 0.0));
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(((-m_delta) / SWIPEDISTANCE) * XDISTANCE, 0.0));
}
PWORKSPACE->updateWindowDecos();
} else {
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceIDRight);
if (workspaceIDRight < m_workspaceBegin->m_id || !PWORKSPACE) {
if (*PSWIPENEW) {
g_pHyprRenderer->damageMonitor(m_monitor.lock());
if (VERTANIMS)
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(0.0, ((-m_delta) / SWIPEDISTANCE) * YDISTANCE));
else
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(((-m_delta) / SWIPEDISTANCE) * XDISTANCE, 0.0));
m_workspaceBegin->updateWindowDecos();
return;
}
m_delta = 0;
return;
}
PWORKSPACE->m_forceRendering = true;
PWORKSPACE->m_alpha->setValueAndWarp(1.f);
if (workspaceIDLeft != workspaceIDRight && workspaceIDLeft != m_workspaceBegin->m_id) {
const auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft);
if (PWORKSPACEL) {
PWORKSPACEL->m_forceRendering = false;
PWORKSPACEL->m_alpha->setValueAndWarp(0.f);
}
}
if (VERTANIMS) {
PWORKSPACE->m_renderOffset->setValueAndWarp(Vector2D(0.0, ((-m_delta) / SWIPEDISTANCE) * YDISTANCE + YDISTANCE));
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(0.0, ((-m_delta) / SWIPEDISTANCE) * YDISTANCE));
} else {
PWORKSPACE->m_renderOffset->setValueAndWarp(Vector2D(((-m_delta) / SWIPEDISTANCE) * XDISTANCE + XDISTANCE, 0.0));
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(((-m_delta) / SWIPEDISTANCE) * XDISTANCE, 0.0));
}
PWORKSPACE->updateWindowDecos();
}
g_pHyprRenderer->damageMonitor(m_monitor.lock());
m_workspaceBegin->updateWindowDecos();
if (*PSWIPEFOREVER) {
if (abs(m_delta) >= SWIPEDISTANCE) {
end();
begin();
}
}
}
void CUnifiedWorkspaceSwipeGesture::end() {
if (!isGestureInProgress())
return;
static auto PSWIPEPERC = CConfigValue<Config::FLOAT>("gestures:workspace_swipe_cancel_ratio");
static auto PSWIPEDIST = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_distance");
static auto PSWIPEFORC = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_min_speed_to_force");
static auto PSWIPENEW = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_create_new");
static auto PSWIPEUSER = CConfigValue<Config::INTEGER>("gestures:workspace_swipe_use_r");
static auto PWORKSPACEGAP = CConfigValue<Config::INTEGER>("general:gaps_workspaces");
const auto ANIMSTYLE = m_workspaceBegin->m_renderOffset->getStyle();
const bool VERTANIMS = ANIMSTYLE == "slidevert" || ANIMSTYLE.starts_with("slidefadevert");
// commit
auto workspaceIDLeft = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r-1" : "m-1")).id;
auto workspaceIDRight = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r+1" : "m+1")).id;
const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, sc<int64_t>(1LL), sc<int64_t>(UINT32_MAX));
// If we've been swiping off the right end with PSWIPENEW enabled, there is
// no workspace there yet, and we need to choose an ID for a new one now.
if (workspaceIDRight <= m_workspaceBegin->m_id && *PSWIPENEW)
workspaceIDRight = getWorkspaceIDNameFromString("r+1").id;
auto PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight); // not guaranteed if PSWIPENEW || PSWIPENUMBER
auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft); // not guaranteed if PSWIPENUMBER
const auto RENDEROFFSETMIDDLE = m_workspaceBegin->m_renderOffset->value();
const auto XDISTANCE = m_monitor->m_size.x + *PWORKSPACEGAP;
const auto YDISTANCE = m_monitor->m_size.y + *PWORKSPACEGAP;
PHLWORKSPACE pSwitchedTo = nullptr;
if ((abs(m_delta) < SWIPEDISTANCE * *PSWIPEPERC && (*PSWIPEFORC == 0 || (*PSWIPEFORC != 0 && m_avgSpeed < *PSWIPEFORC))) || abs(m_delta) < 2) {
// revert
if (abs(m_delta) < 2) {
if (PWORKSPACEL)
PWORKSPACEL->m_renderOffset->setValueAndWarp(Vector2D(0, 0));
if (PWORKSPACER)
PWORKSPACER->m_renderOffset->setValueAndWarp(Vector2D(0, 0));
m_workspaceBegin->m_renderOffset->setValueAndWarp(Vector2D(0, 0));
} else {
if (m_delta < 0) {
// to left
if (PWORKSPACEL) {
if (VERTANIMS)
*PWORKSPACEL->m_renderOffset = Vector2D{0.0, -YDISTANCE};
else
*PWORKSPACEL->m_renderOffset = Vector2D{-XDISTANCE, 0.0};
}
} else if (PWORKSPACER) {
// to right
if (VERTANIMS)
*PWORKSPACER->m_renderOffset = Vector2D{0.0, YDISTANCE};
else
*PWORKSPACER->m_renderOffset = Vector2D{XDISTANCE, 0.0};
}
*m_workspaceBegin->m_renderOffset = Vector2D();
}
pSwitchedTo = m_workspaceBegin;
} else if (m_delta < 0) {
// switch to left
const auto RENDEROFFSET = PWORKSPACEL ? PWORKSPACEL->m_renderOffset->value() : Vector2D();
if (PWORKSPACEL)
m_monitor->changeWorkspace(workspaceIDLeft);
else {
m_monitor->changeWorkspace(g_pCompositor->createNewWorkspace(workspaceIDLeft, m_monitor->m_id));
PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft);
}
PWORKSPACEL->m_renderOffset->setValue(RENDEROFFSET);
PWORKSPACEL->m_alpha->setValueAndWarp(1.f);
m_workspaceBegin->m_renderOffset->setValue(RENDEROFFSETMIDDLE);
if (VERTANIMS)
*m_workspaceBegin->m_renderOffset = Vector2D(0.0, YDISTANCE);
else
*m_workspaceBegin->m_renderOffset = Vector2D(XDISTANCE, 0.0);
m_workspaceBegin->m_alpha->setValueAndWarp(1.f);
g_pInputManager->unconstrainMouse();
Log::logger->log(Log::DEBUG, "Ended swipe to the left");
pSwitchedTo = PWORKSPACEL;
} else {
// switch to right
const auto RENDEROFFSET = PWORKSPACER ? PWORKSPACER->m_renderOffset->value() : Vector2D();
if (PWORKSPACER)
m_monitor->changeWorkspace(workspaceIDRight);
else {
m_monitor->changeWorkspace(g_pCompositor->createNewWorkspace(workspaceIDRight, m_monitor->m_id));
PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight);
}
PWORKSPACER->m_renderOffset->setValue(RENDEROFFSET);
PWORKSPACER->m_alpha->setValueAndWarp(1.f);
m_workspaceBegin->m_renderOffset->setValue(RENDEROFFSETMIDDLE);
if (VERTANIMS)
*m_workspaceBegin->m_renderOffset = Vector2D(0.0, -YDISTANCE);
else
*m_workspaceBegin->m_renderOffset = Vector2D(-XDISTANCE, 0.0);
m_workspaceBegin->m_alpha->setValueAndWarp(1.f);
g_pInputManager->unconstrainMouse();
Log::logger->log(Log::DEBUG, "Ended swipe to the right");
pSwitchedTo = PWORKSPACER;
}
g_pHyprRenderer->damageMonitor(m_monitor.lock());
if (PWORKSPACEL)
PWORKSPACEL->m_forceRendering = false;
if (PWORKSPACER)
PWORKSPACER->m_forceRendering = false;
m_workspaceBegin->m_forceRendering = false;
m_workspaceBegin = nullptr;
m_initialDirection = 0;
g_pInputManager->refocus();
// apply alpha
for (auto const& ls : Desktop::focusState()->monitor()->m_layerSurfaceLayers[2]) {
*ls->m_alpha = pSwitchedTo->m_hasFullscreenWindow && pSwitchedTo->m_fullscreenMode == FSMODE_FULLSCREEN ? 0.f : 1.f;
}
}
|