diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 2d875ccd..844b43be 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -185,6 +185,9 @@ void CCompositor::initAllSignals() { addWLSignal(&m_sWLRCursor->events.pinch_begin, &Events::listen_pinchBegin, m_sWLRCursor, "WLRCursor"); addWLSignal(&m_sWLRCursor->events.pinch_update, &Events::listen_pinchUpdate, m_sWLRCursor, "WLRCursor"); addWLSignal(&m_sWLRCursor->events.pinch_end, &Events::listen_pinchEnd, m_sWLRCursor, "WLRCursor"); + addWLSignal(&m_sWLRCursor->events.touch_down, &Events::listen_touchBegin, m_sWLRCursor, "WLRCursor"); + addWLSignal(&m_sWLRCursor->events.touch_up, &Events::listen_touchEnd, m_sWLRCursor, "WLRCursor"); + addWLSignal(&m_sWLRCursor->events.touch_motion, &Events::listen_touchUpdate, m_sWLRCursor, "WLRCursor"); addWLSignal(&m_sWLRBackend->events.new_input, &Events::listen_newInput, m_sWLRBackend, "Backend"); addWLSignal(&m_sSeat.seat->events.request_set_cursor, &Events::listen_requestMouse, &m_sSeat, "Seat"); addWLSignal(&m_sSeat.seat->events.request_set_selection, &Events::listen_requestSetSel, &m_sSeat, "Seat"); diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp index b29d0dbc..7ec94435 100644 --- a/src/events/Devices.cpp +++ b/src/events/Devices.cpp @@ -72,7 +72,6 @@ void Events::listener_newInput(wl_listener* listener, void* data) { break; case WLR_INPUT_DEVICE_TOUCH: Debug::log(LOG, "Attached a touch device with name %s", DEVICE->name); - Debug::log(WARN, "!!!! Hyprland does not directly support touchscreens, bugs may occur !!!!"); wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, DEVICE); break; case WLR_INPUT_DEVICE_TABLET_TOOL: @@ -195,4 +194,16 @@ void Events::listener_newVirtualKeyboard(wl_listener* listener, void* data) { const auto WLRKB = (wlr_virtual_keyboard_v1*)data; g_pInputManager->newVirtualKeyboard(&WLRKB->keyboard.base); +} + +void Events::listener_touchBegin(wl_listener* listener, void* data) { + g_pInputManager->onTouchDown((wlr_touch_down_event*)data); +} + +void Events::listener_touchEnd(wl_listener* listener, void* data) { + g_pInputManager->onTouchUp((wlr_touch_up_event*)data); +} + +void Events::listener_touchUpdate(wl_listener* listener, void* data) { + g_pInputManager->onTouchMove((wlr_touch_motion_event*)data); } \ No newline at end of file diff --git a/src/events/Events.hpp b/src/events/Events.hpp index 5cb7325c..5c4ba2d9 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -144,4 +144,9 @@ namespace Events { DYNLISTENFUNC(unmapInputPopup); DYNLISTENFUNC(commitInputPopup); DYNLISTENFUNC(destroyInputPopup); + + // Touch + LISTENER(touchBegin); + LISTENER(touchEnd); + LISTENER(touchUpdate); }; \ No newline at end of file diff --git a/src/includes.hpp b/src/includes.hpp index 2cb531bd..de21d7c7 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -97,6 +97,7 @@ extern "C" { #include #include #include +#include } #undef delete diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 640b462c..2365fb43 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -422,6 +422,8 @@ std::string CAnimationManager::styleValidInConfigVar(const std::string& config, return ""; } + minPerc; // fix warning + return ""; } diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index cb0bd722..188d288f 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -12,6 +12,10 @@ enum eClickBehaviorMode { CLICKMODE_KILL }; +struct STouchData { + CWindow* touchFocusWindow = nullptr; +}; + class CInputManager { public: @@ -44,6 +48,11 @@ public: eClickBehaviorMode getClickMode(); void processMouseRequest(wlr_seat_pointer_request_set_cursor_event*); + void onTouchDown(wlr_touch_down_event*); + void onTouchUp(wlr_touch_up_event*); + void onTouchMove(wlr_touch_motion_event*); + + STouchData m_sTouchData; // for dragging floating windows CWindow* currentlyDraggedWindow = nullptr; diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp new file mode 100644 index 00000000..0b3c8961 --- /dev/null +++ b/src/managers/input/Touch.cpp @@ -0,0 +1,38 @@ +#include "InputManager.hpp" +#include "../../Compositor.hpp" + +void CInputManager::onTouchDown(wlr_touch_down_event* e) { + + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, g_pCompositor->m_pLastMonitor->vecPosition.x + e->x * g_pCompositor->m_pLastMonitor->vecSize.x, g_pCompositor->m_pLastMonitor->vecPosition.y + e->y * g_pCompositor->m_pLastMonitor->vecSize.y); + + refocus(); + + m_sTouchData.touchFocusWindow = nullptr; + + if (g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) { + wlr_seat_touch_notify_down(g_pCompositor->m_sSeat.seat, g_pCompositor->m_pLastFocus, e->time_msec, e->touch_id, + e->x * g_pCompositor->m_pLastMonitor->vecSize.x + g_pCompositor->m_pLastMonitor->vecPosition.x - g_pCompositor->m_pLastWindow->m_vRealPosition.vec().x, + e->y * g_pCompositor->m_pLastMonitor->vecSize.y + g_pCompositor->m_pLastMonitor->vecPosition.y - g_pCompositor->m_pLastWindow->m_vRealPosition.vec().y); + + m_sTouchData.touchFocusWindow = g_pCompositor->m_pLastWindow; + } +} + +void CInputManager::onTouchUp(wlr_touch_up_event* e){ + + if (m_sTouchData.touchFocusWindow) { + wlr_seat_touch_notify_up(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id); + } +} + +void CInputManager::onTouchMove(wlr_touch_motion_event* e){ + if (g_pCompositor->windowValidMapped(m_sTouchData.touchFocusWindow)) { + const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusWindow->m_iMonitorID); + + wlr_seat_touch_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id, + e->x * PMONITOR->vecSize.x + PMONITOR->vecPosition.x - m_sTouchData.touchFocusWindow->m_vRealPosition.vec().x, + e->y * PMONITOR->vecSize.y + PMONITOR->vecPosition.y - m_sTouchData.touchFocusWindow->m_vRealPosition.vec().y); + + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PMONITOR->vecPosition.x + e->x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e->y * PMONITOR->vecSize.y); + } +} \ No newline at end of file