diff options
author | vaxerski <[email protected]> | 2023-03-13 20:28:07 +0000 |
---|---|---|
committer | vaxerski <[email protected]> | 2023-03-13 20:28:07 +0000 |
commit | 94ba1713c457e11acb877df6c10b01fe4cd49252 (patch) | |
tree | 8254b41941ddd4308984a5b0f4a61175227f42e4 /src | |
parent | d3157ceb5066e699ae0074eac68c60be3b8ab39b (diff) | |
download | Hyprland-94ba1713c457e11acb877df6c10b01fe4cd49252.tar.gz Hyprland-94ba1713c457e11acb877df6c10b01fe4cd49252.zip |
fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/managers/input/InputMethodRelay.cpp | 91 | ||||
-rw-r--r-- | src/managers/input/InputMethodRelay.hpp | 3 | ||||
-rw-r--r-- | src/protocols/TextInputV1.cpp | 16 | ||||
-rw-r--r-- | src/protocols/TextInputV1.hpp | 7 |
4 files changed, 84 insertions, 33 deletions
diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index c64aad8e..bb3e3efa 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -28,20 +28,36 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { return; } - if (PIMR->m_pWLRIME->current.preedit.text) { - wlr_text_input_v3_send_preedit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.preedit.text, PIMR->m_pWLRIME->current.preedit.cursor_begin, - PIMR->m_pWLRIME->current.preedit.cursor_end); - } + if (PTI->pWlrInput) { + if (PIMR->m_pWLRIME->current.preedit.text) { + wlr_text_input_v3_send_preedit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.preedit.text, PIMR->m_pWLRIME->current.preedit.cursor_begin, + PIMR->m_pWLRIME->current.preedit.cursor_end); + } - if (PIMR->m_pWLRIME->current.commit_text) { - wlr_text_input_v3_send_commit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.commit_text); - } + if (PIMR->m_pWLRIME->current.commit_text) { + wlr_text_input_v3_send_commit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.commit_text); + } - if (PIMR->m_pWLRIME->current.delete_.before_length || PIMR->m_pWLRIME->current.delete_.after_length) { - wlr_text_input_v3_send_delete_surrounding_text(PTI->pWlrInput, PIMR->m_pWLRIME->current.delete_.before_length, PIMR->m_pWLRIME->current.delete_.after_length); - } + if (PIMR->m_pWLRIME->current.delete_.before_length || PIMR->m_pWLRIME->current.delete_.after_length) { + wlr_text_input_v3_send_delete_surrounding_text(PTI->pWlrInput, PIMR->m_pWLRIME->current.delete_.before_length, PIMR->m_pWLRIME->current.delete_.after_length); + } - wlr_text_input_v3_send_done(PTI->pWlrInput); + wlr_text_input_v3_send_done(PTI->pWlrInput); + } else { + if (PIMR->m_pWLRIME->current.preedit.text) { + zwp_text_input_v1_send_preedit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, PIMR->m_pWLRIME->current.preedit.text, + PIMR->m_pWLRIME->current.preedit.text); + } + + if (PIMR->m_pWLRIME->current.commit_text) { + zwp_text_input_v1_send_commit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, PIMR->m_pWLRIME->current.commit_text); + } + + if (PIMR->m_pWLRIME->current.delete_.before_length || PIMR->m_pWLRIME->current.delete_.after_length) { + zwp_text_input_v1_send_delete_surrounding_text(PTI->pV1Input->resourceImpl, PIMR->m_pWLRIME->current.delete_.before_length, + PIMR->m_pWLRIME->current.delete_.after_length); + } + } }, this, "IMERelay"); @@ -62,9 +78,12 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { Debug::log(LOG, "IME Destroy"); if (PTI) { - setPendingSurface(PTI, PTI->pWlrInput->focused_surface); + setPendingSurface(PTI, focusedSurface(PTI)); - wlr_text_input_v3_send_leave(PTI->pWlrInput); + if (PTI->pWlrInput) + wlr_text_input_v3_send_leave(PTI->pWlrInput); + else + zwp_text_input_v1_send_leave(PTI->pV1Input->resourceImpl); } }, this, "IMERelay"); @@ -122,11 +141,19 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { const auto PTI = getFocusableTextInput(); if (PTI) { - wlr_text_input_v3_send_enter(PTI->pWlrInput, PTI->pPendingSurface); + if (PTI->pWlrInput) + wlr_text_input_v3_send_enter(PTI->pWlrInput, PTI->pPendingSurface); + else + zwp_text_input_v1_send_enter(PTI->pV1Input->resourceImpl, PTI->pPendingSurface->resource); + setPendingSurface(PTI, nullptr); } } +wlr_surface* CInputMethodRelay::focusedSurface(STextInput* pTI) { + return pTI->pWlrInput ? pTI->pWlrInput->focused_surface : pTI->pV1Input->focusedSurface; +} + void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { if (!pPopup->pSurface->mapped) return; @@ -136,12 +163,12 @@ void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { const auto PFOCUSEDTI = getFocusedTextInput(); - if (!PFOCUSEDTI || !PFOCUSEDTI->pWlrInput->focused_surface) + if (!PFOCUSEDTI || !focusedSurface(PFOCUSEDTI)) return; - bool cursorRect = PFOCUSEDTI->pWlrInput->current.features & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE; - const auto PFOCUSEDSURFACE = PFOCUSEDTI->pWlrInput->focused_surface; - auto cursorBox = PFOCUSEDTI->pWlrInput->current.cursor_rectangle; + bool cursorRect = PFOCUSEDTI->pWlrInput ? PFOCUSEDTI->pWlrInput->current.features & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE : true; + const auto PFOCUSEDSURFACE = focusedSurface(PFOCUSEDTI); + auto cursorBox = PFOCUSEDTI->pWlrInput ? PFOCUSEDTI->pWlrInput->current.cursor_rectangle : PFOCUSEDTI->pV1Input->cursorRectangle; Vector2D parentPos; Vector2D parentSize; @@ -238,12 +265,12 @@ void CInputMethodRelay::damagePopup(SIMEPopup* pPopup) { const auto PFOCUSEDTI = getFocusedTextInput(); - if (!PFOCUSEDTI || !PFOCUSEDTI->pWlrInput->focused_surface) + if (!PFOCUSEDTI || !focusedSurface(PFOCUSEDTI)) return; Vector2D parentPos; - const auto PFOCUSEDSURFACE = PFOCUSEDTI->pWlrInput->focused_surface; + const auto PFOCUSEDSURFACE = focusedSurface(PFOCUSEDTI); if (wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)) { const auto PLS = g_pCompositor->getLayerSurfaceFromWlr(wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)); @@ -279,8 +306,9 @@ SIMEKbGrab* CInputMethodRelay::getIMEKeyboardGrab(SKeyboard* pKeyboard) { } STextInput* CInputMethodRelay::getFocusedTextInput() { + for (auto& ti : m_lTextInputs) { - if (ti.pWlrInput->focused_surface) { + if (focusedSurface(&ti)) { return &ti; } } @@ -312,7 +340,7 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput pTIV1->pTextInput = PTEXTINPUT; PTEXTINPUT->hyprListener_textInputEnable.initCallback( - &pInput->events.enable, + pInput ? &pInput->events.enable : &pTIV1->sEnable, [](void* owner, void* data) { const auto PINPUT = (STextInput*)owner; @@ -329,7 +357,7 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput PTEXTINPUT, "textInput"); PTEXTINPUT->hyprListener_textInputCommit.initCallback( - &pInput->events.commit, + pInput ? &pInput->events.commit : &pTIV1->sCommit, [](void* owner, void* data) { const auto PINPUT = (STextInput*)owner; @@ -348,7 +376,7 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput PTEXTINPUT, "textInput"); PTEXTINPUT->hyprListener_textInputDisable.initCallback( - &pInput->events.disable, + pInput ? &pInput->events.disable : &pTIV1->sDisable, [](void* owner, void* data) { const auto PINPUT = (STextInput*)owner; @@ -366,7 +394,7 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput PTEXTINPUT, "textInput"); PTEXTINPUT->hyprListener_textInputDestroy.initCallback( - &pInput->events.destroy, + pInput ? &pInput->events.destroy : &pTIV1->sDestroy, [](void* owner, void* data) { const auto PINPUT = (STextInput*)owner; @@ -434,8 +462,7 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) { if (!m_pWLRIME) return; - auto focusedSurface = [](STextInput* pTI) -> wlr_surface* { return pTI->pWlrInput ? pTI->pWlrInput->focused_surface : pTI->pV1Input->focusedSurface; }; - auto client = [](STextInput* pTI) -> wl_client* { return pTI->pWlrInput ? wl_resource_get_client(pTI->pWlrInput->resource) : pTI->pV1Input->client; }; + auto client = [](STextInput* pTI) -> wl_client* { return pTI->pWlrInput ? wl_resource_get_client(pTI->pWlrInput->resource) : pTI->pV1Input->client; }; for (auto& ti : m_lTextInputs) { if (ti.pPendingSurface) { @@ -443,7 +470,7 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) { if (pSurface != ti.pPendingSurface) setPendingSurface(&ti, nullptr); - } else if (ti.pWlrInput->focused_surface) { + } else if (focusedSurface(&ti)) { if (pSurface != focusedSurface(&ti)) { wlr_input_method_v2_send_deactivate(m_pWLRIME); @@ -451,8 +478,10 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) { if (ti.pWlrInput) wlr_text_input_v3_send_leave(ti.pWlrInput); - else + else { zwp_text_input_v1_send_leave(ti.pV1Input->resourceImpl); + ti.pV1Input->focusedSurface = nullptr; + } } else { continue; } @@ -463,8 +492,10 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) { if (m_pWLRIME) { if (ti.pWlrInput) wlr_text_input_v3_send_enter(ti.pWlrInput, pSurface); - else + else { zwp_text_input_v1_send_enter(ti.pV1Input->resourceImpl, pSurface->resource); + ti.pV1Input->focusedSurface = pSurface; + } } else { setPendingSurface(&ti, pSurface); } diff --git a/src/managers/input/InputMethodRelay.hpp b/src/managers/input/InputMethodRelay.hpp index e781298c..83332285 100644 --- a/src/managers/input/InputMethodRelay.hpp +++ b/src/managers/input/InputMethodRelay.hpp @@ -44,7 +44,8 @@ class CInputMethodRelay { DYNLISTENER(IMEGrab); DYNLISTENER(IMENewPopup); - void createNewTextInput(wlr_text_input_v3*, STextInputV1* tiv1 = nullptr); + void createNewTextInput(wlr_text_input_v3*, STextInputV1* tiv1 = nullptr); + wlr_surface* focusedSurface(STextInput* pInput); friend class CHyprRenderer; friend class CInputManager; diff --git a/src/protocols/TextInputV1.cpp b/src/protocols/TextInputV1.cpp index 0cc3108c..4da7cd4f 100644 --- a/src/protocols/TextInputV1.cpp +++ b/src/protocols/TextInputV1.cpp @@ -110,8 +110,8 @@ void CTextInputV1ProtocolManager::removeTI(STextInputV1* pTI) { if (TI == m_pClients.end()) return; - if ((*TI)->resourceImpl) - wl_resource_destroy((*TI)->resourceImpl); + // if ((*TI)->resourceImpl) + // wl_resource_destroy((*TI)->resourceImpl); std::erase_if(m_pClients, [&](const auto& other) { return other.get() == pTI; }); } @@ -124,6 +124,9 @@ STextInputV1* tiFromResource(wl_resource* resource) { static void destroyTI(wl_resource* resource) { const auto TI = tiFromResource(resource); + if (!TI) + return; + if (TI->resourceImpl) { wl_resource_set_user_data(resource, nullptr); } @@ -148,6 +151,14 @@ void CTextInputV1ProtocolManager::createTI(wl_client* client, wl_resource* resou } wl_resource_set_implementation(PTI->resourceImpl, &textInputImpl, PTI, &destroyTI); + wl_resource_set_user_data(PTI->resourceImpl, PTI); + + wl_signal_init(&PTI->sEnable); + wl_signal_init(&PTI->sDisable); + wl_signal_init(&PTI->sDestroy); + wl_signal_init(&PTI->sCommit); + + g_pInputManager->m_sIMERelay.createNewTextInput(nullptr, PTI); } void CTextInputV1ProtocolManager::handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface) { @@ -195,6 +206,7 @@ void CTextInputV1ProtocolManager::handleSetPreferredLanguage(wl_client* client, void CTextInputV1ProtocolManager::handleCommitState(wl_client* client, wl_resource* resource, uint32_t serial) { const auto PTI = tiFromResource(resource); + PTI->serial = serial; PTI->pTextInput->hyprListener_textInputCommit.emit(nullptr); } diff --git a/src/protocols/TextInputV1.hpp b/src/protocols/TextInputV1.hpp index 3b54fd5f..ef0986a2 100644 --- a/src/protocols/TextInputV1.hpp +++ b/src/protocols/TextInputV1.hpp @@ -17,6 +17,13 @@ struct STextInputV1 { STextInput* pTextInput = nullptr; + wl_signal sEnable; + wl_signal sDisable; + wl_signal sCommit; + wl_signal sDestroy; + + uint32_t serial = 0; + struct SPendingSurr { bool isPending = false; std::string text = ""; |