Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IME: fix crash and auto enter #5428

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/managers/input/InputMethodRelay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
Debug::log(LOG, "IME Destroy");

if (PTI)
PTI->enter(PTI->focusedSurface());
PTI->leave();
},
this, "IMERelay");

Expand Down Expand Up @@ -92,8 +92,18 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
},
this, "IMERelay");

if (const auto PTI = getFocusedTextInput(); PTI)
PTI->enter(PTI->focusedSurface());
if (!g_pCompositor->m_pLastFocus)
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) {
Expand Down
18 changes: 8 additions & 10 deletions src/managers/input/TextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ void CTextInput::initCallbacks() {
hyprListener_textInputDestroy.initCallback(
isV3() ? &pWlrInput->events.destroy : &pV1Input->sDestroy,
[this](void* owner, void* data) {
if (!g_pInputManager->m_sIMERelay.m_pWLRIME) {
// Debug::log(WARN, "Disabling TextInput on no IME!");
return;
}

if (pWlrInput && pWlrInput->current_enabled) {
if (pWlrInput && pWlrInput->current_enabled && g_pInputManager->m_sIMERelay.m_pWLRIME) {
wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME);

g_pInputManager->m_sIMERelay.commitIMEState(this);
Expand Down Expand Up @@ -71,10 +66,10 @@ void CTextInput::onEnabled(wlr_surface* surfV1) {
// v1 only, map surface to PTI
if (!isV3()) {
wlr_surface* pSurface = surfV1;
if (g_pCompositor->m_pLastFocus == pSurface)
enter(pSurface);
else
setFocusedSurface(pSurface);
if (g_pCompositor->m_pLastFocus != pSurface || !pV1Input->active)
return;

enter(pSurface);
}

wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME);
Expand Down Expand Up @@ -208,6 +203,9 @@ void CTextInput::leave() {

setFocusedSurface(nullptr);

if (!g_pInputManager->m_sIMERelay.m_pWLRIME)
return;

if (!g_pInputManager->m_sIMERelay.m_pWLRIME->active)
return;

Expand Down
2 changes: 2 additions & 0 deletions src/protocols/TextInputV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
return;
}
PTI->active = true;
PTI->pTextInput->onEnabled(wlr_surface_from_resource(surface));
}

void CTextInputV1ProtocolManager::handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat) {
const auto PTI = tiFromResource(resource);
PTI->active = false;
PTI->pTextInput->onDisabled();
}

Expand Down