From 121d3a72137d4780602cf245704615f63357ea22 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 10 May 2024 18:27:57 +0100 Subject: wl_seat: move to hyprland impl --- src/managers/input/InputManager.cpp | 134 ++++++++++++++++-------------------- src/managers/input/InputManager.hpp | 4 +- src/managers/input/Tablets.cpp | 5 +- src/managers/input/Touch.cpp | 14 ++-- 4 files changed, 71 insertions(+), 86 deletions(-) (limited to 'src/managers/input') diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 958fb255..62d9e687 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -14,6 +14,7 @@ #include "../../protocols/VirtualKeyboard.hpp" #include "../../protocols/VirtualPointer.hpp" #include "../../protocols/LayerShell.hpp" +#include "../../protocols/core/Seat.hpp" #include "../../devices/Mouse.hpp" #include "../../devices/VirtualPointer.hpp" @@ -22,6 +23,7 @@ #include "../../devices/TouchDevice.hpp" #include "../../managers/PointerManager.hpp" +#include "../../managers/SeatManager.hpp" CInputManager::CInputManager() { m_sListeners.setCursorShape = PROTO::cursorShape->events.setShape.registerListener([this](std::any data) { @@ -30,10 +32,10 @@ CInputManager::CInputManager() { auto event = std::any_cast(data); - if (!g_pCompositor->m_sSeat.seat->pointer_state.focused_client) + if (!g_pSeatManager->state.pointerFocusResource) return; - if (wl_resource_get_client(event.pMgr->resource()) != g_pCompositor->m_sSeat.seat->pointer_state.focused_client->client) + if (wl_resource_get_client(event.pMgr->resource()) != g_pSeatManager->state.pointerFocusResource->client()) return; Debug::log(LOG, "cursorImage request: shape {} -> {}", (uint32_t)event.shape, event.shapeName); @@ -52,6 +54,7 @@ CInputManager::CInputManager() { PROTO::virtualKeyboard->events.newKeyboard.registerListener([this](std::any data) { this->newVirtualKeyboard(std::any_cast>(data)); }); m_sListeners.newVirtualMouse = PROTO::virtualPointer->events.newPointer.registerListener([this](std::any data) { this->newVirtualMouse(std::any_cast>(data)); }); + m_sListeners.setCursor = g_pSeatManager->events.setCursor.registerListener([this](std::any d) { this->processMouseRequest(d); }); } CInputManager::~CInputManager() { @@ -119,8 +122,7 @@ void CInputManager::sendMotionEventsToFocused() { m_bEmptyFocusCursorSet = false; - wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, g_pCompositor->m_pLastFocus, LOCAL.x, LOCAL.y); - wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, now.tv_sec * 1000 + now.tv_nsec / 10000000, LOCAL.x, LOCAL.y); + g_pSeatManager->setPointerFocus(g_pCompositor->m_pLastFocus, LOCAL); } void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { @@ -190,7 +192,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { } // constraints - if (!g_pCompositor->m_sSeat.mouse.expired() && isConstrained()) { + if (!g_pSeatManager->mouse.expired() && isConstrained()) { const auto SURF = CWLSurface::surfaceFromWlr(g_pCompositor->m_pLastFocus); const auto CONSTRAINT = SURF->constraint(); @@ -205,7 +207,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { const auto CLOSESTLOCAL = (CLOSEST - (BOX.has_value() ? BOX->pos() : Vector2D{})) * (SURF->getWindow() ? SURF->getWindow()->m_fX11SurfaceScaledBy : 1.0); g_pCompositor->warpCursorTo(CLOSEST, true); - wlr_seat_pointer_send_motion(g_pCompositor->m_sSeat.seat, time, CLOSESTLOCAL.x, CLOSESTLOCAL.y); + g_pSeatManager->sendPointerMotion(time, CLOSESTLOCAL); PROTO::relativePointer->sendRelativeMotion((uint64_t)time * 1000, {}, {}); } @@ -218,8 +220,8 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { // update stuff updateDragIcon(); - if (!m_sDrag.drag && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && m_pLastMouseSurface) { - foundSurface = m_pLastMouseSurface; + if (!m_sDrag.drag && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && g_pSeatManager->state.pointerFocus) { + foundSurface = g_pSeatManager->state.pointerFocus; pFoundLayerSurface = g_pCompositor->getLayerSurfaceFromSurface(foundSurface); if (pFoundLayerSurface) { surfacePos = pFoundLayerSurface->position; @@ -232,7 +234,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { m_bFocusHeldByButtons = true; m_bRefocusHeldByButtons = refocus; } else if (!g_pCompositor->m_pLastWindow.expired()) { - foundSurface = m_pLastMouseSurface; + foundSurface = g_pSeatManager->state.pointerFocus; pFoundWindow = g_pCompositor->m_pLastWindow.lock(); surfaceCoords = g_pCompositor->vectorToSurfaceLocal(mouseCoords, pFoundWindow, foundSurface); @@ -371,8 +373,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { m_bEmptyFocusCursorSet = true; } - wlr_seat_pointer_clear_focus(g_pCompositor->m_sSeat.seat); - m_pLastMouseSurface = nullptr; + g_pSeatManager->setPointerFocus(nullptr, {}); if (refocus || g_pCompositor->m_pLastWindow.expired()) // if we are forcing a refocus, and we don't find a surface, clear the kb focus too! g_pCompositor->focusWindow(nullptr); @@ -412,8 +413,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { } if (currentlyDraggedWindow.lock() && pFoundWindow != currentlyDraggedWindow) { - wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); - wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); + g_pSeatManager->setPointerFocus(foundSurface, surfaceLocal); return; } @@ -441,20 +441,15 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { // enter if change floating style if (FOLLOWMOUSE != 3 && allowKeyboardRefocus) g_pCompositor->focusWindow(pFoundWindow, foundSurface); - m_pLastMouseSurface = foundSurface; - wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); - } else if (FOLLOWMOUSE == 2 || FOLLOWMOUSE == 3) { - m_pLastMouseSurface = foundSurface; - wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); - } + g_pSeatManager->setPointerFocus(foundSurface, surfaceLocal); + } else if (FOLLOWMOUSE == 2 || FOLLOWMOUSE == 3) + g_pSeatManager->setPointerFocus(foundSurface, surfaceLocal); - if (pFoundWindow == g_pCompositor->m_pLastWindow) { - m_pLastMouseSurface = foundSurface; - wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); - } + if (pFoundWindow == g_pCompositor->m_pLastWindow) + g_pSeatManager->setPointerFocus(foundSurface, surfaceLocal); if (FOLLOWMOUSE != 0 || pFoundWindow == g_pCompositor->m_pLastWindow) - wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); + g_pSeatManager->setPointerFocus(foundSurface, surfaceLocal); m_bLastFocusOnLS = false; return; // don't enter any new surfaces @@ -489,9 +484,8 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { m_bLastFocusOnLS = true; } - m_pLastMouseSurface = foundSurface; - wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); - wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); + g_pSeatManager->setPointerFocus(foundSurface, surfaceLocal); + g_pSeatManager->sendPointerMotion(time, surfaceLocal); } void CInputManager::onMouseButton(IPointer::SButtonEvent e) { @@ -526,34 +520,33 @@ void CInputManager::onMouseButton(IPointer::SButtonEvent e) { } } -void CInputManager::processMouseRequest(wlr_seat_pointer_request_set_cursor_event* e) { +void CInputManager::processMouseRequest(std::any E) { if (!cursorImageUnlocked()) return; - Debug::log(LOG, "cursorImage request: surface {:x}", (uintptr_t)e->surface); + auto e = std::any_cast(E); - if (e->seat_client == g_pCompositor->m_sSeat.seat->pointer_state.focused_client) { + Debug::log(LOG, "cursorImage request: surface {:x}", (uintptr_t)e.surf); - if (e->surface != m_sCursorSurfaceInfo.wlSurface.wlr()) { - m_sCursorSurfaceInfo.wlSurface.unassign(); + if (e.surf != m_sCursorSurfaceInfo.wlSurface.wlr()) { + m_sCursorSurfaceInfo.wlSurface.unassign(); - if (e->surface) - m_sCursorSurfaceInfo.wlSurface.assign(e->surface); - } + if (e.surf) + m_sCursorSurfaceInfo.wlSurface.assign(e.surf); + } - if (e->surface) { - m_sCursorSurfaceInfo.vHotspot = {e->hotspot_x, e->hotspot_y}; - m_sCursorSurfaceInfo.hidden = false; - } else { - m_sCursorSurfaceInfo.vHotspot = {}; - m_sCursorSurfaceInfo.hidden = true; - } + if (e.surf) { + m_sCursorSurfaceInfo.vHotspot = e.hotspot; + m_sCursorSurfaceInfo.hidden = false; + } else { + m_sCursorSurfaceInfo.vHotspot = {}; + m_sCursorSurfaceInfo.hidden = true; + } - m_sCursorSurfaceInfo.name = ""; + m_sCursorSurfaceInfo.name = ""; - m_sCursorSurfaceInfo.inUse = true; - g_pHyprRenderer->setCursorSurface(&m_sCursorSurfaceInfo.wlSurface, e->hotspot_x, e->hotspot_y); - } + m_sCursorSurfaceInfo.inUse = true; + g_pHyprRenderer->setCursorSurface(&m_sCursorSurfaceInfo.wlSurface, e.hotspot.x, e.hotspot.y); } void CInputManager::restoreCursorIconToApp() { @@ -659,7 +652,7 @@ void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e) { if (*PFOLLOWMOUSE == 3) // don't refocus on full loose break; - if ((g_pCompositor->m_sSeat.mouse.expired() || !isConstrained()) /* No constraints */ + if ((g_pSeatManager->mouse.expired() || !isConstrained()) /* No constraints */ && (w && g_pCompositor->m_pLastWindow.lock() != w) /* window should change */) { // a bit hacky // if we only pressed one button, allow us to refocus. m_lCurrentlyHeldButtons.size() > 0 will stick the focus @@ -681,8 +674,7 @@ void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e) { } // notify app if we didnt handle it - if (g_pCompositor->doesSeatAcceptInput(g_pCompositor->m_pLastFocus)) - wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, e.timeMs, e.button, e.state); + g_pSeatManager->sendPointerButton(e.timeMs, e.button, e.state); if (const auto PMON = g_pCompositor->getMonitorFromVector(mouseCoords); PMON != g_pCompositor->m_pLastMonitor.get() && PMON) g_pCompositor->setActiveMonitor(PMON); @@ -747,14 +739,13 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) { if (*POFFWINDOWAXIS == 3) g_pCompositor->warpCursorTo({TEMPCURX, TEMPCURY}, true); - wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, e.timeMs, TEMPCURX - BOX.x, TEMPCURY - BOX.y); - wlr_seat_pointer_notify_frame(g_pCompositor->m_sSeat.seat); + g_pSeatManager->sendPointerMotion(e.timeMs, Vector2D{TEMPCURX, TEMPCURY} - BOX.pos()); + g_pSeatManager->sendPointerFrame(); } } } - wlr_seat_pointer_notify_axis(g_pCompositor->m_sSeat.seat, e.timeMs, e.axis, factor * e.delta, std::round(factor * e.deltaDiscrete), e.source, - WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL); + g_pSeatManager->sendPointerAxis(e.timeMs, e.axis, factor * e.delta, std::round(factor * e.deltaDiscrete), e.source, WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL); } Vector2D CInputManager::getMouseCoordsInternal() { @@ -826,13 +817,9 @@ void CInputManager::setupKeyboard(SP keeb) { disableAllKeyboards(false); - g_pCompositor->m_sSeat.keyboard = keeb; - - keeb->active = true; - applyConfigToKeyboard(keeb); - wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, keeb->wlr()); + g_pSeatManager->setKeyboard(keeb); } void CInputManager::setKeyboardLayout() { @@ -1015,7 +1002,7 @@ void CInputManager::setupMouse(SP mauz) { }, mauz.get()); - g_pCompositor->m_sSeat.mouse = mauz; + g_pSeatManager->setMouse(mauz); m_tmrLastCursorMovement.reset(); } @@ -1185,12 +1172,11 @@ void CInputManager::destroyKeyboard(SP pKeyboard) { std::erase_if(m_vKeyboards, [pKeyboard](const auto& other) { return other == pKeyboard; }); if (m_vKeyboards.size() > 0) { - g_pCompositor->m_sSeat.keyboard = m_vKeyboards.back(); - g_pCompositor->m_sSeat.keyboard->active = true; - wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, g_pCompositor->m_sSeat.keyboard->wlr()); + const auto PNEWKEYBOARD = m_vKeyboards.back(); + g_pSeatManager->setKeyboard(PNEWKEYBOARD); + PNEWKEYBOARD->active = true; } else { - g_pCompositor->m_sSeat.keyboard.reset(); - wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, nullptr); + g_pSeatManager->setKeyboard(nullptr); } removeFromHIDs(pKeyboard); @@ -1199,9 +1185,9 @@ void CInputManager::destroyKeyboard(SP pKeyboard) { void CInputManager::destroyPointer(SP mouse) { std::erase_if(m_vPointers, [mouse](const auto& other) { return other == mouse; }); - g_pCompositor->m_sSeat.mouse = m_vPointers.size() > 0 ? m_vPointers.front() : nullptr; + g_pSeatManager->setMouse(m_vPointers.size() > 0 ? m_vPointers.front() : nullptr); - if (!g_pCompositor->m_sSeat.mouse.expired()) + if (!g_pSeatManager->mouse.expired()) unconstrainMouse(); removeFromHIDs(mouse); @@ -1287,8 +1273,8 @@ void CInputManager::onKeyboardKey(std::any event, SP pKeyboard) { IME->setKeyboard(pKeyboard->wlr()); IME->sendKey(e.timeMs, e.keycode, e.state); } else { - wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, pKeyboard->wlr()); - wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, e.timeMs, e.keycode, e.state); + g_pSeatManager->setKeyboard(pKeyboard); + g_pSeatManager->sendKeyboardKey(e.timeMs, e.keycode, e.state); } updateKeyboardsLeds(pKeyboard); @@ -1313,8 +1299,8 @@ void CInputManager::onKeyboardMod(SP pKeyboard) { IME->setKeyboard(PWLRKB); IME->sendMods(MODS.depressed, MODS.latched, MODS.locked, MODS.group); } else { - wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, PWLRKB); - wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &MODS); + g_pSeatManager->setKeyboard(pKeyboard); + g_pSeatManager->sendKeyboardMods(MODS.depressed, MODS.latched, MODS.locked, MODS.group); } updateKeyboardsLeds(pKeyboard); @@ -1361,7 +1347,7 @@ void CInputManager::updateDragIcon() { } void CInputManager::unconstrainMouse() { - if (g_pCompositor->m_sSeat.mouse.expired()) + if (g_pSeatManager->mouse.expired()) return; for (auto& c : m_vConstraints) { @@ -1410,7 +1396,7 @@ void CInputManager::updateCapabilities() { caps |= WL_SEAT_CAPABILITY_TOUCH; } - wlr_seat_set_capabilities(g_pCompositor->m_sSeat.seat, caps); + g_pSeatManager->updateCapabilities(caps); m_uiCapabilities = caps; } @@ -1422,7 +1408,7 @@ uint32_t CInputManager::accumulateModsFromAllKBs() { if (kb->isVirtual() && shouldIgnoreVirtualKeyboard(kb)) continue; - if (!kb->enabled) + if (!kb->enabled || !kb->wlr()) continue; finalMask |= wlr_keyboard_get_modifiers(kb->wlr()); @@ -1657,7 +1643,7 @@ void CInputManager::releaseAllMouseButtons() { return; for (auto& mb : buttonsCopy) { - wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, 0, mb, WL_POINTER_BUTTON_STATE_RELEASED); + g_pSeatManager->sendPointerButton(0, mb, WL_POINTER_BUTTON_STATE_RELEASED); } m_lCurrentlyHeldButtons.clear(); diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index df36b975..42c9d3da 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -118,7 +118,7 @@ class CInputManager { void setClickMode(eClickBehaviorMode); eClickBehaviorMode getClickMode(); - void processMouseRequest(wlr_seat_pointer_request_set_cursor_event* e); + void processMouseRequest(std::any e); void onTouchDown(ITouch::SDownEvent); void onTouchUp(ITouch::SUpEvent); @@ -197,7 +197,6 @@ class CInputManager { // for tracking mouse refocus PHLWINDOWREF m_pLastMouseFocus; - wlr_surface* m_pLastMouseSurface = nullptr; // bool m_bEmptyFocusCursorSet = false; @@ -209,6 +208,7 @@ class CInputManager { CHyprSignalListener newIdleInhibitor; CHyprSignalListener newVirtualKeyboard; CHyprSignalListener newVirtualMouse; + CHyprSignalListener setCursor; } m_sListeners; bool m_bCursorImageOverridden = false; diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index cf666ec6..56e817ec 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -4,6 +4,7 @@ #include "../../protocols/Tablet.hpp" #include "../../devices/Tablet.hpp" #include "../../managers/PointerManager.hpp" +#include "../../managers/SeatManager.hpp" #include "../../protocols/PointerConstraints.hpp" static void unfocusTool(SP tool) { @@ -36,7 +37,7 @@ static void focusTool(SP tool, SP tablet, wlr_surface* sur } static void refocusTablet(SP tab, SP tool, bool motion = false) { - const auto LASTHLSURFACE = CWLSurface::surfaceFromWlr(g_pInputManager->m_pLastMouseSurface); + const auto LASTHLSURFACE = CWLSurface::surfaceFromWlr(g_pSeatManager->state.pointerFocus); if (!LASTHLSURFACE || !tool->active) { if (tool->getSurface()) @@ -56,7 +57,7 @@ static void refocusTablet(SP tab, SP tool, bool motion = f const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal(); - focusTool(tool, tab, g_pInputManager->m_pLastMouseSurface); + focusTool(tool, tab, g_pSeatManager->state.pointerFocus); if (!motion) return; diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index 4a6484c2..7748813b 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -3,6 +3,7 @@ #include "../../config/ConfigValue.hpp" #include "../../protocols/IdleNotify.hpp" #include "../../devices/ITouch.hpp" +#include "../SeatManager.hpp" void CInputManager::onTouchDown(ITouch::SDownEvent e) { static auto PSWIPETOUCH = CConfigValue("gestures:workspace_swipe_touch"); @@ -76,7 +77,7 @@ void CInputManager::onTouchDown(ITouch::SDownEvent e) { } else return; // oops, nothing found. - wlr_seat_touch_notify_down(g_pCompositor->m_sSeat.seat, m_sTouchData.touchFocusSurface, e.timeMs, e.touchID, local.x, local.y); + g_pSeatManager->sendTouchDown(m_sTouchData.touchFocusSurface, e.timeMs, e.touchID, local); PROTO::idle->onActivity(); } @@ -90,9 +91,8 @@ void CInputManager::onTouchUp(ITouch::SUpEvent e) { return; } - if (m_sTouchData.touchFocusSurface) { - wlr_seat_touch_notify_up(g_pCompositor->m_sSeat.seat, e.timeMs, e.touchID); - } + if (m_sTouchData.touchFocusSurface) + g_pSeatManager->sendTouchUp(e.timeMs, e.touchID); } void CInputManager::onTouchMove(ITouch::SMotionEvent e) { @@ -131,8 +131,7 @@ void CInputManager::onTouchMove(ITouch::SMotionEvent e) { if (m_sTouchData.touchFocusWindow->m_bIsX11) local = local * m_sTouchData.touchFocusWindow->m_fX11SurfaceScaledBy; - wlr_seat_touch_notify_motion(g_pCompositor->m_sSeat.seat, e.timeMs, e.touchID, local.x, local.y); - // wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, local.x, local.y); + g_pSeatManager->sendTouchMotion(e.timeMs, e.touchID, local); } else if (!m_sTouchData.touchFocusLS.expired()) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusLS->monitorID); @@ -140,7 +139,6 @@ void CInputManager::onTouchMove(ITouch::SMotionEvent e) { const auto local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchSurfaceOrigin; - wlr_seat_touch_notify_motion(g_pCompositor->m_sSeat.seat, e.timeMs, e.touchID, local.x, local.y); - // wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, local.x, local.y); + g_pSeatManager->sendTouchMotion(e.timeMs, e.touchID, local); } } -- cgit v1.2.3