diff options
Diffstat (limited to 'src/managers/input/InputMethodRelay.cpp')
| -rw-r--r-- | src/managers/input/InputMethodRelay.cpp | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index ca8fff9d..dc03eb89 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -1,5 +1,6 @@ #include "InputMethodRelay.hpp" #include "InputManager.hpp" +#include "../../Compositor.hpp" CInputMethodRelay::CInputMethodRelay() { @@ -29,15 +30,17 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { Debug::log(LOG, "IME Commit"); if (PIMR->m_pWLRIME->current.preedit.text) { + Debug::log(LOG, "IME TextInput preedit"); 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) { + Debug::log(LOG, "IME TextInput commit"); 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) { + if (PIMR->m_pWLRIME->current.delete_.before_length || PIMR->m_pWLRIME->current.delete_.after_length) { + Debug::log(LOG, "IME TextInput delete"); wlr_text_input_v3_send_delete_surrounding_text(PTI->pWlrInput, PIMR->m_pWLRIME->current.delete_.before_length, PIMR->m_pWLRIME->current.delete_.after_length); } @@ -51,6 +54,9 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { hyprListener_IMEDestroy.removeCallback(); hyprListener_IMECommit.removeCallback(); + hyprListener_IMEGrab.removeCallback(); + + m_pKeyboardGrab.reset(nullptr); const auto PTI = getFocusedTextInput(); @@ -64,6 +70,38 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { }, this, "IMERelay"); + hyprListener_IMEGrab.initCallback(&m_pWLRIME->events.grab_keyboard, [&](void* owner, void* data) { + + Debug::log(LOG, "IME TextInput Keyboard Grab new"); + + m_pKeyboardGrab.reset(nullptr); + + m_pKeyboardGrab = std::make_unique<SIMEKbGrab>(); + + m_pKeyboardGrab->pKeyboard = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat); + + const auto PKBGRAB = (wlr_input_method_keyboard_grab_v2*)data; + + m_pKeyboardGrab->pWlrKbGrab = PKBGRAB; + + wlr_input_method_keyboard_grab_v2_set_keyboard(m_pKeyboardGrab->pWlrKbGrab, m_pKeyboardGrab->pKeyboard); + + m_pKeyboardGrab->hyprListener_grabDestroy.initCallback(&PKBGRAB->events.destroy, [&](void* owner, void* data) { + + m_pKeyboardGrab->hyprListener_grabDestroy.removeCallback(); + + Debug::log(LOG, "IME TextInput Keyboard Grab destroy"); + + if (m_pKeyboardGrab->pKeyboard) { + wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &m_pKeyboardGrab->pKeyboard->modifiers); + } + + m_pKeyboardGrab.reset(nullptr); + + }, m_pKeyboardGrab.get(), "IME Keyboard Grab"); + + }, this, "IMERelay"); + const auto PTI = getFocusableTextInput(); if (PTI) { @@ -72,6 +110,25 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { } } +SIMEKbGrab* CInputMethodRelay::getIMEKeyboardGrab(SKeyboard* pKeyboard) { + + if (!m_pWLRIME) + return nullptr; + + if (!m_pKeyboardGrab.get()) + return nullptr; + + const auto VIRTKB = wlr_input_device_get_virtual_keyboard(pKeyboard->keyboard); + + if (VIRTKB && (wl_resource_get_client(VIRTKB->resource) == wl_resource_get_client(m_pKeyboardGrab->pWlrKbGrab->resource))) + return nullptr; + + if (wlr_keyboard_from_input_device(pKeyboard->keyboard) != m_pKeyboardGrab->pKeyboard) + return nullptr; + + return m_pKeyboardGrab.get(); +} + STextInput* CInputMethodRelay::getFocusedTextInput() { for (auto& ti : m_lTextInputs) { if (ti.pWlrInput->focused_surface) { @@ -184,9 +241,14 @@ void CInputMethodRelay::removeTextInput(wlr_text_input_v3* pInput) { } void CInputMethodRelay::commitIMEState(wlr_text_input_v3* pInput) { - wlr_input_method_v2_send_surrounding_text(m_pWLRIME, pInput->current.surrounding.text, pInput->current.surrounding.cursor, pInput->current.surrounding.anchor); + if (pInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT) + wlr_input_method_v2_send_surrounding_text(m_pWLRIME, pInput->current.surrounding.text, pInput->current.surrounding.cursor, pInput->current.surrounding.anchor); + wlr_input_method_v2_send_text_change_cause(m_pWLRIME, pInput->current.text_change_cause); - wlr_input_method_v2_send_content_type(m_pWLRIME, pInput->current.content_type.hint, pInput->current.content_type.purpose); + + if (pInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE) + wlr_input_method_v2_send_content_type(m_pWLRIME, pInput->current.content_type.hint, pInput->current.content_type.purpose); + wlr_input_method_v2_send_done(m_pWLRIME); } |
