on 47aff7b help sign in
unity8/plugins/WindowManager/TopLevelWindowModel.cpp
808 lines 25 kB history raw
1/*
2 * Copyright (C) 2016 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 <QDebug>
29// local
30#include "Window.h"
31#include "Workspace.h"
32#include "windowmanagementpolicy.h"
34// qtmir
35#include <qtmir/mirserverapplication.h>
36#include <qtmir/windowmodelnotifier.h>
38Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel")
40#define DEBUG_MSG qCDebug(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
41#define INFO_MSG qCInfo(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
43namespace unityapi = unity::shell::application;
45TopLevelWindowModel::TopLevelWindowModel()
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 disconnect(m_applicationManager, 0, this, 0);
64 }
66 m_applicationManager = value;
68 if (m_applicationManager && m_workspace) {
70 if (m_workspace->isActive()) {
71 connectApplicationManager();
72 }
74 if (m_surfaceManager) {
75 refreshWindows();
76 }
77 }
79 Q_EMIT applicationManagerChanged(m_applicationManager);
81 endResetModel();
82 m_modelState = IdleState;
85void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *surfaceManager)
87 if (surfaceManager == m_surfaceManager) {
88 return;
89 }
91 DEBUG_MSG << "(" << surfaceManager << ")";
93 Q_ASSERT(m_modelState == IdleState);
94 m_modelState = ResettingState;
96 beginResetModel();
98 if (m_surfaceManager) {
99 disconnect(m_surfaceManager, 0, this, 0);
100 }
102 m_surfaceManager = surfaceManager;
104 if (m_surfaceManager) {
105 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfaceCreated, this, &TopLevelWindowModel::onSurfaceCreated);
106 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
107 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
108 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
110 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
111 this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
113 if (m_workspace && m_applicationManager) {
114 refreshWindows();
115 }
116 }
118 Q_EMIT surfaceManagerChanged(m_surfaceManager);
120 endResetModel();
121 m_modelState = IdleState;
124void TopLevelWindowModel::setWorkspace(Workspace *workspace)
126 if (workspace == m_workspace) {
127 return;
128 }
130 DEBUG_MSG << "(" << workspace << ")";
132 Q_ASSERT(m_modelState == IdleState);
133 m_modelState = ResettingState;
135 beginResetModel();
137 if (m_workspace) {
138 m_windowModel.clear();
139 m_allSurfaces.clear();
140 if (m_applicationManager) {
141 disconnect(m_applicationManager, 0, this, 0);
142 }
143 }
145 disconnect(m_applicationManager, 0 ,this, 0);
147 m_workspace = workspace;
149 if (m_workspace) {
150 connect(m_workspace, &Workspace::activeChanged, this, [this](bool active) {
151 if (m_applicationManager) {
152 if (!active) disconnect(m_applicationManager, 0, this, 0);
153 else {
154 connectApplicationManager();
155 }
156 }
157 });
159 if (m_applicationManager && m_workspace->isActive()) {
160 connectApplicationManager();
161 }
163 if (m_surfaceManager && m_applicationManager) {
164 refreshWindows();
165 }
166 }
168 Q_EMIT workspaceChanged(workspace);
170 endResetModel();
171 m_modelState = IdleState;
174void TopLevelWindowModel::addApplication(unityapi::ApplicationInfoInterface *application)
176 DEBUG_MSG << "(" << application->appId() << ")";
178 if (application->state() != unityapi::ApplicationInfoInterface::Stopped && application->surfaceList()->count() == 0) {
179 prependPlaceholder(application);
180 }
183void TopLevelWindowModel::removeApplication(unityapi::ApplicationInfoInterface *application)
185 DEBUG_MSG << "(" << application->appId() << ")";
187 Q_ASSERT(m_modelState == IdleState);
189 int i = 0;
190 while (i < m_windowModel.count()) {
191 if (m_windowModel.at(i).application == application) {
192 removeAt(i);
193 } else {
194 ++i;
195 }
196 }
199void TopLevelWindowModel::prependPlaceholder(unityapi::ApplicationInfoInterface *application)
201 INFO_MSG << "(" << application->appId() << ")";
203 prependSurfaceHelper(nullptr, application);
206void TopLevelWindowModel::prependSurface(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
208 Q_ASSERT(surface != nullptr);
210 bool filledPlaceholder = false;
211 for (int i = 0; i < m_windowModel.count() && !filledPlaceholder; ++i) {
212 ModelEntry &entry = m_windowModel[i];
213 if (entry.application == application && entry.window->surface() == nullptr) {
214 entry.window->setSurface(surface);
215 connectSurface(surface);
216 INFO_MSG << " appId=" << application->appId() << " surface=" << surface
217 << ", filling out placeholder. after: " << toString();
218 filledPlaceholder = true;
219 }
220 }
222 if (!filledPlaceholder) {
223 INFO_MSG << " appId=" << application->appId() << " surface=" << surface << ", adding new row";
224 prependSurfaceHelper(surface, application);
225 }
228void TopLevelWindowModel::prependSurfaceHelper(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
230 if (m_modelState == IdleState) {
231 m_modelState = InsertingState;
232 beginInsertRows(QModelIndex(), 0 /*first*/, 0 /*last*/);
233 } else {
234 Q_ASSERT(m_modelState == ResettingState);
235 // No point in signaling anything if we're resetting the whole model
236 }
238 Window *window = createWindow(surface);
240 m_windowModel.prepend(ModelEntry(window, application));
241 m_allSurfaces.insert(surface);
242 if (surface) {
243 connectSurface(surface);
244 }
246 if (m_modelState == InsertingState) {
247 endInsertRows();
248 Q_EMIT countChanged();
249 Q_EMIT listChanged();
250 m_modelState = IdleState;
251 }
253 if (!surface) {
254 activateEmptyWindow(window);
255 }
257 INFO_MSG << " after " << toString();
260void TopLevelWindowModel::connectWindow(Window *window)
262 connect(window, &Window::focusRequested, this, [this, window]() {
263 if (!window->surface()) {
264 activateEmptyWindow(window);
265 }
266 });
268 connect(window, &Window::focusedChanged, this, [this, window](bool focused) {
269 if (window->surface()) {
270 // Condense changes to the focused window
271 // eg: Do focusedWindow=A to focusedWindow=B instead of
272 // focusedWindow=A to focusedWindow=null to focusedWindow=B
273 if (focused) {
274 Q_ASSERT(m_newlyFocusedWindow == nullptr);
275 m_focusedWindowChanged = true;
276 m_newlyFocusedWindow = window;
277 } else if (m_focusedWindow == window) {
278 m_focusedWindowChanged = true;
279 } else {
280 // don't clear the focused window if you were not there in the first place
281 // happens when a filled window gets replaced with an empty one (no surface) as the focused window.
282 }
283 }
284 });
286 connect(window, &Window::closeRequested, this, [this, window]() {
287 if (!window->surface()) {
288 // do things ourselves as miral doesn't know about this window
289 int id = window->id();
290 int index = indexForId(id);
291 bool focusOther = false;
292 Q_ASSERT(index >= 0);
293 if (window->focused()) {
294 focusOther = true;
295 }
296 m_windowModel[index].application->close();
297 if (focusOther) {
298 activateTopMostWindowWithoutId(id);
299 }
300 }
301 });
303 connect(window, &Window::emptyWindowActivated, this, [this, window]() {
304 activateEmptyWindow(window);
305 });
308void TopLevelWindowModel::activateEmptyWindow(Window *window)
310 Q_ASSERT(!window->surface());
311 DEBUG_MSG << "(" << window << ")";
313 // miral doesn't know about empty windows (ie, windows that are not backed up by MirSurfaces)
314 // So we have to activate them ourselves (instead of asking SurfaceManager to do it for us).
316 window->setFocused(true);
317 raiseId(window->id());
318 Window *previousWindow = m_focusedWindow;
319 setFocusedWindow(window);
320 if (previousWindow && previousWindow->surface() && previousWindow->surface()->focused()) {
321 m_surfaceManager->activate(nullptr);
322 }
325void TopLevelWindowModel::connectSurface(unityapi::MirSurfaceInterface *surface)
327 connect(surface, &unityapi::MirSurfaceInterface::liveChanged, this, [this, surface](bool live){
328 if (!live) {
329 onSurfaceDied(surface);
330 }
331 });
332 connect(surface, &QObject::destroyed, this, [this, surface](){ this->onSurfaceDestroyed(surface); });
335void TopLevelWindowModel::onSurfaceDied(unityapi::MirSurfaceInterface *surface)
337 if (surface->type() == Mir::InputMethodType) {
338 removeInputMethodWindow();
339 return;
340 }
342 int i = indexOf(surface);
343 if (i == -1) {
344 return;
345 }
347 auto application = m_windowModel[i].application;
349 // can't be starting if it already has a surface
350 Q_ASSERT(application->state() != unityapi::ApplicationInfoInterface::Starting);
352 if (application->state() == unityapi::ApplicationInfoInterface::Running) {
353 m_windowModel[i].removeOnceSurfaceDestroyed = true;
354 } else {
355 // assume it got killed by the out-of-memory daemon.
356 //
357 // So leave entry in the model and only remove its surface, so shell can display a screenshot
358 // in its place.
359 m_windowModel[i].removeOnceSurfaceDestroyed = false;
360 }
363void TopLevelWindowModel::onSurfaceDestroyed(unityapi::MirSurfaceInterface *surface)
365 int i = indexOf(surface);
366 if (i == -1) {
367 return;
368 }
370 if (m_windowModel[i].removeOnceSurfaceDestroyed) {
371 removeAt(i);
372 } else {
373 auto window = m_windowModel[i].window;
374 window->setSurface(nullptr);
375 window->setFocused(false);
376 m_allSurfaces.remove(surface);
377 INFO_MSG << " Removed surface from entry. After: " << toString();
378 }
381Window *TopLevelWindowModel::createWindow(unityapi::MirSurfaceInterface *surface)
383 int id = generateId();
384 Window *qmlWindow = new Window(id, this);
385 connectWindow(qmlWindow);
386 if (surface) {
387 qmlWindow->setSurface(surface);
388 }
389 return qmlWindow;
393void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface */*surface*/)
397void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
398 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
400 if (workspace != m_workspace->workspace()) return;
402 Q_FOREACH(auto surface, surfaces) {
403 if (m_allSurfaces.contains(surface)) continue;
405 if (surface->parentSurface()) {
406 // Wrap it in a Window so that we keep focusedWindow() up to date.
407 Window *window = createWindow(surface);
408 connect(surface, &QObject::destroyed, window, [=](){
409 window->setSurface(nullptr);
410 window->deleteLater();
411 });
412 } else {
413 if (surface->type() == Mir::InputMethodType) {
414 setInputMethodWindow(createWindow(surface));
415 } else {
416 auto *application = m_applicationManager->findApplicationWithSurface(surface);
417 if (application) {
418 prependSurface(surface, application);
419 } else {
420 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
421 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
422 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
423 Window *promptWindow = createWindow(surface);
424 connect(surface, &QObject::destroyed, promptWindow, [=](){
425 promptWindow->setSurface(nullptr);
426 promptWindow->deleteLater();
427 });
428 }
429 }
430 }
431 }
434void TopLevelWindowModel::removeAt(int index)
436 if (m_modelState == IdleState) {
437 beginRemoveRows(QModelIndex(), index, index);
438 m_modelState = RemovingState;
439 } else {
440 Q_ASSERT(m_modelState == ResettingState);
441 // No point in signaling anything if we're resetting the whole model
442 }
444 auto window = m_windowModel[index].window;
446 window->setSurface(nullptr);
447 window->setFocused(false);
449 m_windowModel.removeAt(index);
450 m_allSurfaces.remove(window->surface());
452 if (m_modelState == RemovingState) {
453 endRemoveRows();
454 Q_EMIT countChanged();
455 Q_EMIT listChanged();
456 m_modelState = IdleState;
457 }
459 disconnect(window, 0, this, 0);
460 if (m_focusedWindow == window) {
461 setFocusedWindow(nullptr);
462 }
463 delete window;
465 INFO_MSG << " after " << toString();
468void TopLevelWindowModel::setInputMethodWindow(Window *window)
470 if (m_inputMethodWindow) {
471 qWarning("Multiple Input Method Surfaces created, removing the old one!");
472 delete m_inputMethodWindow;
473 }
474 m_inputMethodWindow = window;
475 Q_EMIT inputMethodSurfaceChanged(m_inputMethodWindow->surface());
478void TopLevelWindowModel::removeInputMethodWindow()
480 if (m_inputMethodWindow) {
481 delete m_inputMethodWindow;
482 m_inputMethodWindow = nullptr;
483 Q_EMIT inputMethodSurfaceChanged(nullptr);
484 }
487void TopLevelWindowModel::onSurfacesRaised(const QVector<unityapi::MirSurfaceInterface*> &surfaces)
489 DEBUG_MSG << "(" << surfaces << ")";
490 const int raiseCount = surfaces.size();
491 for (int i = 0; i < raiseCount; i++) {
492 int fromIndex = findIndexOf(surfaces[i]);
493 if (fromIndex != -1) {
494 move(fromIndex, 0);
495 }
496 }
499int TopLevelWindowModel::rowCount(const QModelIndex &/*parent*/) const
501 return m_windowModel.count();
504QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
506 if (index.row() < 0 || index.row() >= m_windowModel.size())
507 return QVariant();
509 if (role == WindowRole) {
510 Window *window = m_windowModel.at(index.row()).window;
511 return QVariant::fromValue(window);
512 } else if (role == ApplicationRole) {
513 return QVariant::fromValue(m_windowModel.at(index.row()).application);
514 } else {
515 return QVariant();
516 }
519void TopLevelWindowModel::connectApplicationManager()
521 connect(m_applicationManager, &QAbstractItemModel::rowsInserted,
522 this, [this](const QModelIndex &/*parent*/, int first, int last) {
523 for (int i = first; i <= last; ++i) {
524 auto application = m_applicationManager->get(i);
525 addApplication(application);
526 }
527 });
529 connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved,
530 this, [this](const QModelIndex &/*parent*/, int first, int last) {
531 for (int i = first; i <= last; ++i) {
532 auto application = m_applicationManager->get(i);
533 removeApplication(application);
534 }
535 });
539int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
541 for (int i=0; i<m_windowModel.count(); i++) {
542 if (m_windowModel[i].window->surface() == surface) {
543 return i;
544 }
545 }
546 return -1;
549int TopLevelWindowModel::generateId()
551 int id = m_nextId;
552 m_nextId = nextFreeId(nextId(id), id);
553 return id;
556int TopLevelWindowModel::nextId(int id) const
558 if (id == m_maxId) {
559 return id = 1;
560 } else {
561 return id + 1;
562 }
565int TopLevelWindowModel::nextFreeId(int candidateId, const int latestId)
567 int firstCandidateId = candidateId;
569 while (indexForId(candidateId) != -1 || candidateId == latestId) {
570 candidateId = nextId(candidateId);
572 if (candidateId == firstCandidateId) {
573 qFatal("TopLevelWindowModel: run out of window ids.");
574 }
575 }
577 return candidateId;
580QString TopLevelWindowModel::toString()
582 QString str;
583 for (int i = 0; i < m_windowModel.count(); ++i) {
584 auto item = m_windowModel.at(i);
586 QString itemStr = QString("(index=%1,appId=%2,surface=0x%3,id=%4)")
587 .arg(QString::number(i),
588 item.application->appId(),
589 QString::number((qintptr)item.window->surface(), 16),
590 QString::number(item.window->id()));
592 if (i > 0) {
593 str.append(",");
594 }
595 str.append(itemStr);
596 }
597 return str;
600int TopLevelWindowModel::indexOf(unityapi::MirSurfaceInterface *surface)
602 for (int i = 0; i < m_windowModel.count(); ++i) {
603 if (m_windowModel.at(i).window->surface() == surface) {
604 return i;
605 }
606 }
607 return -1;
610int TopLevelWindowModel::indexForId(int id) const
612 for (int i = 0; i < m_windowModel.count(); ++i) {
613 if (m_windowModel[i].window->id() == id) {
614 return i;
615 }
616 }
617 return -1;
620Window *TopLevelWindowModel::windowAt(int index) const
622 if (index >=0 && index < m_windowModel.count()) {
623 return m_windowModel[index].window;
624 } else {
625 return nullptr;
626 }
629unityapi::MirSurfaceInterface *TopLevelWindowModel::surfaceAt(int index) const
631 if (index >=0 && index < m_windowModel.count()) {
632 return m_windowModel[index].window->surface();
633 } else {
634 return nullptr;
635 }
638unityapi::ApplicationInfoInterface *TopLevelWindowModel::applicationAt(int index) const
640 if (index >=0 && index < m_windowModel.count()) {
641 return m_windowModel[index].application;
642 } else {
643 return nullptr;
644 }
647int TopLevelWindowModel::idAt(int index) const
649 if (index >=0 && index < m_windowModel.count()) {
650 return m_windowModel[index].window->id();
651 } else {
652 return 0;
653 }
656void TopLevelWindowModel::raiseId(int id)
658 if (m_modelState == IdleState) {
659 DEBUG_MSG << "(id=" << id << ") - do it now.";
660 doRaiseId(id);
661 } else {
662 DEBUG_MSG << "(id=" << id << ") - Model busy (modelState=" << m_modelState << "). Try again in the next event loop.";
663 // The model has just signalled some change. If we have a Repeater responding to this update, it will get nuts
664 // if we perform yet another model change straight away.
665 //
666 // A bad sympton of this problem is a Repeater.itemAt(index) call returning null event though Repeater.count says
667 // the index is definitely within bounds.
668 QMetaObject::invokeMethod(this, "raiseId", Qt::QueuedConnection, Q_ARG(int, id));
669 }
672void TopLevelWindowModel::doRaiseId(int id)
674 int fromIndex = indexForId(id);
675 // can't raise something that doesn't exist or that it's already on top
676 if (fromIndex != -1 && fromIndex != 0) {
677 auto surface = m_windowModel[fromIndex].window->surface();
678 if (surface) {
679 m_surfaceManager->raise(surface);
680 } else {
681 // move it ourselves. Since there's no mir::scene::Surface/miral::Window, there's nothing
682 // miral can do about it.
683 move(fromIndex, 0);
684 }
685 }
688void TopLevelWindowModel::setFocusedWindow(Window *window)
690 if (window != m_focusedWindow) {
691 INFO_MSG << "(" << window << ")";
693 Window* previousWindow = m_focusedWindow;
695 m_focusedWindow = window;
696 Q_EMIT focusedWindowChanged(m_focusedWindow);
698 if (previousWindow && previousWindow->focused() && !previousWindow->surface()) {
699 // do it ourselves. miral doesn't know about this window
700 previousWindow->setFocused(false);
701 }
702 }
705unityapi::MirSurfaceInterface* TopLevelWindowModel::inputMethodSurface() const
707 return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
710Window* TopLevelWindowModel::focusedWindow() const
712 return m_focusedWindow;
715void TopLevelWindowModel::move(int from, int to)
717 if (from == to) return;
718 DEBUG_MSG << " from=" << from << " to=" << to;
720 if (from >= 0 && from < m_windowModel.size() && to >= 0 && to < m_windowModel.size()) {
721 QModelIndex parent;
722 /* When moving an item down, the destination index needs to be incremented
723 by one, as explained in the documentation:
724 http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */
726 Q_ASSERT(m_modelState == IdleState);
727 m_modelState = MovingState;
729 beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
730#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
731 const auto &window = m_windowModel.takeAt(from);
732 m_windowModel.insert(to, window);
733#else
734 m_windowModel.move(from, to);
735#endif
736 endMoveRows();
738 Q_EMIT listChanged();
739 m_modelState = IdleState;
741 INFO_MSG << " after " << toString();
742 }
744void TopLevelWindowModel::onModificationsStarted()
748void TopLevelWindowModel::onModificationsEnded()
750 if (m_focusedWindowChanged) {
751 setFocusedWindow(m_newlyFocusedWindow);
752 }
753 // reset
754 m_focusedWindowChanged = false;
755 m_newlyFocusedWindow = nullptr;
758void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
760 DEBUG_MSG << "(" << forbiddenId << ")";
762 for (int i = 0; i < m_windowModel.count(); ++i) {
763 Window *window = m_windowModel[i].window;
764 if (window->id() != forbiddenId) {
765 window->activate();
766 }
767 }
770void TopLevelWindowModel::refreshWindows()
772 DEBUG_MSG << "()";
774 m_windowModel.clear();
775 m_allSurfaces.clear();
777 WindowManagementPolicy::instance()->forEachWindowInWorkspace(m_workspace->workspace(), [this](const miral::Window &window) {
778 auto surface = m_surfaceManager->surfaceFor(window);
779 if (surface) {
780 if (surface->parentSurface()) {
781 // Wrap it in a Window so that we keep focusedWindow() up to date.
782 Window *window = createWindow(surface);
783 connect(surface, &QObject::destroyed, window, [=](){
784 window->setSurface(nullptr);
785 window->deleteLater();
786 });
787 } else {
788 if (surface->type() == Mir::InputMethodType) {
789 setInputMethodWindow(createWindow(surface));
790 } else {
791 auto *application = m_applicationManager->findApplicationWithSurface(surface);
792 if (application) {
793 prependSurface(surface, application);
794 } else {
795 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
796 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
797 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
798 Window *promptWindow = createWindow(surface);
799 connect(surface, &QObject::destroyed, promptWindow, [=](){
800 promptWindow->setSurface(nullptr);
801 promptWindow->deleteLater();
802 });
803 }
804 }
805 }
806 }
807 });