@@ -254,14 +254,14 @@ void TopLevelWindowModel::connectWindow(Window *window)
255 connect(window, &Window::focusedChanged, this, [this, window](bool focused) {
255 connect(window, &Window::focusedChanged, this, [this, window](bool focused) {
256 if (window->surface()) {
256 if (window->surface()) {
257− // Condense changes to the focused window
258− // eg: Do focusedWindow=A to focusedWindow=B instead of
259− // focusedWindow=A to focusedWindow=null to focusedWindow=B
260 if (focused) {
257 if (focused) {
261− m_focusedWindowChanged = true;
258+ setFocusedWindow(window);
262− m_newlyFocusedWindow = window;
259+ m_focusedWindowCleared = false;
263 } else if (m_focusedWindow == window) {
260 } else if (m_focusedWindow == window) {
264− m_focusedWindowChanged = true;
261+ // Condense changes to the focused window
262+ // eg: Do focusedWindow=A to focusedWindow=B instead of
263+ // focusedWindow=A to focusedWindow=null to focusedWindow=B
264+ m_focusedWindowCleared = true;
266 // don't clear the focused window if you were not there in the first place
266 // don't clear the focused window if you were not there in the first place
267 // happens when a filled window gets replaced with an empty one (no surface) as the focused window.
267 // happens when a filled window gets replaced with an empty one (no surface) as the focused window.
@@ -500,10 +500,7 @@ void TopLevelWindowModel::removeAt(int index)
500 disconnect(window, 0, this, 0);
500 disconnect(window, 0, this, 0);
501 if (m_focusedWindow == window) {
501 if (m_focusedWindow == window) {
502 setFocusedWindow(nullptr);
502 setFocusedWindow(nullptr);
503− }
503+ m_focusedWindowCleared = false;
504− if (m_newlyFocusedWindow == window) {
505− m_focusedWindowChanged = false;
506− m_newlyFocusedWindow = nullptr;
508 delete window;
505 delete window;
@@ -772,12 +769,11 @@ void TopLevelWindowModel::onModificationsStarted()
773void TopLevelWindowModel::onModificationsEnded()
770void TopLevelWindowModel::onModificationsEnded()
775− if (m_focusedWindowChanged) {
772+ if (m_focusedWindowCleared) {
776− setFocusedWindow(m_newlyFocusedWindow);
773+ setFocusedWindow(nullptr);
779− m_focusedWindowChanged = false;
776+ m_focusedWindowCleared = false;
780− m_newlyFocusedWindow = nullptr;
783void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
779void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
@@ -840,6 +836,5 @@ void TopLevelWindowModel::clear()
841 m_allSurfaces.clear();
837 m_allSurfaces.clear();
842 setFocusedWindow(nullptr);
838 setFocusedWindow(nullptr);
843− m_focusedWindowChanged = false;
839+ m_focusedWindowCleared = false;
844− m_newlyFocusedWindow = nullptr;