on 747a319 help sign in
unity8/plugins/WindowManager/TopLevelWindowModel.cpp
800 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", QtInfoMsg)
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 if (m_applicationManager) {
140 disconnect(m_applicationManager, 0, this, 0);
141 }
142 }
144 disconnect(m_applicationManager, 0 ,this, 0);
146 m_workspace = workspace;
148 if (m_workspace) {
149 connect(m_workspace, &Workspace::activeChanged, this, [this](bool active) {
150 if (m_applicationManager) {
151 if (!active) disconnect(m_applicationManager, 0, this, 0);
152 else {
153 connectApplicationManager();
154 }
155 }
156 });
158 if (m_applicationManager && m_workspace->isActive()) {
159 connectApplicationManager();
160 }
162 if (m_surfaceManager && m_applicationManager) {
163 refreshWindows();
164 }
165 }
167 Q_EMIT workspaceChanged(workspace);
169 endResetModel();
170 m_modelState = IdleState;
173void TopLevelWindowModel::addApplication(unityapi::ApplicationInfoInterface *application)
175 DEBUG_MSG << "(" << application->appId() << ")";
177 if (application->state() != unityapi::ApplicationInfoInterface::Stopped && application->surfaceList()->count() == 0) {
178 prependPlaceholder(application);
179 }
182void TopLevelWindowModel::removeApplication(unityapi::ApplicationInfoInterface *application)
184 DEBUG_MSG << "(" << application->appId() << ")";
186 Q_ASSERT(m_modelState == IdleState);
188 int i = 0;
189 while (i < m_windowModel.count()) {
190 if (m_windowModel.at(i).application == application) {
191 removeAt(i);
192 } else {
193 ++i;
194 }
195 }
198void TopLevelWindowModel::prependPlaceholder(unityapi::ApplicationInfoInterface *application)
200 INFO_MSG << "(" << application->appId() << ")";
202 prependSurfaceHelper(nullptr, application);
205void TopLevelWindowModel::prependSurface(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
207 Q_ASSERT(surface != nullptr);
209 bool filledPlaceholder = false;
210 for (int i = 0; i < m_windowModel.count() && !filledPlaceholder; ++i) {
211 ModelEntry &entry = m_windowModel[i];
212 if (entry.application == application && entry.window->surface() == nullptr) {
213 entry.window->setSurface(surface);
214 connectSurface(surface);
215 INFO_MSG << " appId=" << application->appId() << " surface=" << surface
216 << ", filling out placeholder. after: " << toString();
217 filledPlaceholder = true;
218 }
219 }
221 if (!filledPlaceholder) {
222 INFO_MSG << " appId=" << application->appId() << " surface=" << surface << ", adding new row";
223 prependSurfaceHelper(surface, application);
224 }
227void TopLevelWindowModel::prependSurfaceHelper(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
229 if (m_modelState == IdleState) {
230 m_modelState = InsertingState;
231 beginInsertRows(QModelIndex(), 0 /*first*/, 0 /*last*/);
232 } else {
233 Q_ASSERT(m_modelState == ResettingState);
234 // No point in signaling anything if we're resetting the whole model
235 }
237 Window *window = createWindow(surface);
239 m_windowModel.prepend(ModelEntry(window, application));
240 if (surface) {
241 connectSurface(surface);
242 }
244 if (m_modelState == InsertingState) {
245 endInsertRows();
246 Q_EMIT countChanged();
247 Q_EMIT listChanged();
248 m_modelState = IdleState;
249 }
251 if (!surface) {
252 activateEmptyWindow(window);
253 }
255 INFO_MSG << " after " << toString();
258void TopLevelWindowModel::connectWindow(Window *window)
260 connect(window, &Window::focusRequested, this, [this, window]() {
261 if (!window->surface()) {
262 activateEmptyWindow(window);
263 }
264 });
266 connect(window, &Window::focusedChanged, this, [this, window](bool focused) {
267 if (window->surface()) {
268 // Condense changes to the focused window
269 // eg: Do focusedWindow=A to focusedWindow=B instead of
270 // focusedWindow=A to focusedWindow=null to focusedWindow=B
271 if (focused) {
272 Q_ASSERT(m_newlyFocusedWindow == nullptr);
273 m_focusedWindowChanged = true;
274 m_newlyFocusedWindow = window;
275 } else if (m_focusedWindow == window) {
276 m_focusedWindowChanged = true;
277 } else {
278 // don't clear the focused window if you were not there in the first place
279 // happens when a filled window gets replaced with an empty one (no surface) as the focused window.
280 }
281 }
282 });
284 connect(window, &Window::closeRequested, this, [this, window]() {
285 if (!window->surface()) {
286 // do things ourselves as miral doesn't know about this window
287 int id = window->id();
288 int index = indexForId(id);
289 bool focusOther = false;
290 Q_ASSERT(index >= 0);
291 if (window->focused()) {
292 focusOther = true;
293 }
294 m_windowModel[index].application->close();
295 if (focusOther) {
296 activateTopMostWindowWithoutId(id);
297 }
298 }
299 });
301 connect(window, &Window::emptyWindowActivated, this, [this, window]() {
302 activateEmptyWindow(window);
303 });
306void TopLevelWindowModel::activateEmptyWindow(Window *window)
308 Q_ASSERT(!window->surface());
309 DEBUG_MSG << "(" << window << ")";
311 // miral doesn't know about empty windows (ie, windows that are not backed up by MirSurfaces)
312 // So we have to activate them ourselves (instead of asking SurfaceManager to do it for us).
314 window->setFocused(true);
315 raiseId(window->id());
316 Window *previousWindow = m_focusedWindow;
317 setFocusedWindow(window);
318 if (previousWindow && previousWindow->surface() && previousWindow->surface()->focused()) {
319 m_surfaceManager->activate(nullptr);
320 }
323void TopLevelWindowModel::connectSurface(unityapi::MirSurfaceInterface *surface)
325 connect(surface, &unityapi::MirSurfaceInterface::liveChanged, this, [this, surface](bool live){
326 if (!live) {
327 onSurfaceDied(surface);
328 }
329 });
330 connect(surface, &QObject::destroyed, this, [this, surface](){ this->onSurfaceDestroyed(surface); });
333void TopLevelWindowModel::onSurfaceDied(unityapi::MirSurfaceInterface *surface)
335 if (surface->type() == Mir::InputMethodType) {
336 removeInputMethodWindow();
337 return;
338 }
340 int i = indexOf(surface);
341 if (i == -1) {
342 return;
343 }
345 auto application = m_windowModel[i].application;
347 // can't be starting if it already has a surface
348 Q_ASSERT(application->state() != unityapi::ApplicationInfoInterface::Starting);
350 if (application->state() == unityapi::ApplicationInfoInterface::Running) {
351 m_windowModel[i].removeOnceSurfaceDestroyed = true;
352 } else {
353 // assume it got killed by the out-of-memory daemon.
354 //
355 // So leave entry in the model and only remove its surface, so shell can display a screenshot
356 // in its place.
357 m_windowModel[i].removeOnceSurfaceDestroyed = false;
358 }
361void TopLevelWindowModel::onSurfaceDestroyed(unityapi::MirSurfaceInterface *surface)
363 int i = indexOf(surface);
364 if (i == -1) {
365 return;
366 }
368 if (m_windowModel[i].removeOnceSurfaceDestroyed) {
369 removeAt(i);
370 } else {
371 auto window = m_windowModel[i].window;
372 window->setSurface(nullptr);
373 window->setFocused(false);
374 INFO_MSG << " Removed surface from entry. After: " << toString();
375 }
378Window *TopLevelWindowModel::createWindow(unityapi::MirSurfaceInterface *surface)
380 int id = generateId();
381 Window *qmlWindow = new Window(id, this);
382 connectWindow(qmlWindow);
383 if (surface) {
384 qmlWindow->setSurface(surface);
385 }
386 return qmlWindow;
390void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface */*surface*/)
394void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
395 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
397 if (workspace != m_workspace->workspace()) return;
399 Q_FOREACH(auto surface, surfaces) {
400 DEBUG_MSG << "(" << surface << ")";
402 if (surface->parentSurface()) {
403 // Wrap it in a Window so that we keep focusedWindow() up to date.
404 Window *window = createWindow(surface);
405 connect(surface, &QObject::destroyed, window, [=](){
406 window->setSurface(nullptr);
407 window->deleteLater();
408 });
409 } else {
410 if (surface->type() == Mir::InputMethodType) {
411 setInputMethodWindow(createWindow(surface));
412 } else {
413 auto *application = m_applicationManager->findApplicationWithSurface(surface);
414 if (application) {
415 prependSurface(surface, application);
416 } else {
417 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
418 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
419 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
420 Window *promptWindow = createWindow(surface);
421 connect(surface, &QObject::destroyed, promptWindow, [=](){
422 promptWindow->setSurface(nullptr);
423 promptWindow->deleteLater();
424 });
425 }
426 }
427 }
428 }
431void TopLevelWindowModel::removeAt(int index)
433 if (m_modelState == IdleState) {
434 beginRemoveRows(QModelIndex(), index, index);
435 m_modelState = RemovingState;
436 } else {
437 Q_ASSERT(m_modelState == ResettingState);
438 // No point in signaling anything if we're resetting the whole model
439 }
441 auto window = m_windowModel[index].window;
443 window->setSurface(nullptr);
444 window->setFocused(false);
446 m_windowModel.removeAt(index);
448 if (m_modelState == RemovingState) {
449 endRemoveRows();
450 Q_EMIT countChanged();
451 Q_EMIT listChanged();
452 m_modelState = IdleState;
453 }
455 disconnect(window, 0, this, 0);
456 if (m_focusedWindow == window) {
457 setFocusedWindow(nullptr);
458 }
459 delete window;
461 INFO_MSG << " after " << toString();
464void TopLevelWindowModel::setInputMethodWindow(Window *window)
466 if (m_inputMethodWindow) {
467 qWarning("Multiple Input Method Surfaces created, removing the old one!");
468 delete m_inputMethodWindow;
469 }
470 m_inputMethodWindow = window;
471 Q_EMIT inputMethodSurfaceChanged(m_inputMethodWindow->surface());
474void TopLevelWindowModel::removeInputMethodWindow()
476 if (m_inputMethodWindow) {
477 delete m_inputMethodWindow;
478 m_inputMethodWindow = nullptr;
479 Q_EMIT inputMethodSurfaceChanged(nullptr);
480 }
483void TopLevelWindowModel::onSurfacesRaised(const QVector<unityapi::MirSurfaceInterface*> &surfaces)
485 DEBUG_MSG << "(" << surfaces << ")";
486 const int raiseCount = surfaces.size();
487 for (int i = 0; i < raiseCount; i++) {
488 int fromIndex = findIndexOf(surfaces[i]);
489 if (fromIndex != -1) {
490 move(fromIndex, 0);
491 }
492 }
495int TopLevelWindowModel::rowCount(const QModelIndex &/*parent*/) const
497 return m_windowModel.count();
500QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
502 if (index.row() < 0 || index.row() >= m_windowModel.size())
503 return QVariant();
505 if (role == WindowRole) {
506 Window *window = m_windowModel.at(index.row()).window;
507 return QVariant::fromValue(window);
508 } else if (role == ApplicationRole) {
509 return QVariant::fromValue(m_windowModel.at(index.row()).application);
510 } else {
511 return QVariant();
512 }
515void TopLevelWindowModel::connectApplicationManager()
517 connect(m_applicationManager, &QAbstractItemModel::rowsInserted,
518 this, [this](const QModelIndex &/*parent*/, int first, int last) {
519 for (int i = first; i <= last; ++i) {
520 auto application = m_applicationManager->get(i);
521 addApplication(application);
522 }
523 });
525 connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved,
526 this, [this](const QModelIndex &/*parent*/, int first, int last) {
527 for (int i = first; i <= last; ++i) {
528 auto application = m_applicationManager->get(i);
529 removeApplication(application);
530 }
531 });
535int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
537 for (int i=0; i<m_windowModel.count(); i++) {
538 if (m_windowModel[i].window->surface() == surface) {
539 return i;
540 }
541 }
542 return -1;
545int TopLevelWindowModel::generateId()
547 int id = m_nextId;
548 m_nextId = nextFreeId(nextId(id), id);
549 return id;
552int TopLevelWindowModel::nextId(int id) const
554 if (id == m_maxId) {
555 return id = 1;
556 } else {
557 return id + 1;
558 }
561int TopLevelWindowModel::nextFreeId(int candidateId, const int latestId)
563 int firstCandidateId = candidateId;
565 while (indexForId(candidateId) != -1 || candidateId == latestId) {
566 candidateId = nextId(candidateId);
568 if (candidateId == firstCandidateId) {
569 qFatal("TopLevelWindowModel: run out of window ids.");
570 }
571 }
573 return candidateId;
576QString TopLevelWindowModel::toString()
578 QString str;
579 for (int i = 0; i < m_windowModel.count(); ++i) {
580 auto item = m_windowModel.at(i);
582 QString itemStr = QString("(index=%1,appId=%2,surface=0x%3,id=%4)")
583 .arg(QString::number(i),
584 item.application->appId(),
585 QString::number((qintptr)item.window->surface(), 16),
586 QString::number(item.window->id()));
588 if (i > 0) {
589 str.append(",");
590 }
591 str.append(itemStr);
592 }
593 return str;
596int TopLevelWindowModel::indexOf(unityapi::MirSurfaceInterface *surface)
598 for (int i = 0; i < m_windowModel.count(); ++i) {
599 if (m_windowModel.at(i).window->surface() == surface) {
600 return i;
601 }
602 }
603 return -1;
606int TopLevelWindowModel::indexForId(int id) const
608 for (int i = 0; i < m_windowModel.count(); ++i) {
609 if (m_windowModel[i].window->id() == id) {
610 return i;
611 }
612 }
613 return -1;
616Window *TopLevelWindowModel::windowAt(int index) const
618 if (index >=0 && index < m_windowModel.count()) {
619 return m_windowModel[index].window;
620 } else {
621 return nullptr;
622 }
625unityapi::MirSurfaceInterface *TopLevelWindowModel::surfaceAt(int index) const
627 if (index >=0 && index < m_windowModel.count()) {
628 return m_windowModel[index].window->surface();
629 } else {
630 return nullptr;
631 }
634unityapi::ApplicationInfoInterface *TopLevelWindowModel::applicationAt(int index) const
636 if (index >=0 && index < m_windowModel.count()) {
637 return m_windowModel[index].application;
638 } else {
639 return nullptr;
640 }
643int TopLevelWindowModel::idAt(int index) const
645 if (index >=0 && index < m_windowModel.count()) {
646 return m_windowModel[index].window->id();
647 } else {
648 return 0;
649 }
652void TopLevelWindowModel::raiseId(int id)
654 if (m_modelState == IdleState) {
655 DEBUG_MSG << "(id=" << id << ") - do it now.";
656 doRaiseId(id);
657 } else {
658 DEBUG_MSG << "(id=" << id << ") - Model busy (modelState=" << m_modelState << "). Try again in the next event loop.";
659 // The model has just signalled some change. If we have a Repeater responding to this update, it will get nuts
660 // if we perform yet another model change straight away.
661 //
662 // A bad sympton of this problem is a Repeater.itemAt(index) call returning null event though Repeater.count says
663 // the index is definitely within bounds.
664 QMetaObject::invokeMethod(this, "raiseId", Qt::QueuedConnection, Q_ARG(int, id));
665 }
668void TopLevelWindowModel::doRaiseId(int id)
670 int fromIndex = indexForId(id);
671 // can't raise something that doesn't exist or that it's already on top
672 if (fromIndex != -1 && fromIndex != 0) {
673 auto surface = m_windowModel[fromIndex].window->surface();
674 if (surface) {
675 m_surfaceManager->raise(surface);
676 } else {
677 // move it ourselves. Since there's no mir::scene::Surface/miral::Window, there's nothing
678 // miral can do about it.
679 move(fromIndex, 0);
680 }
681 }
684void TopLevelWindowModel::setFocusedWindow(Window *window)
686 if (window != m_focusedWindow) {
687 INFO_MSG << "(" << window << ")";
689 Window* previousWindow = m_focusedWindow;
691 m_focusedWindow = window;
692 Q_EMIT focusedWindowChanged(m_focusedWindow);
694 if (previousWindow && previousWindow->focused() && !previousWindow->surface()) {
695 // do it ourselves. miral doesn't know about this window
696 previousWindow->setFocused(false);
697 }
698 }
701unityapi::MirSurfaceInterface* TopLevelWindowModel::inputMethodSurface() const
703 return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
706Window* TopLevelWindowModel::focusedWindow() const
708 return m_focusedWindow;
711void TopLevelWindowModel::move(int from, int to)
713 if (from == to) return;
714 DEBUG_MSG << " from=" << from << " to=" << to;
716 if (from >= 0 && from < m_windowModel.size() && to >= 0 && to < m_windowModel.size()) {
717 QModelIndex parent;
718 /* When moving an item down, the destination index needs to be incremented
719 by one, as explained in the documentation:
720 http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */
722 Q_ASSERT(m_modelState == IdleState);
723 m_modelState = MovingState;
725 beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
726#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
727 const auto &window = m_windowModel.takeAt(from);
728 m_windowModel.insert(to, window);
729#else
730 m_windowModel.move(from, to);
731#endif
732 endMoveRows();
734 Q_EMIT listChanged();
735 m_modelState = IdleState;
737 INFO_MSG << " after " << toString();
738 }
740void TopLevelWindowModel::onModificationsStarted()
744void TopLevelWindowModel::onModificationsEnded()
746 if (m_focusedWindowChanged) {
747 setFocusedWindow(m_newlyFocusedWindow);
748 }
749 // reset
750 m_focusedWindowChanged = false;
751 m_newlyFocusedWindow = nullptr;
754void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
756 DEBUG_MSG << "(" << forbiddenId << ")";
758 for (int i = 0; i < m_windowModel.count(); ++i) {
759 Window *window = m_windowModel[i].window;
760 if (window->id() != forbiddenId) {
761 window->activate();
762 }
763 }
766void TopLevelWindowModel::refreshWindows()
768 m_windowModel.clear();
769 WindowManagementPolicy::instance()->forEachWindowInWorkspace(m_workspace->workspace(), [this](const miral::Window &window) {
770 auto surface = m_surfaceManager->surfaceFor(window);
771 if (surface) {
772 if (surface->parentSurface()) {
773 // Wrap it in a Window so that we keep focusedWindow() up to date.
774 Window *window = createWindow(surface);
775 connect(surface, &QObject::destroyed, window, [=](){
776 window->setSurface(nullptr);
777 window->deleteLater();
778 });
779 } else {
780 if (surface->type() == Mir::InputMethodType) {
781 setInputMethodWindow(createWindow(surface));
782 } else {
783 auto *application = m_applicationManager->findApplicationWithSurface(surface);
784 if (application) {
785 prependSurface(surface, application);
786 } else {
787 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
788 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
789 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
790 Window *promptWindow = createWindow(surface);
791 connect(surface, &QObject::destroyed, promptWindow, [=](){
792 promptWindow->setSurface(nullptr);
793 promptWindow->deleteLater();
794 });
795 }
796 }
797 }
798 }
799 });