IME: fix crash on restarting IME (#5428)

This commit is contained in:
Sungyoon Cho 2024-04-05 01:34:04 +09:00 committed by GitHub
parent 4f3e90ad2d
commit c4b660a339
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 13 deletions

View file

@ -49,7 +49,7 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
Debug::log(LOG, "IME Destroy"); Debug::log(LOG, "IME Destroy");
if (PTI) if (PTI)
PTI->enter(PTI->focusedSurface()); PTI->leave();
}, },
this, "IMERelay"); this, "IMERelay");
@ -92,8 +92,18 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
}, },
this, "IMERelay"); this, "IMERelay");
if (const auto PTI = getFocusedTextInput(); PTI) if (!g_pCompositor->m_pLastFocus)
PTI->enter(PTI->focusedSurface()); return;
for (auto& ti : m_vTextInputs) {
if (ti->client() != wl_resource_get_client(g_pCompositor->m_pLastFocus->resource))
continue;
if (ti->isV3())
ti->enter(g_pCompositor->m_pLastFocus);
else
ti->onEnabled(g_pCompositor->m_pLastFocus);
}
} }
void CInputMethodRelay::setIMEPopupFocus(CInputPopup* pPopup, wlr_surface* pSurface) { void CInputMethodRelay::setIMEPopupFocus(CInputPopup* pPopup, wlr_surface* pSurface) {

View file

@ -37,12 +37,7 @@ void CTextInput::initCallbacks() {
hyprListener_textInputDestroy.initCallback( hyprListener_textInputDestroy.initCallback(
isV3() ? &pWlrInput->events.destroy : &pV1Input->sDestroy, isV3() ? &pWlrInput->events.destroy : &pV1Input->sDestroy,
[this](void* owner, void* data) { [this](void* owner, void* data) {
if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { if (pWlrInput && pWlrInput->current_enabled && g_pInputManager->m_sIMERelay.m_pWLRIME) {
// Debug::log(WARN, "Disabling TextInput on no IME!");
return;
}
if (pWlrInput && pWlrInput->current_enabled) {
wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME);
g_pInputManager->m_sIMERelay.commitIMEState(this); g_pInputManager->m_sIMERelay.commitIMEState(this);
@ -71,10 +66,10 @@ void CTextInput::onEnabled(wlr_surface* surfV1) {
// v1 only, map surface to PTI // v1 only, map surface to PTI
if (!isV3()) { if (!isV3()) {
wlr_surface* pSurface = surfV1; wlr_surface* pSurface = surfV1;
if (g_pCompositor->m_pLastFocus == pSurface) if (g_pCompositor->m_pLastFocus != pSurface || !pV1Input->active)
return;
enter(pSurface); enter(pSurface);
else
setFocusedSurface(pSurface);
} }
wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME); wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME);
@ -208,6 +203,9 @@ void CTextInput::leave() {
setFocusedSurface(nullptr); setFocusedSurface(nullptr);
if (!g_pInputManager->m_sIMERelay.m_pWLRIME)
return;
if (!g_pInputManager->m_sIMERelay.m_pWLRIME->active) if (!g_pInputManager->m_sIMERelay.m_pWLRIME->active)
return; return;

View file

@ -167,11 +167,13 @@ void CTextInputV1ProtocolManager::handleActivate(wl_client* client, wl_resource*
Debug::log(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)PTI); Debug::log(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)PTI);
return; return;
} }
PTI->active = true;
PTI->pTextInput->onEnabled(wlr_surface_from_resource(surface)); PTI->pTextInput->onEnabled(wlr_surface_from_resource(surface));
} }
void CTextInputV1ProtocolManager::handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat) { void CTextInputV1ProtocolManager::handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat) {
const auto PTI = tiFromResource(resource); const auto PTI = tiFromResource(resource);
PTI->active = false;
PTI->pTextInput->onDisabled(); PTI->pTextInput->onDisabled();
} }