From 2233190e6758d532d2a0377b2595335399f1d98f Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 31 Mar 2023 13:20:52 +0300 Subject: [PATCH] Update pointer and tablet focus when focused window is closed Prior to dropping Deleted, we implicitly relied on the fact that the QPointer storing the focused window will be reset to null when the window is closed so we didn't include any cleanup logic. After dropping Deleted and extending the lifetime of the original window, it's no longer the case and we have to explicitly handle closing the window otherwise kwin can encounter unexpected cases. --- src/input.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index 6d54622196..7ae82a9734 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -3337,11 +3337,21 @@ bool InputDeviceHandler::setHover(Window *window) void InputDeviceHandler::setFocus(Window *window) { - if (m_focus.window != window) { - Window *oldFocus = m_focus.window; - m_focus.window = window; - focusUpdate(oldFocus, m_focus.window); + if (m_focus.window == window) { + return; } + + Window *oldFocus = m_focus.window; + if (oldFocus) { + disconnect(oldFocus, &Window::closed, this, &InputDeviceHandler::update); + } + + m_focus.window = window; + if (window) { + connect(window, &Window::closed, this, &InputDeviceHandler::update); + } + + focusUpdate(oldFocus, window); } void InputDeviceHandler::setDecoration(Decoration::DecoratedClientImpl *decoration)