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) {
|
2025-05-01 23:57:11 +02:00
|
|
|
m_lastInputTouch = true;
|
2024-07-22 13:05:06 +02:00
|
|
|
|
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");
|
2025-08-14 19:44:56 +05:00
|
|
|
auto* const PGAPSOUT = sc<CCssGapData*>((PGAPSOUTDATA.ptr())->getData());
|
2024-03-17 11:43:59 -04:00
|
|
|
// 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
|
|
|
|
2025-04-30 23:45:20 +02:00
|
|
|
g_pCompositor->warpCursorTo({PMONITOR->m_position.x + e.pos.x * PMONITOR->m_size.x, PMONITOR->m_position.y + e.pos.y * PMONITOR->m_size.y}, true);
|
2022-08-07 21:17:03 +02:00
|
|
|
|
|
|
|
|
refocus();
|
|
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
if (m_clickBehavior == 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.
|
2025-05-01 23:57:11 +02:00
|
|
|
if (m_activeSwipe.pWorkspaceBegin) {
|
2024-03-17 11:43:59 -04:00
|
|
|
return;
|
|
|
|
|
// TODO: Don't swipe if you touched a floating window.
|
2025-05-01 23:57:11 +02:00
|
|
|
} else if (*PSWIPETOUCH && (m_foundLSToFocus.expired() || m_foundLSToFocus->m_layer <= 1) && !g_pSessionLockManager->isSessionLocked()) {
|
2025-04-30 23:45:20 +02:00
|
|
|
const auto PWORKSPACE = PMONITOR->m_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-30 23:45:20 +02:00
|
|
|
const double TARGETLEFT = ((VERTANIMS ? gapsOut.m_top : gapsOut.m_left) + *PBORDERSIZE) / (VERTANIMS ? PMONITOR->m_size.y : PMONITOR->m_size.x);
|
|
|
|
|
const double TARGETRIGHT = 1 - (((VERTANIMS ? gapsOut.m_bottom : gapsOut.m_right) + *PBORDERSIZE) / (VERTANIMS ? PMONITOR->m_size.y : PMONITOR->m_size.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();
|
2025-05-01 23:57:11 +02:00
|
|
|
m_activeSwipe.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)
|
2025-05-01 23:57:11 +02:00
|
|
|
m_activeSwipe.initialDirection = *PSWIPEINVR ? -1 : 1;
|
2024-03-17 11:43:59 -04:00
|
|
|
else
|
2025-05-01 23:57:11 +02:00
|
|
|
m_activeSwipe.initialDirection = *PSWIPEINVR ? 1 : -1;
|
2024-03-17 11:43:59 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-03 16:07:02 +02:00
|
|
|
// could have abovelock surface, thus only use lock if no ls found
|
|
|
|
|
if (g_pSessionLockManager->isSessionLocked() && m_foundLSToFocus.expired()) {
|
2025-05-01 23:57:11 +02:00
|
|
|
m_touchData.touchFocusLockSurface = g_pSessionLockManager->getSessionLockSurfaceForMonitor(PMONITOR->m_id);
|
|
|
|
|
if (!m_touchData.touchFocusLockSurface)
|
2025-01-25 12:44:13 -06:00
|
|
|
Debug::log(WARN, "The session is locked but can't find a lock surface");
|
|
|
|
|
else
|
2025-05-01 23:57:11 +02:00
|
|
|
m_touchData.touchFocusSurface = m_touchData.touchFocusLockSurface->surface->surface();
|
2025-01-25 12:44:13 -06:00
|
|
|
} else {
|
2025-05-01 23:57:11 +02:00
|
|
|
m_touchData.touchFocusLockSurface.reset();
|
|
|
|
|
m_touchData.touchFocusWindow = m_foundWindowToFocus;
|
|
|
|
|
m_touchData.touchFocusSurface = m_foundSurfaceToFocus;
|
|
|
|
|
m_touchData.touchFocusLS = m_foundLSToFocus;
|
2025-01-25 12:44:13 -06:00
|
|
|
}
|
2022-08-07 21:17:03 +02:00
|
|
|
|
2022-10-14 20:46:32 +01:00
|
|
|
Vector2D local;
|
|
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
if (m_touchData.touchFocusLockSurface) {
|
|
|
|
|
local = g_pInputManager->getMouseCoordsInternal() - PMONITOR->m_position;
|
|
|
|
|
m_touchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local;
|
|
|
|
|
} else if (!m_touchData.touchFocusWindow.expired()) {
|
|
|
|
|
if (m_touchData.touchFocusWindow->m_isX11) {
|
|
|
|
|
local = (g_pInputManager->getMouseCoordsInternal() - m_touchData.touchFocusWindow->m_realPosition->goal()) * m_touchData.touchFocusWindow->m_X11SurfaceScaledBy;
|
|
|
|
|
m_touchData.touchSurfaceOrigin = m_touchData.touchFocusWindow->m_realPosition->goal();
|
2022-08-17 23:23:36 +02:00
|
|
|
} else {
|
2025-05-01 23:57:11 +02:00
|
|
|
g_pCompositor->vectorWindowToSurface(g_pInputManager->getMouseCoordsInternal(), m_touchData.touchFocusWindow.lock(), local);
|
|
|
|
|
m_touchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local;
|
2022-08-17 23:23:36 +02:00
|
|
|
}
|
2025-05-01 23:57:11 +02:00
|
|
|
} else if (!m_touchData.touchFocusLS.expired()) {
|
|
|
|
|
local = g_pInputManager->getMouseCoordsInternal() - m_touchData.touchFocusLS->m_geometry.pos();
|
2022-08-17 23:23:36 +02:00
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
m_touchData.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.
|
|
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
g_pSeatManager->sendTouchDown(m_touchData.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) {
|
2025-05-01 23:57:11 +02:00
|
|
|
m_lastInputTouch = true;
|
2024-07-22 13:05:06 +02:00
|
|
|
|
2023-11-13 17:32:12 +01:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("touchUp", e);
|
2025-05-01 23:57:11 +02:00
|
|
|
if (m_activeSwipe.pWorkspaceBegin) {
|
2024-03-17 11:43:59 -04:00
|
|
|
// If there was a swipe from this finger, end it.
|
2025-05-01 23:57:11 +02:00
|
|
|
if (e.touchID == m_activeSwipe.touch_id)
|
2024-03-17 11:43:59 -04:00
|
|
|
endWorkspaceSwipe();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
if (m_touchData.touchFocusSurface)
|
2024-05-10 18:27:57 +01:00
|
|
|
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) {
|
2025-05-01 23:57:11 +02:00
|
|
|
m_lastInputTouch = true;
|
2024-07-22 13:05:06 +02:00
|
|
|
|
2023-11-13 17:32:12 +01:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("touchMove", e);
|
2025-05-01 23:57:11 +02:00
|
|
|
if (m_activeSwipe.pWorkspaceBegin) {
|
2024-03-17 11:43:59 -04:00
|
|
|
// Do nothing if this is using a different finger.
|
2025-05-01 23:57:11 +02:00
|
|
|
if (e.touchID != m_activeSwipe.touch_id)
|
2024-03-17 11:43:59 -04:00
|
|
|
return;
|
2025-01-07 17:55:14 +00:00
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
const auto ANIMSTYLE = m_activeSwipe.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");
|
2025-08-14 19:44:56 +05:00
|
|
|
const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, sc<int64_t>(1LL), sc<int64_t>(UINT32_MAX));
|
2024-03-17 11:43:59 -04:00
|
|
|
// Handle the workspace swipe if there is one
|
2025-05-01 23:57:11 +02:00
|
|
|
if (m_activeSwipe.initialDirection == -1) {
|
2024-03-17 11:43:59 -04:00
|
|
|
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-05-01 23:57:11 +02:00
|
|
|
if (m_touchData.touchFocusLockSurface) {
|
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_touchData.touchFocusLockSurface->iMonitorID);
|
2025-04-30 23:45:20 +02:00
|
|
|
g_pCompositor->warpCursorTo({PMONITOR->m_position.x + e.pos.x * PMONITOR->m_size.x, PMONITOR->m_position.y + e.pos.y * PMONITOR->m_size.y}, true);
|
|
|
|
|
auto local = g_pInputManager->getMouseCoordsInternal() - PMONITOR->m_position;
|
2025-01-25 12:44:13 -06:00
|
|
|
g_pSeatManager->sendTouchMotion(e.timeMs, e.touchID, local);
|
2025-05-01 23:57:11 +02:00
|
|
|
} else if (validMapped(m_touchData.touchFocusWindow)) {
|
|
|
|
|
const auto PMONITOR = m_touchData.touchFocusWindow->m_monitor.lock();
|
2022-08-07 21:17:03 +02:00
|
|
|
|
2025-04-30 23:45:20 +02:00
|
|
|
g_pCompositor->warpCursorTo({PMONITOR->m_position.x + e.pos.x * PMONITOR->m_size.x, PMONITOR->m_position.y + e.pos.y * PMONITOR->m_size.y}, true);
|
2022-08-17 23:23:36 +02:00
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
auto local = g_pInputManager->getMouseCoordsInternal() - m_touchData.touchSurfaceOrigin;
|
|
|
|
|
if (m_touchData.touchFocusWindow->m_isX11)
|
|
|
|
|
local = local * m_touchData.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);
|
2025-05-01 23:57:11 +02:00
|
|
|
} else if (!m_touchData.touchFocusLS.expired()) {
|
|
|
|
|
const auto PMONITOR = m_touchData.touchFocusLS->m_monitor.lock();
|
2022-10-14 20:46:32 +01:00
|
|
|
|
2025-04-30 23:45:20 +02:00
|
|
|
g_pCompositor->warpCursorTo({PMONITOR->m_position.x + e.pos.x * PMONITOR->m_size.x, PMONITOR->m_position.y + e.pos.y * PMONITOR->m_size.y}, true);
|
2022-10-14 20:46:32 +01:00
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
const auto local = g_pInputManager->getMouseCoordsInternal() - m_touchData.touchSurfaceOrigin;
|
2022-10-14 20:46:32 +01:00
|
|
|
|
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
|
|
|
}
|