diff options
Diffstat (limited to 'src/managers/input/InputMethodRelay.cpp')
| -rw-r--r-- | src/managers/input/InputMethodRelay.cpp | 291 |
1 files changed, 151 insertions, 140 deletions
diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index d49623db..93c7040b 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -2,7 +2,7 @@ #include "InputManager.hpp" #include "../../Compositor.hpp" -CInputMethodRelay::CInputMethodRelay() { } +CInputMethodRelay::CInputMethodRelay() {} void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { if (m_pWLRIME) { @@ -15,101 +15,107 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { m_pWLRIME = pIME; - hyprListener_IMECommit.initCallback(&m_pWLRIME->events.commit, [&](void* owner, void* data) { + hyprListener_IMECommit.initCallback( + &m_pWLRIME->events.commit, + [&](void* owner, void* data) { + const auto PTI = getFocusedTextInput(); + const auto PIMR = (CInputMethodRelay*)owner; - const auto PTI = getFocusedTextInput(); - const auto PIMR = (CInputMethodRelay*)owner; - - if (!PTI) { - Debug::log(LOG, "No focused TextInput on IME Commit"); - 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 (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); - } - - wlr_text_input_v3_send_done(PTI->pWlrInput); - - }, this, "IMERelay"); - - hyprListener_IMEDestroy.initCallback(&m_pWLRIME->events.destroy, [&](void* owner, void* data) { - - m_pWLRIME = nullptr; - - hyprListener_IMEDestroy.removeCallback(); - hyprListener_IMECommit.removeCallback(); - hyprListener_IMEGrab.removeCallback(); - hyprListener_IMENewPopup.removeCallback(); - - m_pKeyboardGrab.reset(nullptr); + if (!PTI) { + Debug::log(LOG, "No focused TextInput on IME Commit"); + return; + } - const auto PTI = getFocusedTextInput(); + 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); + } - Debug::log(LOG, "IME Destroy"); + if (PIMR->m_pWLRIME->current.commit_text) { + wlr_text_input_v3_send_commit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.commit_text); + } - if (PTI) { - setPendingSurface(PTI, PTI->pWlrInput->focused_surface); + 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_leave(PTI->pWlrInput); - } + wlr_text_input_v3_send_done(PTI->pWlrInput); + }, + this, "IMERelay"); - }, this, "IMERelay"); + hyprListener_IMEDestroy.initCallback( + &m_pWLRIME->events.destroy, + [&](void* owner, void* data) { + m_pWLRIME = nullptr; - hyprListener_IMEGrab.initCallback(&m_pWLRIME->events.grab_keyboard, [&](void* owner, void* data) { + hyprListener_IMEDestroy.removeCallback(); + hyprListener_IMECommit.removeCallback(); + hyprListener_IMEGrab.removeCallback(); + hyprListener_IMENewPopup.removeCallback(); - Debug::log(LOG, "IME TextInput Keyboard Grab new"); + m_pKeyboardGrab.reset(nullptr); - m_pKeyboardGrab.reset(nullptr); + const auto PTI = getFocusedTextInput(); - m_pKeyboardGrab = std::make_unique<SIMEKbGrab>(); + Debug::log(LOG, "IME Destroy"); - m_pKeyboardGrab->pKeyboard = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat); + if (PTI) { + setPendingSurface(PTI, PTI->pWlrInput->focused_surface); - const auto PKBGRAB = (wlr_input_method_keyboard_grab_v2*)data; + wlr_text_input_v3_send_leave(PTI->pWlrInput); + } + }, + this, "IMERelay"); - m_pKeyboardGrab->pWlrKbGrab = PKBGRAB; + hyprListener_IMEGrab.initCallback( + &m_pWLRIME->events.grab_keyboard, + [&](void* owner, void* data) { + Debug::log(LOG, "IME TextInput Keyboard Grab new"); - wlr_input_method_keyboard_grab_v2_set_keyboard(m_pKeyboardGrab->pWlrKbGrab, m_pKeyboardGrab->pKeyboard); + m_pKeyboardGrab.reset(nullptr); - m_pKeyboardGrab->hyprListener_grabDestroy.initCallback(&PKBGRAB->events.destroy, [&](void* owner, void* data) { + m_pKeyboardGrab = std::make_unique<SIMEKbGrab>(); - m_pKeyboardGrab->hyprListener_grabDestroy.removeCallback(); + m_pKeyboardGrab->pKeyboard = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat); - Debug::log(LOG, "IME TextInput Keyboard Grab destroy"); + const auto PKBGRAB = (wlr_input_method_keyboard_grab_v2*)data; - if (m_pKeyboardGrab->pKeyboard) { - wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &m_pKeyboardGrab->pKeyboard->modifiers); - } + m_pKeyboardGrab->pWlrKbGrab = PKBGRAB; - m_pKeyboardGrab.reset(nullptr); + wlr_input_method_keyboard_grab_v2_set_keyboard(m_pKeyboardGrab->pWlrKbGrab, m_pKeyboardGrab->pKeyboard); - }, m_pKeyboardGrab.get(), "IME Keyboard Grab"); + m_pKeyboardGrab->hyprListener_grabDestroy.initCallback( + &PKBGRAB->events.destroy, + [&](void* owner, void* data) { + m_pKeyboardGrab->hyprListener_grabDestroy.removeCallback(); - }, this, "IMERelay"); + Debug::log(LOG, "IME TextInput Keyboard Grab destroy"); - hyprListener_IMENewPopup.initCallback(&m_pWLRIME->events.new_popup_surface, [&](void* owner, void* data) { + if (m_pKeyboardGrab->pKeyboard) { + wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &m_pKeyboardGrab->pKeyboard->modifiers); + } - const auto PNEWPOPUP = &m_lIMEPopups.emplace_back(); + m_pKeyboardGrab.reset(nullptr); + }, + m_pKeyboardGrab.get(), "IME Keyboard Grab"); + }, + this, "IMERelay"); - PNEWPOPUP->pSurface = (wlr_input_popup_surface_v2*)data; + hyprListener_IMENewPopup.initCallback( + &m_pWLRIME->events.new_popup_surface, + [&](void* owner, void* data) { + const auto PNEWPOPUP = &m_lIMEPopups.emplace_back(); - PNEWPOPUP->hyprListener_commitPopup.initCallback(&PNEWPOPUP->pSurface->surface->events.commit, &Events::listener_commitInputPopup, PNEWPOPUP, "IME Popup"); - PNEWPOPUP->hyprListener_mapPopup.initCallback(&PNEWPOPUP->pSurface->events.map, &Events::listener_mapInputPopup, PNEWPOPUP, "IME Popup"); - PNEWPOPUP->hyprListener_unmapPopup.initCallback(&PNEWPOPUP->pSurface->events.unmap, &Events::listener_unmapInputPopup, PNEWPOPUP, "IME Popup"); - PNEWPOPUP->hyprListener_destroyPopup.initCallback(&PNEWPOPUP->pSurface->events.destroy, &Events::listener_destroyInputPopup, PNEWPOPUP, "IME Popup"); + PNEWPOPUP->pSurface = (wlr_input_popup_surface_v2*)data; - Debug::log(LOG, "New input popup"); + PNEWPOPUP->hyprListener_commitPopup.initCallback(&PNEWPOPUP->pSurface->surface->events.commit, &Events::listener_commitInputPopup, PNEWPOPUP, "IME Popup"); + PNEWPOPUP->hyprListener_mapPopup.initCallback(&PNEWPOPUP->pSurface->events.map, &Events::listener_mapInputPopup, PNEWPOPUP, "IME Popup"); + PNEWPOPUP->hyprListener_unmapPopup.initCallback(&PNEWPOPUP->pSurface->events.unmap, &Events::listener_unmapInputPopup, PNEWPOPUP, "IME Popup"); + PNEWPOPUP->hyprListener_destroyPopup.initCallback(&PNEWPOPUP->pSurface->events.destroy, &Events::listener_destroyInputPopup, PNEWPOPUP, "IME Popup"); - }, this, "IMERelay"); + Debug::log(LOG, "New input popup"); + }, + this, "IMERelay"); const auto PTI = getFocusableTextInput(); @@ -131,25 +137,25 @@ void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { if (!PFOCUSEDTI || !PFOCUSEDTI->pWlrInput->focused_surface) return; - bool cursorRect = PFOCUSEDTI->pWlrInput->current.features & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE; + 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; + auto cursorBox = PFOCUSEDTI->pWlrInput->current.cursor_rectangle; - Vector2D parentPos; - Vector2D parentSize; + Vector2D parentPos; + Vector2D parentSize; if (wlr_surface_is_layer_surface(PFOCUSEDSURFACE)) { const auto PLS = g_pCompositor->getLayerSurfaceFromWlr(wlr_layer_surface_v1_from_wlr_surface(PFOCUSEDSURFACE)); if (PLS) { - parentPos = Vector2D(PLS->geometry.x, PLS->geometry.y) + g_pCompositor->getMonitorFromID(PLS->monitorID)->vecPosition; + parentPos = Vector2D(PLS->geometry.x, PLS->geometry.y) + g_pCompositor->getMonitorFromID(PLS->monitorID)->vecPosition; parentSize = Vector2D(PLS->geometry.width, PLS->geometry.height); } } else { const auto PWINDOW = g_pCompositor->getWindowFromSurface(PFOCUSEDSURFACE); if (PWINDOW) { - parentPos = PWINDOW->m_vRealPosition.goalv(); + parentPos = PWINDOW->m_vRealPosition.goalv(); parentSize = PWINDOW->m_vRealSize.goalv(); } } @@ -230,7 +236,7 @@ void CInputMethodRelay::damagePopup(SIMEPopup* pPopup) { if (!PFOCUSEDTI || !PFOCUSEDTI->pWlrInput->focused_surface) return; - Vector2D parentPos; + Vector2D parentPos; const auto PFOCUSEDSURFACE = PFOCUSEDTI->pWlrInput->focused_surface; @@ -296,82 +302,86 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput) { PTEXTINPUT->pWlrInput = pInput; - PTEXTINPUT->hyprListener_textInputEnable.initCallback(&pInput->events.enable, [](void* owner, void* data) { - - const auto PINPUT = (STextInput*)owner; - - if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { - // Debug::log(WARN, "Enabling TextInput on no IME!"); - return; - } - - Debug::log(LOG, "Enable TextInput"); - - wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME); - g_pInputManager->m_sIMERelay.commitIMEState(PINPUT->pWlrInput); - - }, PTEXTINPUT, "textInput"); - - PTEXTINPUT->hyprListener_textInputCommit.initCallback(&pInput->events.commit, [](void* owner, void* data) { - - const auto PINPUT = (STextInput*)owner; - - if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { - // Debug::log(WARN, "Committing TextInput on no IME!"); - return; - } + PTEXTINPUT->hyprListener_textInputEnable.initCallback( + &pInput->events.enable, + [](void* owner, void* data) { + const auto PINPUT = (STextInput*)owner; - if (!PINPUT->pWlrInput->current_enabled) { - Debug::log(WARN, "Disabled TextInput commit?"); - return; - } + if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { + // Debug::log(WARN, "Enabling TextInput on no IME!"); + return; + } - g_pInputManager->m_sIMERelay.commitIMEState(PINPUT->pWlrInput); + Debug::log(LOG, "Enable TextInput"); - }, PTEXTINPUT, "textInput"); + wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME); + g_pInputManager->m_sIMERelay.commitIMEState(PINPUT->pWlrInput); + }, + PTEXTINPUT, "textInput"); - PTEXTINPUT->hyprListener_textInputDisable.initCallback(&pInput->events.disable, [](void* owner, void* data) { + PTEXTINPUT->hyprListener_textInputCommit.initCallback( + &pInput->events.commit, + [](void* owner, void* data) { + const auto PINPUT = (STextInput*)owner; - const auto PINPUT = (STextInput*)owner; + if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { + // Debug::log(WARN, "Committing TextInput on no IME!"); + return; + } - if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { - // Debug::log(WARN, "Disabling TextInput on no IME!"); - return; - } + if (!PINPUT->pWlrInput->current_enabled) { + Debug::log(WARN, "Disabled TextInput commit?"); + return; + } - Debug::log(LOG, "Disable TextInput"); + g_pInputManager->m_sIMERelay.commitIMEState(PINPUT->pWlrInput); + }, + PTEXTINPUT, "textInput"); - wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); + PTEXTINPUT->hyprListener_textInputDisable.initCallback( + &pInput->events.disable, + [](void* owner, void* data) { + const auto PINPUT = (STextInput*)owner; - g_pInputManager->m_sIMERelay.commitIMEState(PINPUT->pWlrInput); + if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { + // Debug::log(WARN, "Disabling TextInput on no IME!"); + return; + } - }, PTEXTINPUT, "textInput"); + Debug::log(LOG, "Disable TextInput"); - PTEXTINPUT->hyprListener_textInputDestroy.initCallback(&pInput->events.destroy, [](void* owner, void* data) { + wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); - const auto PINPUT = (STextInput*)owner; + g_pInputManager->m_sIMERelay.commitIMEState(PINPUT->pWlrInput); + }, + PTEXTINPUT, "textInput"); - if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { - // Debug::log(WARN, "Disabling TextInput on no IME!"); - return; - } + PTEXTINPUT->hyprListener_textInputDestroy.initCallback( + &pInput->events.destroy, + [](void* owner, void* data) { + const auto PINPUT = (STextInput*)owner; - if (PINPUT->pWlrInput->current_enabled) { - wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); + if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { + // Debug::log(WARN, "Disabling TextInput on no IME!"); + return; + } - g_pInputManager->m_sIMERelay.commitIMEState(PINPUT->pWlrInput); - } + if (PINPUT->pWlrInput->current_enabled) { + wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); - g_pInputManager->m_sIMERelay.setPendingSurface(PINPUT, nullptr); + g_pInputManager->m_sIMERelay.commitIMEState(PINPUT->pWlrInput); + } - PINPUT->hyprListener_textInputCommit.removeCallback(); - PINPUT->hyprListener_textInputDestroy.removeCallback(); - PINPUT->hyprListener_textInputDisable.removeCallback(); - PINPUT->hyprListener_textInputEnable.removeCallback(); + g_pInputManager->m_sIMERelay.setPendingSurface(PINPUT, nullptr); - g_pInputManager->m_sIMERelay.removeTextInput(PINPUT->pWlrInput); + PINPUT->hyprListener_textInputCommit.removeCallback(); + PINPUT->hyprListener_textInputDestroy.removeCallback(); + PINPUT->hyprListener_textInputDisable.removeCallback(); + PINPUT->hyprListener_textInputEnable.removeCallback(); - }, PTEXTINPUT, "textInput"); + g_pInputManager->m_sIMERelay.removeTextInput(PINPUT->pWlrInput); + }, + PTEXTINPUT, "textInput"); } void CInputMethodRelay::removeTextInput(wlr_text_input_v3* pInput) { @@ -417,7 +427,6 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) { } else { continue; } - } if (pSurface && wl_resource_get_client(ti.pWlrInput->resource) == wl_resource_get_client(pSurface->resource)) { @@ -427,7 +436,6 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) { } else { setPendingSurface(&ti, pSurface); } - } } } @@ -436,13 +444,16 @@ void CInputMethodRelay::setPendingSurface(STextInput* pInput, wlr_surface* pSurf pInput->pPendingSurface = pSurface; if (pSurface) { - pInput->hyprListener_pendingSurfaceDestroy.initCallback(&pSurface->events.destroy, [](void* owner, void* data) { - const auto PINPUT = (STextInput*)owner; + pInput->hyprListener_pendingSurfaceDestroy.initCallback( + &pSurface->events.destroy, + [](void* owner, void* data) { + const auto PINPUT = (STextInput*)owner; - PINPUT->pPendingSurface = nullptr; + PINPUT->pPendingSurface = nullptr; - PINPUT->hyprListener_pendingSurfaceDestroy.removeCallback(); - }, pInput, "TextInput"); + PINPUT->hyprListener_pendingSurfaceDestroy.removeCallback(); + }, + pInput, "TextInput"); } else { pInput->hyprListener_pendingSurfaceDestroy.removeCallback(); } |
