2022-07-07 11:52:12 +02:00
|
|
|
#include "InputManager.hpp"
|
|
|
|
#include "../../Compositor.hpp"
|
2024-03-03 19:39:20 +01:00
|
|
|
#include "../../config/ConfigValue.hpp"
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
void CInputManager::onSwipeBegin(IPointer::SSwipeBeginEvent e) {
|
2024-06-07 19:54:08 +02:00
|
|
|
static auto PSWIPE = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe");
|
|
|
|
static auto PSWIPEFINGERS = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_fingers");
|
|
|
|
static auto PSWIPEMINFINGERS = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_min_fingers");
|
|
|
|
static auto PSWIPENEW = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_create_new");
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-04-03 20:20:47 +02:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("swipeBegin", e);
|
|
|
|
|
2024-06-07 19:54:08 +02:00
|
|
|
if ((!*PSWIPEMINFINGERS && e.fingers != *PSWIPEFINGERS) || (*PSWIPEMINFINGERS && e.fingers < *PSWIPEFINGERS) || *PSWIPE == 0 || g_pSessionLockManager->isSessionLocked())
|
2022-07-07 11:52:12 +02:00
|
|
|
return;
|
|
|
|
|
2022-07-25 15:42:27 +02:00
|
|
|
int onMonitor = 0;
|
|
|
|
for (auto& w : g_pCompositor->m_vWorkspaces) {
|
2022-11-27 23:42:22 +01:00
|
|
|
if (w->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID && !g_pCompositor->isWorkspaceSpecial(w->m_iID)) {
|
2022-07-25 15:42:27 +02:00
|
|
|
onMonitor++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (onMonitor < 2 && !*PSWIPENEW)
|
2022-07-25 15:42:27 +02:00
|
|
|
return; // disallow swiping when there's 1 workspace on a monitor
|
|
|
|
|
2022-11-03 14:34:06 +01:00
|
|
|
beginWorkspaceSwipe();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::beginWorkspaceSwipe() {
|
2024-04-02 21:32:39 +02:00
|
|
|
const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace;
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2023-09-06 21:45:37 +02:00
|
|
|
Debug::log(LOG, "Starting a swipe from {}", PWORKSPACE->m_szName);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
|
|
|
m_sActiveSwipe.pWorkspaceBegin = PWORKSPACE;
|
2022-12-16 18:17:31 +01:00
|
|
|
m_sActiveSwipe.delta = 0;
|
2024-05-05 23:18:10 +02:00
|
|
|
m_sActiveSwipe.pMonitor = g_pCompositor->m_pLastMonitor.get();
|
2022-12-16 18:17:31 +01:00
|
|
|
m_sActiveSwipe.avgSpeed = 0;
|
|
|
|
m_sActiveSwipe.speedPoints = 0;
|
2022-09-19 11:23:13 +02:00
|
|
|
|
|
|
|
if (PWORKSPACE->m_bHasFullscreenWindow) {
|
2024-05-09 22:47:21 +02:00
|
|
|
for (auto& ls : g_pCompositor->m_pLastMonitor->m_aLayerSurfaceLayers[2]) {
|
2023-01-05 19:25:45 +01:00
|
|
|
ls->alpha = 1.f;
|
2022-09-19 11:23:13 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
void CInputManager::onSwipeEnd(IPointer::SSwipeEndEvent e) {
|
2024-04-03 20:20:47 +02:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("swipeEnd", e);
|
|
|
|
|
2022-07-07 20:53:22 +02:00
|
|
|
if (!m_sActiveSwipe.pWorkspaceBegin)
|
|
|
|
return; // no valid swipe
|
2024-03-17 16:43:59 +01:00
|
|
|
endWorkspaceSwipe();
|
|
|
|
}
|
2022-07-07 20:53:22 +02:00
|
|
|
|
2024-03-17 16:43:59 +01:00
|
|
|
void CInputManager::endWorkspaceSwipe() {
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PSWIPEPERC = CConfigValue<Hyprlang::FLOAT>("gestures:workspace_swipe_cancel_ratio");
|
|
|
|
static auto PSWIPEDIST = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_distance");
|
|
|
|
static auto PSWIPEFORC = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_min_speed_to_force");
|
|
|
|
static auto PSWIPENEW = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_create_new");
|
|
|
|
static auto PSWIPEUSER = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_use_r");
|
|
|
|
static auto PWORKSPACEGAP = CConfigValue<Hyprlang::INT>("general:gaps_workspaces");
|
|
|
|
const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" ||
|
2023-10-15 20:07:23 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert");
|
2022-07-07 11:52:12 +02:00
|
|
|
|
|
|
|
// commit
|
2022-12-16 18:17:31 +01:00
|
|
|
std::string wsname = "";
|
2024-04-11 13:45:46 +02:00
|
|
|
auto workspaceIDLeft = getWorkspaceIDFromString((*PSWIPEUSER ? "r-1" : "m-1"), wsname);
|
|
|
|
auto workspaceIDRight = getWorkspaceIDFromString((*PSWIPEUSER ? "r+1" : "m+1"), wsname);
|
2024-04-26 20:11:28 +02:00
|
|
|
const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2023-04-07 13:18:53 +02:00
|
|
|
// 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.
|
|
|
|
// With multiple monitors, it might not be appropriate to choose one more
|
|
|
|
// than the ID of the workspace we're swiping from, because that ID might
|
|
|
|
// just be on another monitor. It's also not just the smallest unused ID,
|
|
|
|
// because that could be a gap in the existing workspace numbers, and it'd
|
|
|
|
// be counterintuitive to swipe rightwards onto a new workspace and end up
|
|
|
|
// left of where we started. Instead, it's one more than the greatest
|
|
|
|
// workspace ID that currently exists.
|
2024-03-03 19:39:20 +01:00
|
|
|
if (workspaceIDRight <= m_sActiveSwipe.pWorkspaceBegin->m_iID && *PSWIPENEW) {
|
2023-04-07 13:18:53 +02:00
|
|
|
int maxWorkspace = 0;
|
|
|
|
for (const auto& ws : g_pCompositor->m_vWorkspaces) {
|
|
|
|
maxWorkspace = std::max(maxWorkspace, ws->m_iID);
|
|
|
|
}
|
|
|
|
workspaceIDRight = maxWorkspace + 1;
|
2022-10-20 15:54:32 +02:00
|
|
|
}
|
|
|
|
|
2024-04-02 21:32:39 +02:00
|
|
|
auto PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight); // not guaranteed if PSWIPENEW || PSWIPENUMBER
|
|
|
|
auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft); // not guaranteed if PSWIPENUMBER
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-04-02 21:32:39 +02:00
|
|
|
const auto RENDEROFFSETMIDDLE = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.value();
|
|
|
|
const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + *PWORKSPACEGAP;
|
|
|
|
const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP;
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-04-02 21:32:39 +02:00
|
|
|
PHLWORKSPACE pSwitchedTo = nullptr;
|
2022-09-19 11:23:13 +02:00
|
|
|
|
2024-04-26 20:11:28 +02:00
|
|
|
if ((abs(m_sActiveSwipe.delta) < SWIPEDISTANCE * *PSWIPEPERC && (*PSWIPEFORC == 0 || (*PSWIPEFORC != 0 && m_sActiveSwipe.avgSpeed < *PSWIPEFORC))) ||
|
2022-12-16 18:17:31 +01:00
|
|
|
abs(m_sActiveSwipe.delta) < 2) {
|
2022-07-07 11:52:12 +02:00
|
|
|
// revert
|
2022-07-25 14:06:49 +02:00
|
|
|
if (abs(m_sActiveSwipe.delta) < 2) {
|
2022-12-25 16:42:11 +01:00
|
|
|
if (PWORKSPACEL)
|
|
|
|
PWORKSPACEL->m_vRenderOffset.setValueAndWarp(Vector2D(0, 0));
|
2022-10-20 15:54:32 +02:00
|
|
|
if (PWORKSPACER)
|
2022-12-16 18:17:31 +01:00
|
|
|
PWORKSPACER->m_vRenderOffset.setValueAndWarp(Vector2D(0, 0));
|
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0, 0));
|
2022-07-07 11:52:12 +02:00
|
|
|
} else {
|
2022-07-25 14:06:49 +02:00
|
|
|
if (m_sActiveSwipe.delta < 0) {
|
|
|
|
// to left
|
2023-11-19 13:33:26 +01:00
|
|
|
|
2022-12-25 16:42:11 +01:00
|
|
|
if (PWORKSPACEL) {
|
|
|
|
if (VERTANIMS)
|
2024-06-19 16:20:06 +02:00
|
|
|
PWORKSPACEL->m_vRenderOffset = Vector2D{0.0, -YDISTANCE};
|
2022-12-25 16:42:11 +01:00
|
|
|
else
|
2024-06-19 16:20:06 +02:00
|
|
|
PWORKSPACEL->m_vRenderOffset = Vector2D{-XDISTANCE, 0.0};
|
2022-12-25 16:42:11 +01:00
|
|
|
}
|
2022-10-20 15:54:32 +02:00
|
|
|
} else if (PWORKSPACER) {
|
2022-07-25 14:06:49 +02:00
|
|
|
// to right
|
2022-10-07 17:52:53 +02:00
|
|
|
if (VERTANIMS)
|
2024-06-19 16:20:06 +02:00
|
|
|
PWORKSPACER->m_vRenderOffset = Vector2D{0.0, YDISTANCE};
|
2022-10-07 17:52:53 +02:00
|
|
|
else
|
2024-06-19 16:20:06 +02:00
|
|
|
PWORKSPACER->m_vRenderOffset = Vector2D{XDISTANCE, 0.0};
|
2022-07-25 14:06:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset = Vector2D();
|
2022-07-07 11:52:12 +02:00
|
|
|
}
|
2022-09-19 11:23:13 +02:00
|
|
|
|
|
|
|
pSwitchedTo = m_sActiveSwipe.pWorkspaceBegin;
|
2022-07-07 11:52:12 +02:00
|
|
|
} else if (m_sActiveSwipe.delta < 0) {
|
|
|
|
// switch to left
|
2024-03-02 01:35:17 +01:00
|
|
|
const auto RENDEROFFSET = PWORKSPACEL ? PWORKSPACEL->m_vRenderOffset.value() : Vector2D();
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2022-12-25 16:42:11 +01:00
|
|
|
if (PWORKSPACEL)
|
2023-04-14 16:03:53 +02:00
|
|
|
m_sActiveSwipe.pMonitor->changeWorkspace(workspaceIDLeft);
|
2022-12-25 16:42:11 +01:00
|
|
|
else {
|
2023-04-14 16:03:53 +02:00
|
|
|
m_sActiveSwipe.pMonitor->changeWorkspace(g_pCompositor->createNewWorkspace(workspaceIDLeft, m_sActiveSwipe.pMonitor->ID));
|
2022-12-25 16:42:11 +01:00
|
|
|
PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft);
|
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
|
|
|
|
PWORKSPACEL->m_vRenderOffset.setValue(RENDEROFFSET);
|
2023-01-05 19:25:45 +01:00
|
|
|
PWORKSPACEL->m_fAlpha.setValueAndWarp(1.f);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2022-07-19 18:30:53 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValue(RENDEROFFSETMIDDLE);
|
2022-10-07 17:52:53 +02:00
|
|
|
if (VERTANIMS)
|
2024-06-19 16:20:06 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset = Vector2D(0.0, YDISTANCE);
|
2022-10-07 17:52:53 +02:00
|
|
|
else
|
2024-06-19 16:20:06 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset = Vector2D(XDISTANCE, 0.0);
|
2023-01-05 19:25:45 +01:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_fAlpha.setValueAndWarp(1.f);
|
2022-07-19 18:30:53 +02:00
|
|
|
|
2022-08-09 20:36:21 +02:00
|
|
|
g_pInputManager->unconstrainMouse();
|
2022-07-26 18:38:30 +02:00
|
|
|
|
2022-07-07 11:52:12 +02:00
|
|
|
Debug::log(LOG, "Ended swipe to the left");
|
2022-09-19 11:23:13 +02:00
|
|
|
|
|
|
|
pSwitchedTo = PWORKSPACEL;
|
2022-07-07 11:52:12 +02:00
|
|
|
} else {
|
|
|
|
// switch to right
|
2024-03-02 01:35:17 +01:00
|
|
|
const auto RENDEROFFSET = PWORKSPACER ? PWORKSPACER->m_vRenderOffset.value() : Vector2D();
|
2022-10-20 15:54:32 +02:00
|
|
|
|
|
|
|
if (PWORKSPACER)
|
2023-04-14 16:03:53 +02:00
|
|
|
m_sActiveSwipe.pMonitor->changeWorkspace(workspaceIDRight);
|
2022-12-25 16:42:11 +01:00
|
|
|
else {
|
2023-04-14 16:03:53 +02:00
|
|
|
m_sActiveSwipe.pMonitor->changeWorkspace(g_pCompositor->createNewWorkspace(workspaceIDRight, m_sActiveSwipe.pMonitor->ID));
|
2022-12-25 16:42:11 +01:00
|
|
|
PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight);
|
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
|
|
|
|
PWORKSPACER->m_vRenderOffset.setValue(RENDEROFFSET);
|
2023-01-05 19:25:45 +01:00
|
|
|
PWORKSPACER->m_fAlpha.setValueAndWarp(1.f);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2022-07-19 18:30:53 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValue(RENDEROFFSETMIDDLE);
|
2022-10-07 17:52:53 +02:00
|
|
|
if (VERTANIMS)
|
2024-06-19 16:20:06 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset = Vector2D(0.0, -YDISTANCE);
|
2022-10-07 17:52:53 +02:00
|
|
|
else
|
2024-06-19 16:20:06 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset = Vector2D(-XDISTANCE, 0.0);
|
2023-01-05 19:25:45 +01:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_fAlpha.setValueAndWarp(1.f);
|
2022-07-19 18:30:53 +02:00
|
|
|
|
2022-08-09 20:36:21 +02:00
|
|
|
g_pInputManager->unconstrainMouse();
|
2022-07-26 18:38:30 +02:00
|
|
|
|
2022-07-07 11:52:12 +02:00
|
|
|
Debug::log(LOG, "Ended swipe to the right");
|
2022-09-19 11:23:13 +02:00
|
|
|
|
|
|
|
pSwitchedTo = PWORKSPACER;
|
2022-07-07 11:52:12 +02:00
|
|
|
}
|
2023-09-12 00:39:24 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->rememberPrevWorkspace(pSwitchedTo);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2022-08-16 16:34:36 +02:00
|
|
|
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor);
|
|
|
|
|
2022-12-25 16:42:11 +01:00
|
|
|
if (PWORKSPACEL)
|
|
|
|
PWORKSPACEL->m_bForceRendering = false;
|
2022-10-20 15:54:32 +02:00
|
|
|
if (PWORKSPACER)
|
|
|
|
PWORKSPACER->m_bForceRendering = false;
|
2022-07-07 11:52:12 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_bForceRendering = false;
|
|
|
|
|
2023-08-23 22:40:19 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin = nullptr;
|
|
|
|
m_sActiveSwipe.initialDirection = 0;
|
2022-07-07 11:52:12 +02:00
|
|
|
|
|
|
|
g_pInputManager->refocus();
|
2022-09-19 11:23:13 +02:00
|
|
|
|
|
|
|
// apply alpha
|
2024-05-09 22:47:21 +02:00
|
|
|
for (auto& ls : g_pCompositor->m_pLastMonitor->m_aLayerSurfaceLayers[2]) {
|
2023-01-05 19:25:45 +01:00
|
|
|
ls->alpha = pSwitchedTo->m_bHasFullscreenWindow && pSwitchedTo->m_efFullscreenMode == FULLSCREEN_FULL ? 0.f : 1.f;
|
2022-09-19 11:23:13 +02:00
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
void CInputManager::onSwipeUpdate(IPointer::SSwipeUpdateEvent e) {
|
2024-04-03 20:20:47 +02:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("swipeUpdate", e);
|
|
|
|
|
2024-03-20 19:13:31 +01:00
|
|
|
if (!m_sActiveSwipe.pWorkspaceBegin)
|
|
|
|
return;
|
2024-03-17 16:43:59 +01:00
|
|
|
static auto PSWIPEINVR = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_invert");
|
|
|
|
const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" ||
|
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert");
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
const double delta = m_sActiveSwipe.delta + (VERTANIMS ? (*PSWIPEINVR ? -e.delta.y : e.delta.y) : (*PSWIPEINVR ? -e.delta.x : e.delta.x));
|
2024-03-17 16:43:59 +01:00
|
|
|
updateWorkspaceSwipe(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::updateWorkspaceSwipe(double delta) {
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PSWIPEDIST = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_distance");
|
|
|
|
static auto PSWIPENEW = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_create_new");
|
|
|
|
static auto PSWIPEDIRLOCK = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_direction_lock");
|
|
|
|
static auto PSWIPEDIRLOCKTHRESHOLD = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_direction_lock_threshold");
|
|
|
|
static auto PSWIPEFOREVER = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_forever");
|
|
|
|
static auto PSWIPEUSER = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_use_r");
|
|
|
|
static auto PWORKSPACEGAP = CConfigValue<Hyprlang::INT>("general:gaps_workspaces");
|
|
|
|
|
2024-04-26 20:11:28 +02:00
|
|
|
const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX);
|
|
|
|
const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + *PWORKSPACEGAP;
|
|
|
|
const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP;
|
|
|
|
const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" ||
|
2023-10-15 20:07:23 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert");
|
2024-03-17 16:43:59 +01:00
|
|
|
const double d = m_sActiveSwipe.delta - delta;
|
|
|
|
m_sActiveSwipe.delta = delta;
|
2022-10-07 17:52:53 +02:00
|
|
|
|
2024-03-17 16:43:59 +01:00
|
|
|
m_sActiveSwipe.avgSpeed = (m_sActiveSwipe.avgSpeed * m_sActiveSwipe.speedPoints + abs(d)) / (m_sActiveSwipe.speedPoints + 1);
|
2022-07-07 11:52:12 +02:00
|
|
|
m_sActiveSwipe.speedPoints++;
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
std::string wsname = "";
|
2024-04-11 13:45:46 +02:00
|
|
|
auto workspaceIDLeft = getWorkspaceIDFromString((*PSWIPEUSER ? "r-1" : "m-1"), wsname);
|
|
|
|
auto workspaceIDRight = getWorkspaceIDFromString((*PSWIPEUSER ? "r+1" : "m+1"), wsname);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if ((workspaceIDLeft == WORKSPACE_INVALID || workspaceIDRight == WORKSPACE_INVALID || workspaceIDLeft == m_sActiveSwipe.pWorkspaceBegin->m_iID) && !*PSWIPENEW) {
|
2022-09-17 16:05:12 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin = nullptr; // invalidate the swipe
|
2022-07-07 11:52:12 +02:00
|
|
|
return;
|
2022-09-17 16:05:12 +02:00
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2022-07-22 00:13:56 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_bForceRendering = true;
|
|
|
|
|
2024-04-26 20:11:28 +02:00
|
|
|
m_sActiveSwipe.delta = std::clamp(m_sActiveSwipe.delta, (double)-SWIPEDISTANCE, (double)SWIPEDISTANCE);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if ((m_sActiveSwipe.pWorkspaceBegin->m_iID == workspaceIDLeft && *PSWIPENEW && (m_sActiveSwipe.delta < 0)) ||
|
2022-12-16 18:17:31 +01:00
|
|
|
(m_sActiveSwipe.delta > 0 && g_pCompositor->getWindowsOnWorkspace(m_sActiveSwipe.pWorkspaceBegin->m_iID) == 0 &&
|
|
|
|
workspaceIDRight <= m_sActiveSwipe.pWorkspaceBegin->m_iID) ||
|
2022-11-22 00:30:26 +01:00
|
|
|
(m_sActiveSwipe.delta < 0 && m_sActiveSwipe.pWorkspaceBegin->m_iID <= workspaceIDLeft)) {
|
|
|
|
|
2022-10-20 15:54:32 +02:00
|
|
|
m_sActiveSwipe.delta = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PSWIPEDIRLOCK) {
|
2023-08-23 22:40:19 +02:00
|
|
|
if (m_sActiveSwipe.initialDirection != 0 && m_sActiveSwipe.initialDirection != (m_sActiveSwipe.delta < 0 ? -1 : 1))
|
|
|
|
m_sActiveSwipe.delta = 0;
|
2024-03-03 19:39:20 +01:00
|
|
|
else if (m_sActiveSwipe.initialDirection == 0 && abs(m_sActiveSwipe.delta) > *PSWIPEDIRLOCKTHRESHOLD)
|
2023-08-23 22:40:19 +02:00
|
|
|
m_sActiveSwipe.initialDirection = m_sActiveSwipe.delta < 0 ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
2022-07-07 11:52:12 +02:00
|
|
|
if (m_sActiveSwipe.delta < 0) {
|
2022-12-25 16:42:11 +01:00
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceIDLeft);
|
|
|
|
|
|
|
|
if (workspaceIDLeft > m_sActiveSwipe.pWorkspaceBegin->m_iID || !PWORKSPACE) {
|
2024-04-11 13:45:46 +02:00
|
|
|
if (*PSWIPENEW) {
|
2022-12-25 16:42:11 +01:00
|
|
|
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor);
|
|
|
|
|
|
|
|
if (VERTANIMS)
|
2024-06-19 16:20:06 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0.0, ((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * YDISTANCE));
|
2022-12-25 16:42:11 +01:00
|
|
|
else
|
2024-06-19 16:20:06 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE, 0.0));
|
2022-12-25 16:42:11 +01:00
|
|
|
|
|
|
|
g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID);
|
|
|
|
return;
|
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
m_sActiveSwipe.delta = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PWORKSPACE->m_bForceRendering = true;
|
2023-01-05 19:25:45 +01:00
|
|
|
PWORKSPACE->m_fAlpha.setValueAndWarp(1.f);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-01-11 19:22:40 +01:00
|
|
|
if (workspaceIDLeft != workspaceIDRight && workspaceIDRight != m_sActiveSwipe.pWorkspaceBegin->m_iID) {
|
2022-07-25 14:06:49 +02:00
|
|
|
const auto PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight);
|
2022-07-22 00:10:26 +02:00
|
|
|
|
2022-12-25 16:42:11 +01:00
|
|
|
if (PWORKSPACER) {
|
|
|
|
PWORKSPACER->m_bForceRendering = false;
|
|
|
|
PWORKSPACER->m_fAlpha.setValueAndWarp(0.f);
|
|
|
|
}
|
2022-07-25 14:06:49 +02:00
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2022-10-07 17:52:53 +02:00
|
|
|
if (VERTANIMS) {
|
2024-06-19 16:20:06 +02:00
|
|
|
PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(0.0, ((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * YDISTANCE - YDISTANCE));
|
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0.0, ((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * YDISTANCE));
|
2022-10-07 17:52:53 +02:00
|
|
|
} else {
|
2024-06-19 16:20:06 +02:00
|
|
|
PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE - XDISTANCE, 0.0));
|
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE, 0.0));
|
2022-10-07 17:52:53 +02:00
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
|
|
|
|
g_pCompositor->updateWorkspaceWindowDecos(workspaceIDLeft);
|
|
|
|
} else {
|
2022-12-25 16:42:11 +01:00
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceIDRight);
|
|
|
|
|
|
|
|
if (workspaceIDRight < m_sActiveSwipe.pWorkspaceBegin->m_iID || !PWORKSPACE) {
|
2024-04-11 13:45:46 +02:00
|
|
|
if (*PSWIPENEW) {
|
2022-10-20 18:52:17 +02:00
|
|
|
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor);
|
|
|
|
|
2022-10-20 16:02:46 +02:00
|
|
|
if (VERTANIMS)
|
2024-06-19 16:20:06 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0.0, ((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * YDISTANCE));
|
2022-10-20 16:02:46 +02:00
|
|
|
else
|
2024-06-19 16:20:06 +02:00
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE, 0.0));
|
2022-10-20 18:52:17 +02:00
|
|
|
|
|
|
|
g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID);
|
2022-10-20 16:02:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
m_sActiveSwipe.delta = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PWORKSPACE->m_bForceRendering = true;
|
2023-01-05 19:25:45 +01:00
|
|
|
PWORKSPACE->m_fAlpha.setValueAndWarp(1.f);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-01-11 19:22:40 +01:00
|
|
|
if (workspaceIDLeft != workspaceIDRight && workspaceIDLeft != m_sActiveSwipe.pWorkspaceBegin->m_iID) {
|
2022-07-25 14:06:49 +02:00
|
|
|
const auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft);
|
2022-07-22 00:10:26 +02:00
|
|
|
|
2022-12-25 16:42:11 +01:00
|
|
|
if (PWORKSPACEL) {
|
|
|
|
PWORKSPACEL->m_bForceRendering = false;
|
|
|
|
PWORKSPACEL->m_fAlpha.setValueAndWarp(0.f);
|
|
|
|
}
|
2022-07-25 14:06:49 +02:00
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2022-10-07 17:52:53 +02:00
|
|
|
if (VERTANIMS) {
|
2024-06-19 16:20:06 +02:00
|
|
|
PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(0.0, ((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * YDISTANCE + YDISTANCE));
|
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0.0, ((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * YDISTANCE));
|
2022-10-07 17:52:53 +02:00
|
|
|
} else {
|
2024-06-19 16:20:06 +02:00
|
|
|
PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE + XDISTANCE, 0.0));
|
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE, 0.0));
|
2022-10-07 17:52:53 +02:00
|
|
|
}
|
2022-07-07 11:52:12 +02:00
|
|
|
|
|
|
|
g_pCompositor->updateWorkspaceWindowDecos(workspaceIDRight);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor);
|
|
|
|
|
|
|
|
g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID);
|
2022-11-03 14:34:06 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PSWIPEFOREVER) {
|
2024-04-26 20:11:28 +02:00
|
|
|
if (abs(m_sActiveSwipe.delta) >= SWIPEDISTANCE) {
|
2024-05-05 23:18:10 +02:00
|
|
|
onSwipeEnd({});
|
2022-11-03 14:34:06 +01:00
|
|
|
beginWorkspaceSwipe();
|
|
|
|
}
|
|
|
|
}
|
2023-04-07 13:18:53 +02:00
|
|
|
}
|