From 7eeee2c94e882a5df1914234df0571b221f9aa35 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 11 May 2024 17:13:20 +0100 Subject: wl-data-device: move to hyprland impl --- src/managers/PointerManager.cpp | 4 ++++ src/managers/PointerManager.hpp | 1 + src/managers/ProtocolManager.cpp | 5 ++++- src/managers/SeatManager.cpp | 38 +++++++++++++++++++++++++++++++++++++ src/managers/SeatManager.hpp | 12 ++++++++++++ src/managers/input/InputManager.cpp | 28 ++++++--------------------- src/managers/input/InputManager.hpp | 3 --- 7 files changed, 65 insertions(+), 26 deletions(-) (limited to 'src/managers') diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index 60d11e7f..6a0fb984 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -941,3 +941,7 @@ void CPointerManager::damageCursor(SP pMonitor) { return; } } + +Vector2D CPointerManager::cursorSizeLogical() { + return currentCursorImage.size / currentCursorImage.scale; +} diff --git a/src/managers/PointerManager.hpp b/src/managers/PointerManager.hpp index 71ab0fc2..b6cb0c7a 100644 --- a/src/managers/PointerManager.hpp +++ b/src/managers/PointerManager.hpp @@ -52,6 +52,7 @@ class CPointerManager { // Vector2D position(); + Vector2D cursorSizeLogical(); private: void recheckPointerPosition(); diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp index e53eb111..8167103f 100644 --- a/src/managers/ProtocolManager.cpp +++ b/src/managers/ProtocolManager.cpp @@ -28,13 +28,16 @@ #include "../protocols/Tablet.hpp" #include "../protocols/LayerShell.hpp" #include "../protocols/PresentationTime.hpp" -#include "../protocols/core/Seat.hpp" #include "../protocols/XDGShell.hpp" +#include "../protocols/core/Seat.hpp" +#include "../protocols/core/DataDevice.hpp" + CProtocolManager::CProtocolManager() { // Core PROTO::seat = std::make_unique(&wl_seat_interface, 9, "WLSeat"); + PROTO::data = std::make_unique(&wl_data_device_manager_interface, 3, "WLDataDevice"); // Extensions PROTO::tearing = std::make_unique(&wp_tearing_control_manager_v1_interface, 1, "TearingControl"); diff --git a/src/managers/SeatManager.cpp b/src/managers/SeatManager.cpp index d962dd84..76840bd3 100644 --- a/src/managers/SeatManager.cpp +++ b/src/managers/SeatManager.cpp @@ -1,5 +1,6 @@ #include "SeatManager.hpp" #include "../protocols/core/Seat.hpp" +#include "../protocols/core/DataDevice.hpp" #include "../Compositor.hpp" #include "../devices/IKeyboard.hpp" #include @@ -222,6 +223,8 @@ void CSeatManager::sendPointerMotion(uint32_t timeMs, const Vector2D& local) { p->sendMotion(timeMs, local); } + + lastLocalCoords = local; } void CSeatManager::sendPointerButton(uint32_t timeMs, uint32_t key, wl_pointer_button_state state_) { @@ -424,6 +427,28 @@ SP CSeatManager::seatResourceForClient(wl_client* client) { return PROTO::seat->seatResourceForClient(client); } +void CSeatManager::setCurrentSelection(SP source) { + if (source == selection.currentSelection) { + Debug::log(WARN, "[seat] duplicated setCurrentSelection?"); + return; + } + + selection.destroySelection.reset(); + + if (selection.currentSelection) + selection.currentSelection->cancelled(); + + if (!source) + PROTO::data->setSelection(nullptr); + + selection.currentSelection = source; + + if (source) { + selection.destroySelection = source->events.destroy.registerListener([this](std::any d) { setCurrentSelection(nullptr); }); + PROTO::data->setSelection(source); + } +} + void CSeatManager::setGrab(SP grab) { if (seatGrab) { auto oldGrab = seatGrab; @@ -441,6 +466,19 @@ void CSeatManager::setGrab(SP grab) { refocusGrab(); } +void CSeatManager::resendEnterEvents() { + wlr_surface* kb = state.keyboardFocus; + wlr_surface* pt = state.pointerFocus; + + auto last = lastLocalCoords; + + setKeyboardFocus(nullptr); + setPointerFocus(nullptr, {}); + + setKeyboardFocus(kb); + setPointerFocus(pt, last); +} + bool CSeatGrab::accepts(wlr_surface* surf) { return std::find(surfs.begin(), surfs.end(), surf) != surfs.end(); } diff --git a/src/managers/SeatManager.hpp b/src/managers/SeatManager.hpp index 16f11ffd..81ca663d 100644 --- a/src/managers/SeatManager.hpp +++ b/src/managers/SeatManager.hpp @@ -5,6 +5,7 @@ #include "../macros.hpp" #include "../helpers/signal/Signal.hpp" #include "../helpers/Vector2D.hpp" +#include "../protocols/types/DataDevice.hpp" #include constexpr size_t MAX_SERIAL_STORE_LEN = 100; @@ -72,6 +73,8 @@ class CSeatManager { void sendTouchShape(int32_t id, const Vector2D& shape); void sendTouchOrientation(int32_t id, double angle); + void resendEnterEvents(); + uint32_t nextSerial(SP seatResource); // pops the serial if it was valid, meaning it is consumed. bool serialValid(SP seatResource, uint32_t serial); @@ -103,6 +106,13 @@ class CSeatManager { CSignal setCursor; // SSetCursorEvent } events; + struct { + WP currentSelection; + CHyprSignalListener destroySelection; + } selection; + + void setCurrentSelection(SP source); + // do not write to directly, use set... WP mouse; WP keyboard; @@ -132,6 +142,8 @@ class CSeatManager { CHyprSignalListener newSeatResource; } listeners; + Vector2D lastLocalCoords; + DYNLISTENER(keyboardSurfaceDestroy); DYNLISTENER(pointerSurfaceDestroy); DYNLISTENER(touchSurfaceDestroy); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index fe19c98f..d74657d9 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -15,6 +15,7 @@ #include "../../protocols/VirtualPointer.hpp" #include "../../protocols/LayerShell.hpp" #include "../../protocols/core/Seat.hpp" +#include "../../protocols/core/DataDevice.hpp" #include "../../protocols/XDGShell.hpp" #include "../../devices/Mouse.hpp" @@ -137,7 +138,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { static auto PRESIZECURSORICON = CConfigValue("general:hover_icon_on_border"); static auto PZOOMFACTOR = CConfigValue("cursor:zoom_factor"); - const auto FOLLOWMOUSE = *PFOLLOWONDND && m_sDrag.drag ? 1 : *PFOLLOWMOUSE; + const auto FOLLOWMOUSE = *PFOLLOWONDND && PROTO::data->dndActive() ? 1 : *PFOLLOWMOUSE; m_pFoundSurfaceToFocus = nullptr; m_pFoundLSToFocus.reset(); @@ -218,10 +219,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { Debug::log(ERR, "BUG THIS: Null SURF/CONSTRAINT in mouse refocus. Ignoring constraints. {:x} {:x}", (uintptr_t)SURF, (uintptr_t)CONSTRAINT.get()); } - // update stuff - updateDragIcon(); - - if (!m_sDrag.drag && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && g_pSeatManager->state.pointerFocus) { + // if we are holding a pointer button, + // and we're not dnd-ing, don't refocus. Keep focus on last surface. + if (!PROTO::data->dndActive() && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && g_pSeatManager->state.pointerFocus && !m_bHardInput) { foundSurface = g_pSeatManager->state.pointerFocus; pFoundLayerSurface = g_pCompositor->getLayerSurfaceFromSurface(foundSurface); if (pFoundLayerSurface) { @@ -1356,22 +1356,6 @@ void CInputManager::refocus() { mouseMoveUnified(0, true); } -void CInputManager::updateDragIcon() { - if (!m_sDrag.dragIcon) - return; - - switch (m_sDrag.dragIcon->drag->grab_type) { - case WLR_DRAG_GRAB_KEYBOARD: break; - case WLR_DRAG_GRAB_KEYBOARD_POINTER: { - CBox box = {m_sDrag.pos.x - 2, m_sDrag.pos.y - 2, m_sDrag.dragIcon->surface->current.width + 4, m_sDrag.dragIcon->surface->current.height + 4}; - g_pHyprRenderer->damageBox(&box); - m_sDrag.pos = getMouseCoordsInternal(); - break; - } - default: break; - } -} - void CInputManager::unconstrainMouse() { if (g_pSeatManager->mouse.expired()) return; @@ -1665,7 +1649,7 @@ std::string CInputManager::getNameForNewDevice(std::string internalName) { void CInputManager::releaseAllMouseButtons() { const auto buttonsCopy = m_lCurrentlyHeldButtons; - if (g_pInputManager->m_sDrag.drag) + if (PROTO::data->dndActive()) return; for (auto& mb : buttonsCopy) { diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 85efecb8..f7d9ae57 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -112,7 +112,6 @@ class CInputManager { void setTouchDeviceConfigs(SP dev = nullptr); void setTabletConfigs(); - void updateDragIcon(); void updateCapabilities(); void updateKeyboardsLeds(SP); @@ -143,8 +142,6 @@ class CInputManager { // for refocus to be forced PHLWINDOWREF m_pForcedFocus; - SDrag m_sDrag; - std::vector> m_vKeyboards; std::vector> m_vPointers; std::vector> m_vTouches; -- cgit v1.2.3