From d2b42e29c66fc0f6411ce64fa7e14e1b5fcc1c3f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 22 Mar 2024 18:45:24 +0000 Subject: IME: fix crashes with destroyed text-inputs ref #5189 --- src/helpers/WLClasses.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/helpers/WLClasses.cpp') diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index d46f7e40..1c14567d 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -244,3 +244,39 @@ void SKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) { xkb_keymap_unref(NEWKEYMAP); xkb_context_unref(PCONTEXT); } + +void STextInput::setFocusedSurface(wlr_surface* pSurface) { + focusedSurface = pSurface; + + hyprListener_surfaceUnmapped.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + + if (!pSurface) + return; + + hyprListener_surfaceUnmapped.initCallback( + &pSurface->events.unmap, + [this](void* owner, void* data) { + if (!focusedSurface) + return; + + focusedSurface = nullptr; + hyprListener_surfaceUnmapped.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + g_pInputManager->m_sIMERelay.removeSurfaceToPTI(this); + }, + this, "STextInput"); + + hyprListener_surfaceDestroyed.initCallback( + &pSurface->events.destroy, + [this](void* owner, void* data) { + if (!focusedSurface) + return; + + focusedSurface = nullptr; + hyprListener_surfaceUnmapped.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + g_pInputManager->m_sIMERelay.removeSurfaceToPTI(this); + }, + this, "STextInput"); +} \ No newline at end of file -- cgit v1.2.3