on 7fb1979 help sign in
unity8/plugins/WindowManager/TopLevelWindowModel.cpp
799 lines 25 kB history raw
1/*
2 * Copyright (C) 2016-2017 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "TopLevelWindowModel.h"
19// unity-api
20#include <unity/shell/application/ApplicationInfoInterface.h>
21#include <unity/shell/application/ApplicationManagerInterface.h>
22#include <unity/shell/application/MirSurfaceInterface.h>
23#include <unity/shell/application/MirSurfaceListInterface.h>
24#include <unity/shell/application/SurfaceManagerInterface.h>
26// Qt
27#include <QGuiApplication>
28#include <QDebug>
30// local
31#include "Window.h"
33Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel", QtInfoMsg)
35#define DEBUG_MSG qCDebug(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
36#define INFO_MSG qCInfo(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
38namespace unityapi = unity::shell::application;
40TopLevelWindowModel::TopLevelWindowModel()
41 : m_nullWindow(createWindow(nullptr)),
42 m_surfaceManagerBusy(false)
44 connect(m_nullWindow, &Window::focusedChanged, this, [this] {
45 Q_EMIT rootFocusChanged();
46 });
49void TopLevelWindowModel::setApplicationManager(unityapi::ApplicationManagerInterface* value)
51 if (m_applicationManager == value) {
52 return;
53 }
55 DEBUG_MSG << "(" << value << ")";
57 Q_ASSERT(m_modelState == IdleState);
58 m_modelState = ResettingState;
60 beginResetModel();
62 if (m_applicationManager) {
63 m_windowModel.clear();
64 disconnect(m_applicationManager, 0, this, 0);
65 }
67 m_applicationManager = value;
69 if (m_applicationManager) {
70 connect(m_applicationManager, &QAbstractItemModel::rowsInserted,
71 this, [this](const QModelIndex &/*parent*/, int first, int last) {
72 for (int i = first; i <= last; ++i) {
73 auto application = m_applicationManager->get(i);
74 addApplication(application);
75 }
76 });
78 connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved,
79 this, [this](const QModelIndex &/*parent*/, int first, int last) {
80 for (int i = first; i <= last; ++i) {
81 auto application = m_applicationManager->get(i);
82 removeApplication(application);
83 }
84 });
86 for (int i = 0; i < m_applicationManager->rowCount(); ++i) {
87 auto application = m_applicationManager->get(i);
88 addApplication(application);
89 }
90 }
92 endResetModel();
93 m_modelState = IdleState;
96void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *surfaceManager)
98 if (surfaceManager == m_surfaceManager) {
99 return;
100 }
102 DEBUG_MSG << "(" << surfaceManager << ")";
104 if (m_surfaceManager) {
105 disconnect(m_surfaceManager, 0, this, 0);
106 }
108 m_surfaceManager = surfaceManager;
110 if (m_surfaceManager) {
111 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfaceCreated, this, &TopLevelWindowModel::onSurfaceCreated);
112 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
113 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
114 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
115 }
117 Q_EMIT surfaceManagerChanged(m_surfaceManager);
120void TopLevelWindowModel::addApplication(unityapi::ApplicationInfoInterface *application)
122 DEBUG_MSG << "(" << application->appId() << ")";
124 if (application->state() != unityapi::ApplicationInfoInterface::Stopped && application->surfaceList()->count() == 0) {
125 prependPlaceholder(application);
126 }
129void TopLevelWindowModel::removeApplication(unityapi::ApplicationInfoInterface *application)
131 DEBUG_MSG << "(" << application->appId() << ")";
133 Q_ASSERT(m_modelState == IdleState);
135 int i = 0;
136 while (i < m_windowModel.count()) {
137 if (m_windowModel.at(i).application == application) {
138 deleteAt(i);
139 } else {
140 ++i;
141 }
142 }
145void TopLevelWindowModel::prependPlaceholder(unityapi::ApplicationInfoInterface *application)
147 INFO_MSG << "(" << application->appId() << ")";
149 prependSurfaceHelper(nullptr, application);
152void TopLevelWindowModel::prependSurface(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
154 Q_ASSERT(surface != nullptr);
156 connectSurface(surface);
158 bool filledPlaceholder = false;
159 for (int i = 0; i < m_windowModel.count() && !filledPlaceholder; ++i) {
160 ModelEntry &entry = m_windowModel[i];
161 if (entry.application == application && entry.window->surface() == nullptr) {
162 entry.window->setSurface(surface);
163 INFO_MSG << " appId=" << application->appId() << " surface=" << surface
164 << ", filling out placeholder. after: " << toString();
165 filledPlaceholder = true;
166 }
167 }
169 if (!filledPlaceholder) {
170 INFO_MSG << " appId=" << application->appId() << " surface=" << surface << ", adding new row";
171 prependSurfaceHelper(surface, application);
172 }
175void TopLevelWindowModel::prependSurfaceHelper(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
178 Window *window = createWindow(surface);
180 connect(window, &Window::stateChanged, this, [=](Mir::State newState) {
181 if (newState == Mir::HiddenState) {
182 // Comply, removing it from our model. Just as if it didn't exist anymore.
183 removeAt(indexForId(window->id()));
184 } else {
185 if (indexForId(window->id()) == -1) {
186 // was probably hidden before. put it back on the list
187 auto *application = m_applicationManager->findApplicationWithSurface(window->surface());
188 Q_ASSERT(application);
189 prependWindow(window, application);
190 }
191 }
192 });
194 prependWindow(window, application);
196 if (!surface) {
197 activateEmptyWindow(window);
198 }
200 INFO_MSG << " after " << toString();
203void TopLevelWindowModel::prependWindow(Window *window, unityapi::ApplicationInfoInterface *application)
205 if (m_modelState == IdleState) {
206 m_modelState = InsertingState;
207 beginInsertRows(QModelIndex(), 0 /*first*/, 0 /*last*/);
208 } else {
209 Q_ASSERT(m_modelState == ResettingState);
210 // No point in signaling anything if we're resetting the whole model
211 }
213 m_windowModel.prepend(ModelEntry(window, application));
215 if (m_modelState == InsertingState) {
216 endInsertRows();
217 Q_EMIT countChanged();
218 Q_EMIT listChanged();
219 m_modelState = IdleState;
220 }
223void TopLevelWindowModel::connectWindow(Window *window)
225 connect(window, &Window::focusRequested, this, [this, window]() {
226 if (!window->surface()) {
227 activateEmptyWindow(window);
228 }
229 });
231 connect(window, &Window::focusedChanged, this, [this, window](bool focused) {
232 if (window->surface()) {
233 // Condense changes to the focused window
234 // eg: Do focusedWindow=A to focusedWindow=B instead of
235 // focusedWindow=A to focusedWindow=null to focusedWindow=B
236 if (focused) {
237 Q_ASSERT(m_newlyFocusedWindow == nullptr);
238 m_focusedWindowChanged = true;
239 m_newlyFocusedWindow = window;
240 } else if (m_focusedWindow == window) {
241 m_focusedWindowChanged = true;
242 } else {
243 // don't clear the focused window if you were not there in the first place
244 // happens when a filled window gets replaced with an empty one (no surface) as the focused window.
245 }
246 }
247 });
249 connect(window, &Window::closeRequested, this, [this, window]() {
250 if (!window->surface()) {
251 // do things ourselves as miral doesn't know about this window
252 int id = window->id();
253 int index = indexForId(id);
254 bool focusOther = false;
255 Q_ASSERT(index >= 0);
256 if (window->focused()) {
257 focusOther = true;
258 }
259 m_windowModel[index].application->close();
260 if (focusOther) {
261 activateTopMostWindowWithoutId(id);
262 }
263 }
264 });
266 connect(window, &Window::emptyWindowActivated, this, [this, window]() {
267 activateEmptyWindow(window);
268 });
270 connect(window, &Window::liveChanged, this, [this, window](bool isAlive) {
271 if (!isAlive && window->state() == Mir::HiddenState) {
272 // Hidden windows are not in the model. So just delete it right away.
273 delete window;
274 }
275 });
278void TopLevelWindowModel::activateEmptyWindow(Window *window)
280 Q_ASSERT(!window->surface());
281 DEBUG_MSG << "(" << window << ")";
283 // miral doesn't know about empty windows (ie, windows that are not backed up by MirSurfaces)
284 // So we have to activate them ourselves (instead of asking SurfaceManager to do it for us).
286 window->setFocused(true);
287 raiseId(window->id());
288 Window *previousWindow = m_focusedWindow;
289 setFocusedWindow(window);
290 if (previousWindow && previousWindow->surface() && previousWindow->surface()->focused()) {
291 m_surfaceManager->activate(nullptr);
292 }
295void TopLevelWindowModel::connectSurface(unityapi::MirSurfaceInterface *surface)
297 connect(surface, &unityapi::MirSurfaceInterface::liveChanged, this, [this, surface](bool live){
298 if (!live) {
299 onSurfaceDied(surface);
300 }
301 });
302 connect(surface, &QObject::destroyed, this, [this, surface](){ this->onSurfaceDestroyed(surface); });
305void TopLevelWindowModel::onSurfaceDied(unityapi::MirSurfaceInterface *surface)
307 if (surface->type() == Mir::InputMethodType) {
308 removeInputMethodWindow();
309 return;
310 }
312 int i = indexOf(surface);
313 if (i == -1) {
314 return;
315 }
317 auto application = m_windowModel[i].application;
319 // can't be starting if it already has a surface
320 Q_ASSERT(application->state() != unityapi::ApplicationInfoInterface::Starting);
322 if (application->state() == unityapi::ApplicationInfoInterface::Running) {
323 m_windowModel[i].removeOnceSurfaceDestroyed = true;
324 } else {
325 // assume it got killed by the out-of-memory daemon.
326 //
327 // So leave entry in the model and only remove its surface, so shell can display a screenshot
328 // in its place.
329 m_windowModel[i].removeOnceSurfaceDestroyed = false;
330 }
333void TopLevelWindowModel::onSurfaceDestroyed(unityapi::MirSurfaceInterface *surface)
335 int i = indexOf(surface);
336 if (i == -1) {
337 return;
338 }
340 if (m_windowModel[i].removeOnceSurfaceDestroyed) {
341 deleteAt(i);
342 } else {
343 auto window = m_windowModel[i].window;
344 window->setSurface(nullptr);
345 window->setFocused(false);
346 INFO_MSG << " Removed surface from entry. After: " << toString();
347 }
350Window *TopLevelWindowModel::createWindow(unityapi::MirSurfaceInterface *surface)
352 int id = generateId();
353 Window *qmlWindow = new Window(id, this);
354 connectWindow(qmlWindow);
355 if (surface) {
356 qmlWindow->setSurface(surface);
357 }
358 return qmlWindow;
361void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface *surface)
363 DEBUG_MSG << "(" << surface << ")";
365 if (surface->parentSurface()) {
366 // Wrap it in a Window so that we keep focusedWindow() up to date.
367 Window *window = createWindow(surface);
368 connect(surface, &QObject::destroyed, window, [=](){
369 window->setSurface(nullptr);
370 window->deleteLater();
371 });
372 } else {
373 if (surface->type() == Mir::InputMethodType) {
374 connectSurface(surface);
375 setInputMethodWindow(createWindow(surface));
376 } else {
377 auto *application = m_applicationManager->findApplicationWithSurface(surface);
378 if (application) {
379 if (surface->state() == Mir::HiddenState) {
380 // Ignore it until it's finally shown
381 connect(surface, &unityapi::MirSurfaceInterface::stateChanged, this, [=](Mir::State newState) {
382 Q_ASSERT(newState != Mir::HiddenState);
383 disconnect(surface, &unityapi::MirSurfaceInterface::stateChanged, this, 0);
384 prependSurface(surface, application);
385 });
386 } else {
387 prependSurface(surface, application);
388 }
389 } else {
390 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
391 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
392 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
393 Window *promptWindow = createWindow(surface);
394 connect(surface, &QObject::destroyed, promptWindow, [=](){
395 promptWindow->setSurface(nullptr);
396 promptWindow->deleteLater();
397 });
398 }
399 }
400 }
403void TopLevelWindowModel::deleteAt(int index)
405 auto window = m_windowModel[index].window;
407 removeAt(index);
409 window->setSurface(nullptr);
411 delete window;
414void TopLevelWindowModel::removeAt(int index)
416 if (m_modelState == IdleState) {
417 beginRemoveRows(QModelIndex(), index, index);
418 m_modelState = RemovingState;
419 } else {
420 Q_ASSERT(m_modelState == ResettingState);
421 // No point in signaling anything if we're resetting the whole model
422 }
424 auto window = m_windowModel[index].window;
426 if (!window->surface()) {
427 window->setFocused(false);
428 }
430 m_windowModel.removeAt(index);
432 if (m_modelState == RemovingState) {
433 endRemoveRows();
434 Q_EMIT countChanged();
435 Q_EMIT listChanged();
436 m_modelState = IdleState;
437 }
439 if (m_focusedWindow == window) {
440 setFocusedWindow(nullptr);
441 }
443 if (m_previousWindow == window) {
444 m_previousWindow = nullptr;
445 }
447 if (m_closingAllApps) {
448 if (m_windowModel.isEmpty()) {
449 Q_EMIT closedAllWindows();
450 }
451 }
453 INFO_MSG << " after " << toString() << " apps left " << m_windowModel.count();
456void TopLevelWindowModel::setInputMethodWindow(Window *window)
458 if (m_inputMethodWindow) {
459 qWarning("Multiple Input Method Surfaces created, removing the old one!");
460 delete m_inputMethodWindow;
461 }
462 m_inputMethodWindow = window;
463 Q_EMIT inputMethodSurfaceChanged(m_inputMethodWindow->surface());
466void TopLevelWindowModel::removeInputMethodWindow()
468 if (m_inputMethodWindow) {
469 delete m_inputMethodWindow;
470 m_inputMethodWindow = nullptr;
471 Q_EMIT inputMethodSurfaceChanged(nullptr);
472 }
475void TopLevelWindowModel::onSurfacesRaised(const QVector<unityapi::MirSurfaceInterface*> &surfaces)
477 DEBUG_MSG << "(" << surfaces << ")";
478 const int raiseCount = surfaces.size();
479 for (int i = 0; i < raiseCount; i++) {
480 int fromIndex = findIndexOf(surfaces[i]);
481 if (fromIndex != -1) {
482 move(fromIndex, 0);
483 }
484 }
487int TopLevelWindowModel::rowCount(const QModelIndex &/*parent*/) const
489 return m_windowModel.count();
492QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
494 if (index.row() < 0 || index.row() >= m_windowModel.size())
495 return QVariant();
497 if (role == WindowRole) {
498 Window *window = m_windowModel.at(index.row()).window;
499 return QVariant::fromValue(window);
500 } else if (role == ApplicationRole) {
501 return QVariant::fromValue(m_windowModel.at(index.row()).application);
502 } else {
503 return QVariant();
504 }
507int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
509 for (int i=0; i<m_windowModel.count(); i++) {
510 if (m_windowModel[i].window->surface() == surface) {
511 return i;
512 }
513 }
514 return -1;
517int TopLevelWindowModel::generateId()
519 int id = m_nextId;
520 m_nextId = nextFreeId(nextId(id), id);
521 return id;
524int TopLevelWindowModel::nextId(int id) const
526 if (id == m_maxId) {
527 return id = 1;
528 } else {
529 return id + 1;
530 }
533int TopLevelWindowModel::nextFreeId(int candidateId, const int latestId)
535 int firstCandidateId = candidateId;
537 while (indexForId(candidateId) != -1 || candidateId == latestId) {
538 candidateId = nextId(candidateId);
540 if (candidateId == firstCandidateId) {
541 qFatal("TopLevelWindowModel: run out of window ids.");
542 }
543 }
545 return candidateId;
548QString TopLevelWindowModel::toString()
550 QString str;
551 for (int i = 0; i < m_windowModel.count(); ++i) {
552 auto item = m_windowModel.at(i);
554 QString itemStr = QString("(index=%1,appId=%2,surface=0x%3,id=%4)")
555 .arg(QString::number(i),
556 item.application->appId(),
557 QString::number((qintptr)item.window->surface(), 16),
558 QString::number(item.window->id()));
560 if (i > 0) {
561 str.append(",");
562 }
563 str.append(itemStr);
564 }
565 return str;
568int TopLevelWindowModel::indexOf(unityapi::MirSurfaceInterface *surface)
570 for (int i = 0; i < m_windowModel.count(); ++i) {
571 if (m_windowModel.at(i).window->surface() == surface) {
572 return i;
573 }
574 }
575 return -1;
578int TopLevelWindowModel::indexForId(int id) const
580 for (int i = 0; i < m_windowModel.count(); ++i) {
581 if (m_windowModel[i].window->id() == id) {
582 return i;
583 }
584 }
585 return -1;
588Window *TopLevelWindowModel::windowAt(int index) const
590 if (index >=0 && index < m_windowModel.count()) {
591 return m_windowModel[index].window;
592 } else {
593 return nullptr;
594 }
597unityapi::MirSurfaceInterface *TopLevelWindowModel::surfaceAt(int index) const
599 if (index >=0 && index < m_windowModel.count()) {
600 return m_windowModel[index].window->surface();
601 } else {
602 return nullptr;
603 }
606unityapi::ApplicationInfoInterface *TopLevelWindowModel::applicationAt(int index) const
608 if (index >=0 && index < m_windowModel.count()) {
609 return m_windowModel[index].application;
610 } else {
611 return nullptr;
612 }
615int TopLevelWindowModel::idAt(int index) const
617 if (index >=0 && index < m_windowModel.count()) {
618 return m_windowModel[index].window->id();
619 } else {
620 return 0;
621 }
624void TopLevelWindowModel::raiseId(int id)
626 if (m_modelState == IdleState) {
627 DEBUG_MSG << "(id=" << id << ") - do it now.";
628 doRaiseId(id);
629 } else {
630 DEBUG_MSG << "(id=" << id << ") - Model busy (modelState=" << m_modelState << "). Try again in the next event loop.";
631 // The model has just signalled some change. If we have a Repeater responding to this update, it will get nuts
632 // if we perform yet another model change straight away.
633 //
634 // A bad sympton of this problem is a Repeater.itemAt(index) call returning null event though Repeater.count says
635 // the index is definitely within bounds.
636 QMetaObject::invokeMethod(this, "raiseId", Qt::QueuedConnection, Q_ARG(int, id));
637 }
640void TopLevelWindowModel::doRaiseId(int id)
642 int fromIndex = indexForId(id);
643 // can't raise something that doesn't exist or that it's already on top
644 if (fromIndex != -1 && fromIndex != 0) {
645 auto surface = m_windowModel[fromIndex].window->surface();
646 if (surface) {
647 m_surfaceManager->raise(surface);
648 } else {
649 // move it ourselves. Since there's no mir::scene::Surface/miral::Window, there's nothing
650 // miral can do about it.
651 move(fromIndex, 0);
652 }
653 }
656void TopLevelWindowModel::setFocusedWindow(Window *window)
658 if (window != m_focusedWindow) {
659 INFO_MSG << "(" << window << ")";
661 m_previousWindow = m_focusedWindow;
663 m_focusedWindow = window;
664 Q_EMIT focusedWindowChanged(m_focusedWindow);
666 if (m_previousWindow && m_previousWindow->focused() && !m_previousWindow->surface()) {
667 // do it ourselves. miral doesn't know about this window
668 m_previousWindow->setFocused(false);
669 }
670 }
672 // Reset
673 m_pendingActivation = false;
676unityapi::MirSurfaceInterface* TopLevelWindowModel::inputMethodSurface() const
678 return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
681Window* TopLevelWindowModel::focusedWindow() const
683 return m_focusedWindow;
686void TopLevelWindowModel::move(int from, int to)
688 if (from == to) return;
689 DEBUG_MSG << " from=" << from << " to=" << to;
691 if (from >= 0 && from < m_windowModel.size() && to >= 0 && to < m_windowModel.size()) {
692 QModelIndex parent;
693 /* When moving an item down, the destination index needs to be incremented
694 by one, as explained in the documentation:
695 http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */
697 Q_ASSERT(m_modelState == IdleState);
698 m_modelState = MovingState;
700 beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
701#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
702 const auto &window = m_windowModel.takeAt(from);
703 m_windowModel.insert(to, window);
704#else
705 m_windowModel.move(from, to);
706#endif
707 endMoveRows();
709 Q_EMIT listChanged();
710 m_modelState = IdleState;
712 INFO_MSG << " after " << toString();
713 }
715void TopLevelWindowModel::onModificationsStarted()
717 m_surfaceManagerBusy = true;
720void TopLevelWindowModel::onModificationsEnded()
722 if (m_focusedWindowChanged) {
723 setFocusedWindow(m_newlyFocusedWindow);
724 }
725 // reset
726 m_focusedWindowChanged = false;
727 m_newlyFocusedWindow = nullptr;
728 m_surfaceManagerBusy = false;
731void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
733 DEBUG_MSG << "(" << forbiddenId << ")";
735 for (int i = 0; i < m_windowModel.count(); ++i) {
736 Window *window = m_windowModel[i].window;
737 if (window->id() != forbiddenId) {
738 window->activate();
739 break;
740 }
741 }
744void TopLevelWindowModel::closeAllWindows()
746 m_closingAllApps = true;
747 for (auto win : m_windowModel) {
748 win.window->close();
749 }
751 // This is done after the for loop in the unlikely event that
752 // an app starts in between this
753 if (m_windowModel.isEmpty()) {
754 Q_EMIT closedAllWindows();
755 }
758bool TopLevelWindowModel::rootFocus()
760 return !m_nullWindow->focused();
763void TopLevelWindowModel::setRootFocus(bool focus)
765 INFO_MSG << "(" << focus << "), surfaceManagerBusy is " << m_surfaceManagerBusy;
767 if (m_surfaceManagerBusy) {
768 // Something else is probably being focused already, let's not add to
769 // the noise.
770 return;
771 }
773 if (focus) {
774 // Give focus back to previous focused window, only if null window is focused.
775 // If null window is not focused, a different app had taken the focus and we
776 // should repect that, or if a pendingActivation is going on.
777 if (m_previousWindow && !m_previousWindow->focused() && !m_pendingActivation &&
778 m_nullWindow == m_focusedWindow && m_previousWindow != m_nullWindow) {
779 m_previousWindow->activate();
780 } else if (!m_pendingActivation) {
781 // The previous window does not exist any more, focus top window.
782 activateTopMostWindowWithoutId(-1);
783 }
784 } else {
785 if (!m_nullWindow->focused()) {
786 m_nullWindow->activate();
787 }
788 }
791// Pending Activation will block refocus of previous focused window
792// this is needed since surface activation with miral is async,
793// and activation of placeholder is sync. This causes a race condition
794// between placeholder and prev window. This results in prev window
795// gets focused, as it will always be later than the placeholder.
796void TopLevelWindowModel::pendingActivation()
798 m_pendingActivation = true;