From 6967a31450441fc5605c05db6f65505dace4b263 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 8 Jun 2024 10:07:59 +0200 Subject: wayland/core: move to new impl (#6268) * wayland/core/dmabuf: move to new impl it's the final countdown --- src/managers/input/TextInput.cpp | 71 +++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 38 deletions(-) (limited to 'src/managers/input/TextInput.cpp') diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index b3f0b0cb..4c7ffe6e 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -5,6 +5,7 @@ #include "../../Compositor.hpp" #include "../../protocols/TextInputV3.hpp" #include "../../protocols/InputMethodV2.hpp" +#include "../../protocols/core/Compositor.hpp" CTextInput::CTextInput(STextInputV1* ti) : pV1Input(ti) { ti->pTextInput = this; @@ -56,8 +57,8 @@ void CTextInput::initCallbacks() { hyprListener_textInputDestroy.removeCallback(); hyprListener_textInputDisable.removeCallback(); hyprListener_textInputEnable.removeCallback(); - hyprListener_surfaceDestroyed.removeCallback(); - hyprListener_surfaceUnmapped.removeCallback(); + listeners.surfaceUnmap.reset(); + listeners.surfaceDestroy.reset(); g_pInputManager->m_sIMERelay.removeTextInput(this); }, @@ -65,7 +66,7 @@ void CTextInput::initCallbacks() { } } -void CTextInput::onEnabled(wlr_surface* surfV1) { +void CTextInput::onEnabled(SP surfV1) { Debug::log(LOG, "TI ENABLE"); if (g_pInputManager->m_sIMERelay.m_pIME.expired()) { @@ -75,7 +76,7 @@ void CTextInput::onEnabled(wlr_surface* surfV1) { // v1 only, map surface to PTI if (!isV3()) { - wlr_surface* pSurface = surfV1; + SP pSurface = surfV1; if (g_pCompositor->m_pLastFocus != pSurface || !pV1Input->active) return; @@ -97,8 +98,8 @@ void CTextInput::onDisabled() { if (!isV3()) leave(); - hyprListener_surfaceDestroyed.removeCallback(); - hyprListener_surfaceUnmapped.removeCallback(); + listeners.surfaceUnmap.reset(); + listeners.surfaceDestroy.reset(); g_pInputManager->m_sIMERelay.deactivateIME(this); } @@ -117,50 +118,44 @@ void CTextInput::onCommit() { g_pInputManager->m_sIMERelay.commitIMEState(this); } -void CTextInput::setFocusedSurface(wlr_surface* pSurface) { +void CTextInput::setFocusedSurface(SP pSurface) { if (pSurface == pFocusedSurface) return; pFocusedSurface = pSurface; - hyprListener_surfaceUnmapped.removeCallback(); - hyprListener_surfaceDestroyed.removeCallback(); + listeners.surfaceUnmap.reset(); + listeners.surfaceDestroy.reset(); if (!pSurface) return; - hyprListener_surfaceUnmapped.initCallback( - &pSurface->events.unmap, - [this](void* owner, void* data) { - Debug::log(LOG, "Unmap TI owner1"); - - if (enterLocks) - enterLocks--; - pFocusedSurface = nullptr; - hyprListener_surfaceUnmapped.removeCallback(); - hyprListener_surfaceDestroyed.removeCallback(); - }, - this, "CTextInput"); - - hyprListener_surfaceDestroyed.initCallback( - &pSurface->events.destroy, - [this](void* owner, void* data) { - Debug::log(LOG, "destroy TI owner1"); - - if (enterLocks) - enterLocks--; - pFocusedSurface = nullptr; - hyprListener_surfaceUnmapped.removeCallback(); - hyprListener_surfaceDestroyed.removeCallback(); - }, - this, "CTextInput"); + listeners.surfaceUnmap = pSurface->events.unmap.registerListener([this](std::any d) { + Debug::log(LOG, "Unmap TI owner1"); + + if (enterLocks) + enterLocks--; + pFocusedSurface.reset(); + listeners.surfaceUnmap.reset(); + listeners.surfaceDestroy.reset(); + }); + + listeners.surfaceDestroy = pSurface->events.destroy.registerListener([this](std::any d) { + Debug::log(LOG, "Destroy TI owner1"); + + if (enterLocks) + enterLocks--; + pFocusedSurface.reset(); + listeners.surfaceUnmap.reset(); + listeners.surfaceDestroy.reset(); + }); } bool CTextInput::isV3() { return !pV1Input; } -void CTextInput::enter(wlr_surface* pSurface) { +void CTextInput::enter(SP pSurface) { if (!pSurface || !pSurface->mapped) return; @@ -182,7 +177,7 @@ void CTextInput::enter(wlr_surface* pSurface) { if (isV3()) pV3Input->enter(pSurface); else { - zwp_text_input_v1_send_enter(pV1Input->resourceImpl, pSurface->resource); + zwp_text_input_v1_send_enter(pV1Input->resourceImpl, pSurface->getResource()->resource()); pV1Input->active = true; } @@ -211,8 +206,8 @@ void CTextInput::leave() { g_pInputManager->m_sIMERelay.deactivateIME(this); } -wlr_surface* CTextInput::focusedSurface() { - return pFocusedSurface; +SP CTextInput::focusedSurface() { + return pFocusedSurface.lock(); } wl_client* CTextInput::client() { -- cgit v1.2.3