2022-08-07 21:17:03 +02:00
|
|
|
#include "InputManager.hpp"
|
2025-01-25 12:44:13 -06:00
|
|
|
#include "../SessionLockManager.hpp"
|
|
|
|
|
#include "../../protocols/SessionLock.hpp"
|
2022-08-07 21:17:03 +02:00
|
|
|
#include "../../Compositor.hpp"
|
2025-01-17 15:21:35 +00:00
|
|
|
#include "../../desktop/LayerSurface.hpp"
|
2024-03-17 11:43:59 -04:00
|
|
|
#include "../../config/ConfigValue.hpp"
|
2025-04-15 23:00:40 +00:00
|
|
|
#include "../../helpers/Monitor.hpp"
|
2024-05-03 22:34:10 +01:00
|
|
|
#include "../../devices/ITouch.hpp"
|
2024-05-10 18:27:57 +01:00
|
|
|
#include "../SeatManager.hpp"
|
2025-01-07 17:55:14 +00:00
|
|
|
#include "managers/AnimationManager.hpp"
|
2025-01-17 15:21:35 +00:00
|
|
|
#include "../HookSystemManager.hpp"
|
2025-01-25 12:44:13 -06:00
|
|
|
#include "debug/Log.hpp"
|
2022-08-07 21:17:03 +02:00
|
|
|
|
2024-05-05 22:18:10 +01:00
|
|
|
void CInputManager::onTouchDown(ITouch::SDownEvent e) {
|
2024-07-22 13:05:06 +02:00
|
|
|
m_bLastInputTouch = true;
|
|
|
|
|
|
2024-03-17 11:43:59 -04:00
|
|
|
static auto PSWIPETOUCH = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_touch");
|
|
|
|
|
static auto PGAPSOUTDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:gaps_out");
|
|
|
|
|
auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData();
|
|
|
|
|
// TODO: WORKSPACERULE.gapsOut.value_or()
|
|
|
|
|
auto gapsOut = *PGAPSOUT;
|
|
|
|
|
static auto PBORDERSIZE = CConfigValue<Hyprlang::INT>("general:border_size");
|
2024-07-24 10:59:50 +02:00
|
|
|
static auto PSWIPEINVR = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_touch_invert");
|
2023-11-13 17:32:12 +01:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("touchDown", e);
|
|
|
|
|
|
2025-04-29 19:51:07 +02:00
|
|
|
auto PMONITOR = g_pCompositor->getMonitorFromName(!e.device->m_boundOutput.empty() ? e.device->m_boundOutput : "");
|
2022-10-14 12:38:44 +01:00
|
|
|
|
2025-04-22 15:23:29 +02:00
|
|
|
PMONITOR = PMONITOR ? PMONITOR : g_pCompositor->m_lastMonitor.lock();
|
2022-10-14 12:38:44 +01:00
|
|
|
|
2024-05-05 22:18:10 +01:00
|
|
|
g_pCompositor->warpCursorTo({PMONITOR->vecPosition.x + e.pos.x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e.pos.y * PMONITOR->vecSize.y}, true);
|
2022-08-07 21:17:03 +02:00
|
|
|
|
|
|
|
|
refocus();
|
|
|
|
|
|
2023-02-28 19:02:30 +00:00
|
|
|
if (m_ecbClickBehavior == CLICKMODE_KILL) {
|
2024-05-05 22:18:10 +01:00
|
|
|
IPointer::SButtonEvent e;
|
2024-03-09 16:35:35 +00:00
|
|
|
e.state = WL_POINTER_BUTTON_STATE_PRESSED;
|
2024-05-05 22:18:10 +01:00
|
|
|
g_pInputManager->processMouseDownKill(e);
|
2023-02-28 19:02:30 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 11:43:59 -04:00
|
|
|
// Don't propagate new touches when a workspace swipe is in progress.
|
|
|
|
|
if (m_sActiveSwipe.pWorkspaceBegin) {
|
|
|
|
|
return;
|
|
|
|
|
// TODO: Don't swipe if you touched a floating window.
|
2025-04-24 20:49:49 +02:00
|
|
|
} else if (*PSWIPETOUCH && (m_pFoundLSToFocus.expired() || m_pFoundLSToFocus->m_layer <= 1) && !g_pSessionLockManager->isSessionLocked()) {
|
2025-01-07 17:55:14 +00:00
|
|
|
const auto PWORKSPACE = PMONITOR->activeWorkspace;
|
2025-04-25 02:37:12 +02:00
|
|
|
const auto STYLE = PWORKSPACE->m_renderOffset->getStyle();
|
2025-01-07 17:55:14 +00:00
|
|
|
const bool VERTANIMS = STYLE == "slidevert" || STYLE.starts_with("slidefadevert");
|
2025-04-20 20:39:33 +02:00
|
|
|
const double TARGETLEFT = ((VERTANIMS ? gapsOut.m_top : gapsOut.m_left) + *PBORDERSIZE) / (VERTANIMS ? PMONITOR->vecSize.y : PMONITOR->vecSize.x);
|
|
|
|
|
const double TARGETRIGHT = 1 - (((VERTANIMS ? gapsOut.m_bottom : gapsOut.m_right) + *PBORDERSIZE) / (VERTANIMS ? PMONITOR->vecSize.y : PMONITOR->vecSize.x));
|
2024-05-05 22:18:10 +01:00
|
|
|
const double POSITION = (VERTANIMS ? e.pos.y : e.pos.x);
|
2024-03-17 11:43:59 -04:00
|
|
|
if (POSITION < TARGETLEFT || POSITION > TARGETRIGHT) {
|
|
|
|
|
beginWorkspaceSwipe();
|
2024-05-05 22:18:10 +01:00
|
|
|
m_sActiveSwipe.touch_id = e.touchID;
|
2024-03-17 11:43:59 -04:00
|
|
|
// Set the initial direction based on which edge you started from
|
|
|
|
|
if (POSITION > 0.5)
|
|
|
|
|
m_sActiveSwipe.initialDirection = *PSWIPEINVR ? -1 : 1;
|
|
|
|
|
else
|
|
|
|
|
m_sActiveSwipe.initialDirection = *PSWIPEINVR ? 1 : -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-25 12:44:13 -06:00
|
|
|
if (g_pSessionLockManager->isSessionLocked()) {
|
|
|
|
|
m_sTouchData.touchFocusLockSurface = g_pSessionLockManager->getSessionLockSurfaceForMonitor(PMONITOR->ID);
|
|
|
|
|
if (!m_sTouchData.touchFocusLockSurface)
|
|
|
|
|
Debug::log(WARN, "The session is locked but can't find a lock surface");
|
|
|
|
|
else
|
|
|
|
|
m_sTouchData.touchFocusSurface = m_sTouchData.touchFocusLockSurface->surface->surface();
|
|
|
|
|
} else {
|
|
|
|
|
m_sTouchData.touchFocusLockSurface.reset();
|
|
|
|
|
m_sTouchData.touchFocusWindow = m_pFoundWindowToFocus;
|
|
|
|
|
m_sTouchData.touchFocusSurface = m_pFoundSurfaceToFocus;
|
|
|
|
|
m_sTouchData.touchFocusLS = m_pFoundLSToFocus;
|
|
|
|
|
}
|
2022-08-07 21:17:03 +02:00
|
|
|
|
2022-10-14 20:46:32 +01:00
|
|
|
Vector2D local;
|
|
|
|
|
|
2025-01-25 12:44:13 -06:00
|
|
|
if (m_sTouchData.touchFocusLockSurface) {
|
|
|
|
|
local = g_pInputManager->getMouseCoordsInternal() - PMONITOR->vecPosition;
|
|
|
|
|
m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local;
|
|
|
|
|
} else if (!m_sTouchData.touchFocusWindow.expired()) {
|
2025-04-28 22:25:22 +02:00
|
|
|
if (m_sTouchData.touchFocusWindow->m_isX11) {
|
|
|
|
|
local = (g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusWindow->m_realPosition->goal()) * m_sTouchData.touchFocusWindow->m_X11SurfaceScaledBy;
|
|
|
|
|
m_sTouchData.touchSurfaceOrigin = m_sTouchData.touchFocusWindow->m_realPosition->goal();
|
2022-08-17 23:23:36 +02:00
|
|
|
} else {
|
2024-04-27 12:43:12 +01:00
|
|
|
g_pCompositor->vectorWindowToSurface(g_pInputManager->getMouseCoordsInternal(), m_sTouchData.touchFocusWindow.lock(), local);
|
2023-10-27 11:15:29 +02:00
|
|
|
m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local;
|
2022-08-17 23:23:36 +02:00
|
|
|
}
|
2024-04-30 02:41:27 +01:00
|
|
|
} else if (!m_sTouchData.touchFocusLS.expired()) {
|
2025-04-24 20:49:49 +02:00
|
|
|
local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusLS->m_geometry.pos();
|
2022-08-17 23:23:36 +02:00
|
|
|
|
2022-10-14 20:46:32 +01:00
|
|
|
m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local;
|
2024-05-05 22:18:10 +01:00
|
|
|
} else
|
2022-10-14 20:46:32 +01:00
|
|
|
return; // oops, nothing found.
|
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
g_pSeatManager->sendTouchDown(m_sTouchData.touchFocusSurface.lock(), e.timeMs, e.touchID, local);
|
2022-08-07 21:17:03 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-05 22:18:10 +01:00
|
|
|
void CInputManager::onTouchUp(ITouch::SUpEvent e) {
|
2024-07-22 13:05:06 +02:00
|
|
|
m_bLastInputTouch = true;
|
|
|
|
|
|
2023-11-13 17:32:12 +01:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("touchUp", e);
|
2024-03-17 11:43:59 -04:00
|
|
|
if (m_sActiveSwipe.pWorkspaceBegin) {
|
|
|
|
|
// If there was a swipe from this finger, end it.
|
2024-05-05 22:18:10 +01:00
|
|
|
if (e.touchID == m_sActiveSwipe.touch_id)
|
2024-03-17 11:43:59 -04:00
|
|
|
endWorkspaceSwipe();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 18:27:57 +01:00
|
|
|
if (m_sTouchData.touchFocusSurface)
|
|
|
|
|
g_pSeatManager->sendTouchUp(e.timeMs, e.touchID);
|
2022-08-07 21:17:03 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-05 22:18:10 +01:00
|
|
|
void CInputManager::onTouchMove(ITouch::SMotionEvent e) {
|
2024-07-22 13:05:06 +02:00
|
|
|
m_bLastInputTouch = true;
|
|
|
|
|
|
2023-11-13 17:32:12 +01:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("touchMove", e);
|
2024-03-17 11:43:59 -04:00
|
|
|
if (m_sActiveSwipe.pWorkspaceBegin) {
|
|
|
|
|
// Do nothing if this is using a different finger.
|
2024-05-05 22:18:10 +01:00
|
|
|
if (e.touchID != m_sActiveSwipe.touch_id)
|
2024-03-17 11:43:59 -04:00
|
|
|
return;
|
2025-01-07 17:55:14 +00:00
|
|
|
|
2025-04-25 02:37:12 +02:00
|
|
|
const auto ANIMSTYLE = m_sActiveSwipe.pWorkspaceBegin->m_renderOffset->getStyle();
|
2025-01-07 17:55:14 +00:00
|
|
|
const bool VERTANIMS = ANIMSTYLE == "slidevert" || ANIMSTYLE.starts_with("slidefadevert");
|
2024-07-21 13:59:09 +02:00
|
|
|
static auto PSWIPEINVR = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_touch_invert");
|
2024-04-26 19:11:28 +01:00
|
|
|
static auto PSWIPEDIST = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_distance");
|
|
|
|
|
const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX);
|
2024-03-17 11:43:59 -04:00
|
|
|
// Handle the workspace swipe if there is one
|
|
|
|
|
if (m_sActiveSwipe.initialDirection == -1) {
|
|
|
|
|
if (*PSWIPEINVR)
|
2024-04-26 19:11:28 +01:00
|
|
|
// go from 0 to -SWIPEDISTANCE
|
2024-05-05 22:18:10 +01:00
|
|
|
updateWorkspaceSwipe(SWIPEDISTANCE * ((VERTANIMS ? e.pos.y : e.pos.x) - 1));
|
2024-03-17 11:43:59 -04:00
|
|
|
else
|
2024-04-26 19:11:28 +01:00
|
|
|
// go from 0 to -SWIPEDISTANCE
|
2024-05-05 22:18:10 +01:00
|
|
|
updateWorkspaceSwipe(SWIPEDISTANCE * (-1 * (VERTANIMS ? e.pos.y : e.pos.x)));
|
2024-03-17 11:43:59 -04:00
|
|
|
} else if (*PSWIPEINVR)
|
2024-04-26 19:11:28 +01:00
|
|
|
// go from 0 to SWIPEDISTANCE
|
2024-05-05 22:18:10 +01:00
|
|
|
updateWorkspaceSwipe(SWIPEDISTANCE * (VERTANIMS ? e.pos.y : e.pos.x));
|
2024-03-17 11:43:59 -04:00
|
|
|
else
|
2024-04-26 19:11:28 +01:00
|
|
|
// go from 0 to SWIPEDISTANCE
|
2024-05-05 22:18:10 +01:00
|
|
|
updateWorkspaceSwipe(SWIPEDISTANCE * (1 - (VERTANIMS ? e.pos.y : e.pos.x)));
|
2024-03-17 11:43:59 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2025-01-25 12:44:13 -06:00
|
|
|
if (m_sTouchData.touchFocusLockSurface) {
|
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusLockSurface->iMonitorID);
|
|
|
|
|
g_pCompositor->warpCursorTo({PMONITOR->vecPosition.x + e.pos.x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e.pos.y * PMONITOR->vecSize.y}, true);
|
|
|
|
|
auto local = g_pInputManager->getMouseCoordsInternal() - PMONITOR->vecPosition;
|
|
|
|
|
g_pSeatManager->sendTouchMotion(e.timeMs, e.touchID, local);
|
|
|
|
|
} else if (validMapped(m_sTouchData.touchFocusWindow)) {
|
2025-04-28 22:25:22 +02:00
|
|
|
const auto PMONITOR = m_sTouchData.touchFocusWindow->m_monitor.lock();
|
2022-08-07 21:17:03 +02:00
|
|
|
|
2024-05-05 22:18:10 +01:00
|
|
|
g_pCompositor->warpCursorTo({PMONITOR->vecPosition.x + e.pos.x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e.pos.y * PMONITOR->vecSize.y}, true);
|
2022-08-17 23:23:36 +02:00
|
|
|
|
2023-10-27 11:15:29 +02:00
|
|
|
auto local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchSurfaceOrigin;
|
2025-04-28 22:25:22 +02:00
|
|
|
if (m_sTouchData.touchFocusWindow->m_isX11)
|
|
|
|
|
local = local * m_sTouchData.touchFocusWindow->m_X11SurfaceScaledBy;
|
2022-08-17 23:23:36 +02:00
|
|
|
|
2024-05-10 18:27:57 +01:00
|
|
|
g_pSeatManager->sendTouchMotion(e.timeMs, e.touchID, local);
|
2024-04-30 02:41:27 +01:00
|
|
|
} else if (!m_sTouchData.touchFocusLS.expired()) {
|
2025-04-24 20:49:49 +02:00
|
|
|
const auto PMONITOR = m_sTouchData.touchFocusLS->m_monitor.lock();
|
2022-10-14 20:46:32 +01:00
|
|
|
|
2024-05-05 22:18:10 +01:00
|
|
|
g_pCompositor->warpCursorTo({PMONITOR->vecPosition.x + e.pos.x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e.pos.y * PMONITOR->vecSize.y}, true);
|
2022-10-14 20:46:32 +01:00
|
|
|
|
|
|
|
|
const auto local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchSurfaceOrigin;
|
|
|
|
|
|
2024-05-10 18:27:57 +01:00
|
|
|
g_pSeatManager->sendTouchMotion(e.timeMs, e.touchID, local);
|
2022-08-07 21:17:03 +02:00
|
|
|
}
|
2022-09-22 21:14:02 +01:00
|
|
|
}
|