mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 12:06:00 +01:00
textinput: fix ime activation in some edge cases (#7660)
* textinput: clear ti3 state when focused surface gets destroyed * textinput: send enter to newly created ti in focus
This commit is contained in:
parent
c80457be02
commit
727f1b54cd
2 changed files with 40 additions and 19 deletions
|
@ -23,10 +23,15 @@ void CTextInput::initCallbacks() {
|
||||||
listeners.disable = INPUT->events.disable.registerListener([this](std::any p) { onDisabled(); });
|
listeners.disable = INPUT->events.disable.registerListener([this](std::any p) { onDisabled(); });
|
||||||
listeners.commit = INPUT->events.onCommit.registerListener([this](std::any p) { onCommit(); });
|
listeners.commit = INPUT->events.onCommit.registerListener([this](std::any p) { onCommit(); });
|
||||||
listeners.destroy = INPUT->events.destroy.registerListener([this](std::any p) {
|
listeners.destroy = INPUT->events.destroy.registerListener([this](std::any p) {
|
||||||
|
listeners.surfaceUnmap.reset();
|
||||||
|
listeners.surfaceDestroy.reset();
|
||||||
g_pInputManager->m_sIMERelay.removeTextInput(this);
|
g_pInputManager->m_sIMERelay.removeTextInput(this);
|
||||||
if (!g_pInputManager->m_sIMERelay.getFocusedTextInput())
|
if (!g_pInputManager->m_sIMERelay.getFocusedTextInput())
|
||||||
g_pInputManager->m_sIMERelay.deactivateIME(this);
|
g_pInputManager->m_sIMERelay.deactivateIME(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!g_pCompositor->m_pLastFocus.expired() && g_pCompositor->m_pLastFocus->client() == INPUT->client())
|
||||||
|
enter(g_pCompositor->m_pLastFocus.lock());
|
||||||
} else {
|
} else {
|
||||||
const auto INPUT = pV1Input.lock();
|
const auto INPUT = pV1Input.lock();
|
||||||
|
|
||||||
|
@ -72,15 +77,19 @@ void CTextInput::onDisabled() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!focusedSurface())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!isV3())
|
if (!isV3())
|
||||||
leave();
|
leave();
|
||||||
|
|
||||||
listeners.surfaceUnmap.reset();
|
listeners.surfaceUnmap.reset();
|
||||||
listeners.surfaceDestroy.reset();
|
listeners.surfaceDestroy.reset();
|
||||||
|
|
||||||
|
if (!focusedSurface())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto PFOCUSEDTI = g_pInputManager->m_sIMERelay.getFocusedTextInput();
|
||||||
|
if (!PFOCUSEDTI || PFOCUSEDTI != this)
|
||||||
|
return;
|
||||||
|
|
||||||
g_pInputManager->m_sIMERelay.deactivateIME(this);
|
g_pInputManager->m_sIMERelay.deactivateIME(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,12 +113,12 @@ void CTextInput::setFocusedSurface(SP<CWLSurfaceResource> pSurface) {
|
||||||
|
|
||||||
pFocusedSurface = pSurface;
|
pFocusedSurface = pSurface;
|
||||||
|
|
||||||
listeners.surfaceUnmap.reset();
|
|
||||||
listeners.surfaceDestroy.reset();
|
|
||||||
|
|
||||||
if (!pSurface)
|
if (!pSurface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
listeners.surfaceUnmap.reset();
|
||||||
|
listeners.surfaceDestroy.reset();
|
||||||
|
|
||||||
listeners.surfaceUnmap = pSurface->events.unmap.registerListener([this](std::any d) {
|
listeners.surfaceUnmap = pSurface->events.unmap.registerListener([this](std::any d) {
|
||||||
Debug::log(LOG, "Unmap TI owner1");
|
Debug::log(LOG, "Unmap TI owner1");
|
||||||
|
|
||||||
|
@ -118,6 +127,12 @@ void CTextInput::setFocusedSurface(SP<CWLSurfaceResource> pSurface) {
|
||||||
pFocusedSurface.reset();
|
pFocusedSurface.reset();
|
||||||
listeners.surfaceUnmap.reset();
|
listeners.surfaceUnmap.reset();
|
||||||
listeners.surfaceDestroy.reset();
|
listeners.surfaceDestroy.reset();
|
||||||
|
|
||||||
|
if (isV3() && !pV3Input.expired() && pV3Input->current.enabled)
|
||||||
|
pV3Input->current.enabled = false;
|
||||||
|
|
||||||
|
if (!g_pInputManager->m_sIMERelay.getFocusedTextInput())
|
||||||
|
g_pInputManager->m_sIMERelay.deactivateIME(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
listeners.surfaceDestroy = pSurface->events.destroy.registerListener([this](std::any d) {
|
listeners.surfaceDestroy = pSurface->events.destroy.registerListener([this](std::any d) {
|
||||||
|
@ -128,6 +143,12 @@ void CTextInput::setFocusedSurface(SP<CWLSurfaceResource> pSurface) {
|
||||||
pFocusedSurface.reset();
|
pFocusedSurface.reset();
|
||||||
listeners.surfaceUnmap.reset();
|
listeners.surfaceUnmap.reset();
|
||||||
listeners.surfaceDestroy.reset();
|
listeners.surfaceDestroy.reset();
|
||||||
|
|
||||||
|
if (isV3() && !pV3Input.expired() && pV3Input->current.enabled)
|
||||||
|
pV3Input->current.enabled = false;
|
||||||
|
|
||||||
|
if (!g_pInputManager->m_sIMERelay.getFocusedTextInput())
|
||||||
|
g_pInputManager->m_sIMERelay.deactivateIME(this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,10 +163,8 @@ void CTextInput::enter(SP<CWLSurfaceResource> pSurface) {
|
||||||
if (pSurface == focusedSurface())
|
if (pSurface == focusedSurface())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (focusedSurface()) {
|
if (focusedSurface())
|
||||||
leave();
|
leave();
|
||||||
setFocusedSurface(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
enterLocks++;
|
enterLocks++;
|
||||||
if (enterLocks != 1) {
|
if (enterLocks != 1) {
|
||||||
|
@ -173,11 +192,14 @@ void CTextInput::leave() {
|
||||||
enterLocks = 0;
|
enterLocks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isV3() && focusedSurface())
|
if (isV3()) {
|
||||||
pV3Input->leave(focusedSurface());
|
pV3Input->leave(focusedSurface());
|
||||||
else if (focusedSurface() && pV1Input) {
|
if (pV3Input->current.enabled) {
|
||||||
pV1Input->leave();
|
pV3Input->current.enabled = false;
|
||||||
|
onDisabled();
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
pV1Input->leave();
|
||||||
|
|
||||||
setFocusedSurface(nullptr);
|
setFocusedSurface(nullptr);
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,9 @@ CTextInputV3::CTextInputV3(SP<CZwpTextInputV3> resource_) : resource(resource_)
|
||||||
current = pending;
|
current = pending;
|
||||||
serial++;
|
serial++;
|
||||||
|
|
||||||
if (wasEnabled && !current.enabled) {
|
if (wasEnabled && !current.enabled)
|
||||||
current.reset();
|
|
||||||
events.disable.emit();
|
events.disable.emit();
|
||||||
} else if (!wasEnabled && current.enabled)
|
else if (!wasEnabled && current.enabled)
|
||||||
events.enable.emit();
|
events.enable.emit();
|
||||||
else
|
else
|
||||||
events.onCommit.emit();
|
events.onCommit.emit();
|
||||||
|
@ -53,12 +52,12 @@ CTextInputV3::CTextInputV3(SP<CZwpTextInputV3> resource_) : resource(resource_)
|
||||||
pending.box.cursorBox = {x, y, w, h};
|
pending.box.cursorBox = {x, y, w, h};
|
||||||
});
|
});
|
||||||
|
|
||||||
resource->setEnable([this](CZwpTextInputV3* r) { pending.enabled = true; });
|
resource->setEnable([this](CZwpTextInputV3* r) {
|
||||||
|
|
||||||
resource->setDisable([this](CZwpTextInputV3* r) {
|
|
||||||
pending.enabled = false;
|
|
||||||
pending.reset();
|
pending.reset();
|
||||||
|
pending.enabled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
resource->setDisable([this](CZwpTextInputV3* r) { pending.enabled = false; });
|
||||||
}
|
}
|
||||||
|
|
||||||
CTextInputV3::~CTextInputV3() {
|
CTextInputV3::~CTextInputV3() {
|
||||||
|
|
Loading…
Reference in a new issue