From 27552976705e416ce481ca74d377578bcbc134e0 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 3 May 2024 01:27:59 +0100 Subject: virtual-pointer: move to new impl --- src/managers/input/InputManager.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/managers/input/InputManager.cpp') diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index e3c1b463..58b5caa3 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -12,6 +12,7 @@ #include "../../protocols/SessionLock.hpp" #include "../../protocols/InputMethodV2.hpp" #include "../../protocols/VirtualKeyboard.hpp" +#include "../../protocols/VirtualPointer.hpp" CInputManager::CInputManager() { m_sListeners.setCursorShape = PROTO::cursorShape->events.setShape.registerListener([this](std::any data) { @@ -40,6 +41,8 @@ CInputManager::CInputManager() { m_sListeners.newIdleInhibitor = PROTO::idleInhibit->events.newIdleInhibitor.registerListener([this](std::any data) { this->newIdleInhibitor(data); }); m_sListeners.newVirtualKeyboard = 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)); }); } CInputManager::~CInputManager() { @@ -968,12 +971,41 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { pKeyboard->keyboard->name); } -void CInputManager::newMouse(wlr_input_device* mouse, bool virt) { +void CInputManager::newVirtualMouse(SP mouse) { + const auto PMOUSE = &m_lMice.emplace_back(); + + PMOUSE->mouse = &mouse->wlr()->base; + PMOUSE->virtualPointer = mouse; + PMOUSE->virt = true; + try { + PMOUSE->name = getNameForNewDevice(mouse->wlr()->base.name); + } catch (std::exception& e) { + Debug::log(ERR, "Mouse had no name???"); // logic error + } + + wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, &mouse->wlr()->base); + + PMOUSE->connected = true; + + setPointerConfigs(); + + PMOUSE->hyprListener_destroyMouse.initCallback(&mouse->wlr()->base.events.destroy, &Events::listener_destroyMouse, PMOUSE, "Mouse"); + + // TODO: this pointer pass sucks. + PMOUSE->listeners.destroyMouse = mouse->events.destroy.registerListener([this, PMOUSE](std::any data) { destroyMouse(PMOUSE->mouse); }); + + g_pCompositor->m_sSeat.mouse = PMOUSE; + + m_tmrLastCursorMovement.reset(); + + Debug::log(LOG, "New virtual mouse created, pointer WLR: {:x}", (uintptr_t)mouse->wlr()); +} + +void CInputManager::newMouse(wlr_input_device* mouse) { m_lMice.emplace_back(); const auto PMOUSE = &m_lMice.back(); PMOUSE->mouse = mouse; - PMOUSE->virt = virt; try { PMOUSE->name = getNameForNewDevice(mouse->name); } catch (std::exception& e) { -- cgit v1.2.3