2022-08-07 21:17:03 +02:00
|
|
|
#include "InputManager.hpp"
|
|
|
|
#include "../../Compositor.hpp"
|
2024-03-17 16:43:59 +01:00
|
|
|
#include "../../config/ConfigValue.hpp"
|
2022-08-07 21:17:03 +02:00
|
|
|
|
|
|
|
void CInputManager::onTouchDown(wlr_touch_down_event* e) {
|
2024-03-17 16:43:59 +01: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");
|
|
|
|
static auto PSWIPEINVR = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_invert");
|
2023-11-13 17:32:12 +01:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("touchDown", e);
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
auto PMONITOR = g_pCompositor->getMonitorFromName(e->touch->output_name ? e->touch->output_name : "");
|
2022-10-14 13:38:44 +02:00
|
|
|
|
|
|
|
const auto PDEVIT = std::find_if(m_lTouchDevices.begin(), m_lTouchDevices.end(), [&](const STouchDevice& other) { return other.pWlrDevice == &e->touch->base; });
|
|
|
|
|
|
|
|
if (PDEVIT != m_lTouchDevices.end() && !PDEVIT->boundOutput.empty())
|
|
|
|
PMONITOR = g_pCompositor->getMonitorFromName(PDEVIT->boundOutput);
|
|
|
|
|
2022-10-06 10:26:05 +02:00
|
|
|
PMONITOR = PMONITOR ? PMONITOR : g_pCompositor->m_pLastMonitor;
|
|
|
|
|
2022-10-28 00:44:23 +02:00
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PMONITOR->vecPosition.x + e->x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e->y * PMONITOR->vecSize.y);
|
2022-08-07 21:17:03 +02:00
|
|
|
|
|
|
|
refocus();
|
|
|
|
|
2023-02-28 20:02:30 +01:00
|
|
|
if (m_ecbClickBehavior == CLICKMODE_KILL) {
|
|
|
|
wlr_pointer_button_event e;
|
2024-03-09 17:35:35 +01:00
|
|
|
e.state = WL_POINTER_BUTTON_STATE_PRESSED;
|
2023-02-28 20:02:30 +01:00
|
|
|
g_pInputManager->processMouseDownKill(&e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-17 16:43:59 +01: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.
|
|
|
|
} else if (*PSWIPETOUCH && (!m_pFoundLSToFocus || m_pFoundLSToFocus->layer <= ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)) {
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
|
|
|
|
const bool VERTANIMS = PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" ||
|
|
|
|
PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert");
|
|
|
|
// TODO: support no_gaps_when_only?
|
|
|
|
const double TARGETLEFT = ((VERTANIMS ? gapsOut.top : gapsOut.left) + *PBORDERSIZE) / (VERTANIMS ? PMONITOR->vecSize.y : PMONITOR->vecSize.x);
|
|
|
|
const double TARGETRIGHT = 1 - (((VERTANIMS ? gapsOut.bottom : gapsOut.right) + *PBORDERSIZE) / (VERTANIMS ? PMONITOR->vecSize.y : PMONITOR->vecSize.x));
|
|
|
|
const double POSITION = (VERTANIMS ? e->y : e->x);
|
|
|
|
if (POSITION < TARGETLEFT || POSITION > TARGETRIGHT) {
|
|
|
|
beginWorkspaceSwipe();
|
|
|
|
m_sActiveSwipe.touch_id = e->touch_id;
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 11:47:39 +01:00
|
|
|
m_bLastInputTouch = true;
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_sTouchData.touchFocusWindow = m_pFoundWindowToFocus;
|
2022-10-14 21:46:32 +02:00
|
|
|
m_sTouchData.touchFocusSurface = m_pFoundSurfaceToFocus;
|
2022-12-16 18:17:31 +01:00
|
|
|
m_sTouchData.touchFocusLS = m_pFoundLSToFocus;
|
2022-08-07 21:17:03 +02:00
|
|
|
|
2022-10-14 21:46:32 +02:00
|
|
|
Vector2D local;
|
|
|
|
|
|
|
|
if (m_sTouchData.touchFocusWindow) {
|
|
|
|
if (m_sTouchData.touchFocusWindow->m_bIsX11) {
|
2024-03-02 01:35:17 +01:00
|
|
|
local = (g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusWindow->m_vRealPosition.goal()) * m_sTouchData.touchFocusWindow->m_fX11SurfaceScaledBy;
|
|
|
|
m_sTouchData.touchSurfaceOrigin = m_sTouchData.touchFocusWindow->m_vRealPosition.goal();
|
2022-08-17 23:23:36 +02:00
|
|
|
} else {
|
2022-10-14 21:46:32 +02:00
|
|
|
g_pCompositor->vectorWindowToSurface(g_pInputManager->getMouseCoordsInternal(), m_sTouchData.touchFocusWindow, local);
|
2023-10-27 11:15:29 +02:00
|
|
|
m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local;
|
2022-08-17 23:23:36 +02:00
|
|
|
}
|
2022-10-14 21:46:32 +02:00
|
|
|
} else if (m_sTouchData.touchFocusLS) {
|
2023-05-24 22:19:22 +02:00
|
|
|
local = g_pInputManager->getMouseCoordsInternal() - Vector2D(m_sTouchData.touchFocusLS->geometry.x, m_sTouchData.touchFocusLS->geometry.y);
|
2022-08-17 23:23:36 +02:00
|
|
|
|
2022-10-14 21:46:32 +02:00
|
|
|
m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local;
|
|
|
|
} else {
|
|
|
|
return; // oops, nothing found.
|
2022-08-07 21:17:03 +02:00
|
|
|
}
|
2022-10-14 21:46:32 +02:00
|
|
|
|
|
|
|
wlr_seat_touch_notify_down(g_pCompositor->m_sSeat.seat, m_sTouchData.touchFocusSurface, e->time_msec, e->touch_id, local.x, local.y);
|
2022-11-12 00:40:55 +01:00
|
|
|
|
2023-07-13 18:05:34 +02:00
|
|
|
g_pCompositor->notifyIdleActivity();
|
2022-08-07 21:17:03 +02:00
|
|
|
}
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
void CInputManager::onTouchUp(wlr_touch_up_event* e) {
|
2023-11-13 17:32:12 +01:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("touchUp", e);
|
2024-03-17 16:43:59 +01:00
|
|
|
if (m_sActiveSwipe.pWorkspaceBegin) {
|
|
|
|
// If there was a swipe from this finger, end it.
|
|
|
|
if (e->touch_id == m_sActiveSwipe.touch_id)
|
|
|
|
endWorkspaceSwipe();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-14 21:46:32 +02:00
|
|
|
if (m_sTouchData.touchFocusSurface) {
|
2022-08-07 21:17:03 +02:00
|
|
|
wlr_seat_touch_notify_up(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
void CInputManager::onTouchMove(wlr_touch_motion_event* e) {
|
2023-11-13 17:32:12 +01:00
|
|
|
EMIT_HOOK_EVENT_CANCELLABLE("touchMove", e);
|
2024-03-17 16:43:59 +01:00
|
|
|
if (m_sActiveSwipe.pWorkspaceBegin) {
|
|
|
|
// Do nothing if this is using a different finger.
|
|
|
|
if (e->touch_id != m_sActiveSwipe.touch_id)
|
|
|
|
return;
|
|
|
|
const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" ||
|
|
|
|
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert");
|
|
|
|
static auto PSWIPEINVR = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_invert");
|
|
|
|
static auto PSWIPEDIST = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_distance");
|
|
|
|
// Handle the workspace swipe if there is one
|
|
|
|
if (m_sActiveSwipe.initialDirection == -1) {
|
|
|
|
if (*PSWIPEINVR)
|
|
|
|
// go from 0 to -PSWIPEDIST
|
|
|
|
updateWorkspaceSwipe(*PSWIPEDIST * ((VERTANIMS ? e->y : e->x) - 1));
|
|
|
|
else
|
|
|
|
// go from 0 to -PSWIPEDIST
|
|
|
|
updateWorkspaceSwipe(*PSWIPEDIST * (-1 * (VERTANIMS ? e->y : e->x)));
|
|
|
|
} else if (*PSWIPEINVR)
|
|
|
|
// go from 0 to PSWIPEDIST
|
|
|
|
updateWorkspaceSwipe(*PSWIPEDIST * (VERTANIMS ? e->y : e->x));
|
|
|
|
else
|
|
|
|
// go from 0 to PSWIPEDIST
|
|
|
|
updateWorkspaceSwipe(*PSWIPEDIST * (1 - (VERTANIMS ? e->y : e->x)));
|
|
|
|
return;
|
|
|
|
}
|
2022-10-14 21:46:32 +02:00
|
|
|
if (m_sTouchData.touchFocusWindow && g_pCompositor->windowValidMapped(m_sTouchData.touchFocusWindow)) {
|
2022-08-07 21:17:03 +02:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusWindow->m_iMonitorID);
|
|
|
|
|
2023-05-24 22:19:22 +02:00
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PMONITOR->vecPosition.x + e->x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e->y * PMONITOR->vecSize.y);
|
2022-08-17 23:23:36 +02:00
|
|
|
|
2023-10-27 11:15:29 +02:00
|
|
|
auto local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchSurfaceOrigin;
|
|
|
|
if (m_sTouchData.touchFocusWindow->m_bIsX11)
|
|
|
|
local = local * m_sTouchData.touchFocusWindow->m_fX11SurfaceScaledBy;
|
2022-08-17 23:23:36 +02:00
|
|
|
|
2022-10-14 21:46:32 +02:00
|
|
|
wlr_seat_touch_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id, local.x, local.y);
|
2023-12-06 15:30:40 +01:00
|
|
|
// wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, local.x, local.y);
|
2022-10-14 21:46:32 +02:00
|
|
|
} else if (m_sTouchData.touchFocusLS) {
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusLS->monitorID);
|
|
|
|
|
2023-05-24 22:19:22 +02:00
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PMONITOR->vecPosition.x + e->x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e->y * PMONITOR->vecSize.y);
|
2022-10-14 21:46:32 +02:00
|
|
|
|
|
|
|
const auto local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchSurfaceOrigin;
|
|
|
|
|
2022-08-17 23:23:36 +02:00
|
|
|
wlr_seat_touch_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id, local.x, local.y);
|
2023-12-06 15:30:40 +01:00
|
|
|
// wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, local.x, local.y);
|
2022-08-07 21:17:03 +02:00
|
|
|
}
|
2022-09-22 22:14:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::onPointerHoldBegin(wlr_pointer_hold_begin_event* e) {
|
|
|
|
wlr_pointer_gestures_v1_send_hold_begin(g_pCompositor->m_sWLRPointerGestures, g_pCompositor->m_sSeat.seat, e->time_msec, e->fingers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::onPointerHoldEnd(wlr_pointer_hold_end_event* e) {
|
|
|
|
wlr_pointer_gestures_v1_send_hold_end(g_pCompositor->m_sWLRPointerGestures, g_pCompositor->m_sSeat.seat, e->time_msec, e->cancelled);
|
|
|
|
}
|