on 888c73c help sign in
unity8/plugins/WindowManager/TopLevelWindowModel.cpp
829 lines 26 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 "wmpolicyinterface.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) {
69 connect(m_applicationManager, &QAbstractItemModel::rowsInserted,
70 this, [this](const QModelIndex &/*parent*/, int first, int last) {
71 if (!m_workspace || !m_workspace->isActive())
72 return;
74 for (int i = first; i <= last; ++i) {
75 auto application = m_applicationManager->get(i);
76 addApplication(application);
77 }
78 });
80 connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved,
81 this, [this](const QModelIndex &/*parent*/, int first, int last) {
82 for (int i = first; i <= last; ++i) {
83 auto application = m_applicationManager->get(i);
84 removeApplication(application);
85 }
86 });
87 }
89 Q_EMIT applicationManagerChanged(m_applicationManager);
90 refreshWindows();
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 Q_ASSERT(m_modelState == IdleState);
105 m_modelState = ResettingState;
107 beginResetModel();
109 if (m_surfaceManager) {
110 disconnect(m_surfaceManager, 0, this, 0);
111 }
113 m_surfaceManager = surfaceManager;
115 if (m_surfaceManager) {
116 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfaceCreated, this, &TopLevelWindowModel::onSurfaceCreated);
117 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
118 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
119 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
121 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
122 this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
123 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAboutToBeRemovedFromWorkspace,
124 this, &TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace);
125 }
127 refreshWindows();
128 Q_EMIT surfaceManagerChanged(m_surfaceManager);
130 endResetModel();
131 m_modelState = IdleState;
134void TopLevelWindowModel::setWorkspace(Workspace *workspace)
136 if (workspace == m_workspace) {
137 return;
138 }
140 DEBUG_MSG << "(" << workspace << ")";
142 Q_ASSERT(m_modelState == IdleState);
143 m_modelState = ResettingState;
145 beginResetModel();
147 if (m_workspace) {
148 disconnect(m_workspace, 0, this, 0);
149 }
151 m_workspace = workspace;
153 refreshWindows();
154 Q_EMIT workspaceChanged(workspace);
156 endResetModel();
157 m_modelState = IdleState;
160void TopLevelWindowModel::addApplication(unityapi::ApplicationInfoInterface *application)
162 DEBUG_MSG << "(" << application->appId() << ")";
164 if (application->state() != unityapi::ApplicationInfoInterface::Stopped && application->surfaceList()->count() == 0) {
165 prependPlaceholder(application);
166 }
169void TopLevelWindowModel::removeApplication(unityapi::ApplicationInfoInterface *application)
171 DEBUG_MSG << "(" << application->appId() << ")";
173 Q_ASSERT(m_modelState == IdleState);
175 int i = 0;
176 while (i < m_windowModel.count()) {
177 if (m_windowModel.at(i).application == application) {
178 removeAt(i);
179 } else {
180 ++i;
181 }
182 }
185void TopLevelWindowModel::prependPlaceholder(unityapi::ApplicationInfoInterface *application)
187 INFO_MSG << "(" << application->appId() << ")";
189 prependSurfaceHelper(nullptr, application);
192void TopLevelWindowModel::prependSurface(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
194 Q_ASSERT(surface != nullptr);
196 bool filledPlaceholder = false;
197 for (int i = 0; i < m_windowModel.count() && !filledPlaceholder; ++i) {
198 ModelEntry &entry = m_windowModel[i];
199 if (entry.application == application && entry.window->surface() == nullptr) {
200 entry.window->setSurface(surface);
201 m_allSurfaces.insert(surface);
202 connectSurface(surface);
203 INFO_MSG << " appId=" << application->appId() << " surface=" << surface
204 << ", filling out placeholder. after: " << toString();
205 filledPlaceholder = true;
206 }
207 }
209 if (!filledPlaceholder) {
210 INFO_MSG << " appId=" << application->appId() << " surface=" << surface << ", adding new row";
211 prependSurfaceHelper(surface, application);
212 }
215void TopLevelWindowModel::prependSurfaceHelper(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
217 if (m_modelState == IdleState) {
218 m_modelState = InsertingState;
219 beginInsertRows(QModelIndex(), 0 /*first*/, 0 /*last*/);
220 } else {
221 Q_ASSERT(m_modelState == ResettingState);
222 // No point in signaling anything if we're resetting the whole model
223 }
225 Window *window = createWindow(surface);
227 m_windowModel.prepend(ModelEntry(window, application));
228 if (surface) {
229 m_allSurfaces.insert(surface);
230 connectSurface(surface);
231 }
233 if (m_modelState == InsertingState) {
234 endInsertRows();
235 Q_EMIT countChanged();
236 Q_EMIT listChanged();
237 m_modelState = IdleState;
238 }
240 if (!surface) {
241 activateEmptyWindow(window);
242 }
244 INFO_MSG << " after " << toString();
247void TopLevelWindowModel::connectWindow(Window *window)
249 connect(window, &Window::focusRequested, this, [this, window]() {
250 if (!window->surface()) {
251 activateEmptyWindow(window);
252 }
253 });
255 connect(window, &Window::focusedChanged, this, [this, window](bool focused) {
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) {
261 Q_ASSERT(m_newlyFocusedWindow == nullptr);
262 m_focusedWindowChanged = true;
263 m_newlyFocusedWindow = window;
264 } else if (m_focusedWindow == window) {
265 m_focusedWindowChanged = true;
266 } else {
267 // don't clear the focused window if you were not there in the first place
268 // happens when a filled window gets replaced with an empty one (no surface) as the focused window.
269 }
270 }
271 });
273 connect(window, &Window::closeRequested, this, [this, window]() {
274 if (!window->surface()) {
275 // do things ourselves as miral doesn't know about this window
276 int id = window->id();
277 int index = indexForId(id);
278 bool focusOther = false;
279 Q_ASSERT(index >= 0);
280 if (window->focused()) {
281 focusOther = true;
282 }
283 m_windowModel[index].application->close();
284 if (focusOther) {
285 activateTopMostWindowWithoutId(id);
286 }
287 }
288 });
290 connect(window, &Window::emptyWindowActivated, this, [this, window]() {
291 activateEmptyWindow(window);
292 });
295void TopLevelWindowModel::activateEmptyWindow(Window *window)
297 Q_ASSERT(!window->surface());
298 DEBUG_MSG << "(" << window << ")";
300 // miral doesn't know about empty windows (ie, windows that are not backed up by MirSurfaces)
301 // So we have to activate them ourselves (instead of asking SurfaceManager to do it for us).
303 window->setFocused(true);
304 raiseId(window->id());
305 Window *previousWindow = m_focusedWindow;
306 setFocusedWindow(window);
307 if (previousWindow && previousWindow->surface() && previousWindow->surface()->focused()) {
308 m_surfaceManager->activate(nullptr);
309 }
312void TopLevelWindowModel::connectSurface(unityapi::MirSurfaceInterface *surface)
314 connect(surface, &unityapi::MirSurfaceInterface::liveChanged, this, [this, surface](bool live){
315 if (!live) {
316 onSurfaceDied(surface);
317 }
318 });
319 connect(surface, &QObject::destroyed, this, [this, surface](){ this->onSurfaceDestroyed(surface); });
322void TopLevelWindowModel::onSurfaceDied(unityapi::MirSurfaceInterface *surface)
324 if (surface->type() == Mir::InputMethodType) {
325 removeInputMethodWindow();
326 return;
327 }
329 int i = indexOf(surface);
330 if (i == -1) {
331 return;
332 }
334 auto application = m_windowModel[i].application;
336 // can't be starting if it already has a surface
337 Q_ASSERT(application->state() != unityapi::ApplicationInfoInterface::Starting);
339 if (application->state() == unityapi::ApplicationInfoInterface::Running) {
340 m_windowModel[i].removeOnceSurfaceDestroyed = true;
341 } else {
342 // assume it got killed by the out-of-memory daemon.
343 //
344 // So leave entry in the model and only remove its surface, so shell can display a screenshot
345 // in its place.
346 m_windowModel[i].removeOnceSurfaceDestroyed = false;
347 }
350void TopLevelWindowModel::onSurfaceDestroyed(unityapi::MirSurfaceInterface *surface)
352 int i = indexOf(surface);
353 if (i == -1) {
354 return;
355 }
357 if (m_windowModel[i].removeOnceSurfaceDestroyed) {
358 removeAt(i);
359 } else {
360 auto window = m_windowModel[i].window;
361 window->setSurface(nullptr);
362 window->setFocused(false);
363 m_allSurfaces.remove(surface);
364 INFO_MSG << " Removed surface from entry. After: " << toString();
365 }
368Window *TopLevelWindowModel::createWindow(unityapi::MirSurfaceInterface *surface)
370 int id = generateId();
371 Window *qmlWindow = new Window(id, this);
372 connectWindow(qmlWindow);
373 if (surface) {
374 qmlWindow->setSurface(surface);
375 }
376 return qmlWindow;
380void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface */*surface*/)
384void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
385 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
387 if (!m_workspace || !m_applicationManager) return;
388 if (workspace != m_workspace->workspace()) return;
390 Q_FOREACH(auto surface, surfaces) {
391 if (m_allSurfaces.contains(surface)) continue;
393 if (surface->parentSurface()) {
394 // Wrap it in a Window so that we keep focusedWindow() up to date.
395 Window *window = createWindow(surface);
396 connect(surface, &QObject::destroyed, window, [=](){
397 window->setSurface(nullptr);
398 window->deleteLater();
399 });
400 } else {
401 if (surface->type() == Mir::InputMethodType) {
402 setInputMethodWindow(createWindow(surface));
403 } else {
404 auto *application = m_applicationManager->findApplicationWithSurface(surface);
405 if (application) {
406 prependSurface(surface, application);
407 } else {
408 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
409 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
410 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
411 Window *promptWindow = createWindow(surface);
412 connect(surface, &QObject::destroyed, promptWindow, [=](){
413 promptWindow->setSurface(nullptr);
414 promptWindow->deleteLater();
415 });
416 }
417 }
418 }
419 }
422void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
423 const QVector<unity::shell::application::MirSurfaceInterface *> surfaces)
425 if (!m_workspace || workspace != m_workspace->workspace()) return;
427 int start = -1;
428 int end = -1;
429 for (auto iter = surfaces.constBegin(); iter != surfaces.constEnd();) {
430 auto surface = *iter;
431 iter++;
433 // Do removals in adjacent blocks.
434 start = end = indexOf(surface);
435 if (start == -1) {
436 // probably a child surface
437 m_allSurfaces.remove(surface);
438 continue;
439 }
440 while(iter != surfaces.constEnd()) {
441 int index = indexOf(*iter);
442 if (index != end+1) {
443 break;
444 }
445 end++;
446 iter++;
447 }
449 if (m_modelState == IdleState) {
450 beginRemoveRows(QModelIndex(), start, end);
451 m_modelState = RemovingState;
452 } else {
453 Q_ASSERT(m_modelState == ResettingState);
454 // No point in signaling anything if we're resetting the whole model
455 }
457 for (int index = start; index <= end; index++) {
458 auto window = m_windowModel[start].window;
459 window->setSurface(nullptr);
460 window->setFocused(false);
462 m_windowModel.removeAt(start);
463 m_allSurfaces.remove(surface);
464 }
466 if (m_modelState == RemovingState) {
467 endRemoveRows();
468 Q_EMIT countChanged();
469 Q_EMIT listChanged();
470 m_modelState = IdleState;
471 }
472 }
475void TopLevelWindowModel::removeAt(int index)
477 if (m_modelState == IdleState) {
478 beginRemoveRows(QModelIndex(), index, index);
479 m_modelState = RemovingState;
480 } else {
481 Q_ASSERT(m_modelState == ResettingState);
482 // No point in signaling anything if we're resetting the whole model
483 }
485 auto window = m_windowModel[index].window;
486 auto surface = window->surface();
488 window->setSurface(nullptr);
489 window->setFocused(false);
491 m_windowModel.removeAt(index);
492 m_allSurfaces.remove(surface);
494 if (m_modelState == RemovingState) {
495 endRemoveRows();
496 Q_EMIT countChanged();
497 Q_EMIT listChanged();
498 m_modelState = IdleState;
499 }
501 disconnect(window, 0, this, 0);
502 if (m_focusedWindow == window) {
503 setFocusedWindow(nullptr);
504 }
505 delete window;
507 INFO_MSG << " after " << toString();
510void TopLevelWindowModel::setInputMethodWindow(Window *window)
512 if (m_inputMethodWindow) {
513 qWarning("Multiple Input Method Surfaces created, removing the old one!");
514 delete m_inputMethodWindow;
515 }
516 m_inputMethodWindow = window;
517 Q_EMIT inputMethodSurfaceChanged(m_inputMethodWindow->surface());
520void TopLevelWindowModel::removeInputMethodWindow()
522 if (m_inputMethodWindow) {
523 delete m_inputMethodWindow;
524 m_inputMethodWindow = nullptr;
525 Q_EMIT inputMethodSurfaceChanged(nullptr);
526 }
529void TopLevelWindowModel::onSurfacesRaised(const QVector<unityapi::MirSurfaceInterface*> &surfaces)
531 DEBUG_MSG << "(" << surfaces << ")";
532 const int raiseCount = surfaces.size();
533 for (int i = 0; i < raiseCount; i++) {
534 int fromIndex = findIndexOf(surfaces[i]);
535 if (fromIndex != -1) {
536 move(fromIndex, 0);
537 }
538 }
541int TopLevelWindowModel::rowCount(const QModelIndex &/*parent*/) const
543 return m_windowModel.count();
546QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
548 if (index.row() < 0 || index.row() >= m_windowModel.size())
549 return QVariant();
551 if (role == WindowRole) {
552 Window *window = m_windowModel.at(index.row()).window;
553 return QVariant::fromValue(window);
554 } else if (role == ApplicationRole) {
555 return QVariant::fromValue(m_windowModel.at(index.row()).application);
556 } else {
557 return QVariant();
558 }
561int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
563 for (int i=0; i<m_windowModel.count(); i++) {
564 if (m_windowModel[i].window->surface() == surface) {
565 return i;
566 }
567 }
568 return -1;
571int TopLevelWindowModel::generateId()
573 int id = m_nextId;
574 m_nextId = nextFreeId(nextId(id), id);
575 return id;
578int TopLevelWindowModel::nextId(int id) const
580 if (id == m_maxId) {
581 return id = 1;
582 } else {
583 return id + 1;
584 }
587int TopLevelWindowModel::nextFreeId(int candidateId, const int latestId)
589 int firstCandidateId = candidateId;
591 while (indexForId(candidateId) != -1 || candidateId == latestId) {
592 candidateId = nextId(candidateId);
594 if (candidateId == firstCandidateId) {
595 qFatal("TopLevelWindowModel: run out of window ids.");
596 }
597 }
599 return candidateId;
602QString TopLevelWindowModel::toString()
604 QString str;
605 for (int i = 0; i < m_windowModel.count(); ++i) {
606 auto item = m_windowModel.at(i);
608 QString itemStr = QString("(index=%1,appId=%2,surface=0x%3,id=%4)")
609 .arg(QString::number(i),
610 item.application->appId(),
611 QString::number((qintptr)item.window->surface(), 16),
612 QString::number(item.window->id()));
614 if (i > 0) {
615 str.append(",");
616 }
617 str.append(itemStr);
618 }
619 return str;
622int TopLevelWindowModel::indexOf(unityapi::MirSurfaceInterface *surface)
624 for (int i = 0; i < m_windowModel.count(); ++i) {
625 if (m_windowModel.at(i).window->surface() == surface) {
626 return i;
627 }
628 }
629 return -1;
632int TopLevelWindowModel::indexForId(int id) const
634 for (int i = 0; i < m_windowModel.count(); ++i) {
635 if (m_windowModel[i].window->id() == id) {
636 return i;
637 }
638 }
639 return -1;
642Window *TopLevelWindowModel::windowAt(int index) const
644 if (index >=0 && index < m_windowModel.count()) {
645 return m_windowModel[index].window;
646 } else {
647 return nullptr;
648 }
651unityapi::MirSurfaceInterface *TopLevelWindowModel::surfaceAt(int index) const
653 if (index >=0 && index < m_windowModel.count()) {
654 return m_windowModel[index].window->surface();
655 } else {
656 return nullptr;
657 }
660unityapi::ApplicationInfoInterface *TopLevelWindowModel::applicationAt(int index) const
662 if (index >=0 && index < m_windowModel.count()) {
663 return m_windowModel[index].application;
664 } else {
665 return nullptr;
666 }
669int TopLevelWindowModel::idAt(int index) const
671 if (index >=0 && index < m_windowModel.count()) {
672 return m_windowModel[index].window->id();
673 } else {
674 return 0;
675 }
678void TopLevelWindowModel::raiseId(int id)
680 if (m_modelState == IdleState) {
681 DEBUG_MSG << "(id=" << id << ") - do it now.";
682 doRaiseId(id);
683 } else {
684 DEBUG_MSG << "(id=" << id << ") - Model busy (modelState=" << m_modelState << "). Try again in the next event loop.";
685 // The model has just signalled some change. If we have a Repeater responding to this update, it will get nuts
686 // if we perform yet another model change straight away.
687 //
688 // A bad sympton of this problem is a Repeater.itemAt(index) call returning null event though Repeater.count says
689 // the index is definitely within bounds.
690 QMetaObject::invokeMethod(this, "raiseId", Qt::QueuedConnection, Q_ARG(int, id));
691 }
694void TopLevelWindowModel::doRaiseId(int id)
696 int fromIndex = indexForId(id);
697 // can't raise something that doesn't exist or that it's already on top
698 if (fromIndex != -1 && fromIndex != 0) {
699 auto surface = m_windowModel[fromIndex].window->surface();
700 if (surface) {
701 m_surfaceManager->raise(surface);
702 } else {
703 // move it ourselves. Since there's no mir::scene::Surface/miral::Window, there's nothing
704 // miral can do about it.
705 move(fromIndex, 0);
706 }
707 }
710void TopLevelWindowModel::setFocusedWindow(Window *window)
712 if (window != m_focusedWindow) {
713 INFO_MSG << "(" << window << ")";
715 Window* previousWindow = m_focusedWindow;
717 m_focusedWindow = window;
718 Q_EMIT focusedWindowChanged(m_focusedWindow);
720 if (previousWindow && previousWindow->focused() && !previousWindow->surface()) {
721 // do it ourselves. miral doesn't know about this window
722 previousWindow->setFocused(false);
723 }
724 }
727unityapi::MirSurfaceInterface* TopLevelWindowModel::inputMethodSurface() const
729 return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
732Window* TopLevelWindowModel::focusedWindow() const
734 return m_focusedWindow;
737void TopLevelWindowModel::move(int from, int to)
739 if (from == to) return;
740 DEBUG_MSG << " from=" << from << " to=" << to;
742 if (from >= 0 && from < m_windowModel.size() && to >= 0 && to < m_windowModel.size()) {
743 QModelIndex parent;
744 /* When moving an item down, the destination index needs to be incremented
745 by one, as explained in the documentation:
746 http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */
748 Q_ASSERT(m_modelState == IdleState);
749 m_modelState = MovingState;
751 beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
752#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
753 const auto &window = m_windowModel.takeAt(from);
754 m_windowModel.insert(to, window);
755#else
756 m_windowModel.move(from, to);
757#endif
758 endMoveRows();
760 Q_EMIT listChanged();
761 m_modelState = IdleState;
763 INFO_MSG << " after " << toString();
764 }
766void TopLevelWindowModel::onModificationsStarted()
770void TopLevelWindowModel::onModificationsEnded()
772 if (m_focusedWindowChanged) {
773 setFocusedWindow(m_newlyFocusedWindow);
774 }
775 // reset
776 m_focusedWindowChanged = false;
777 m_newlyFocusedWindow = nullptr;
780void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
782 DEBUG_MSG << "(" << forbiddenId << ")";
784 for (int i = 0; i < m_windowModel.count(); ++i) {
785 Window *window = m_windowModel[i].window;
786 if (window->id() != forbiddenId) {
787 window->activate();
788 }
789 }
792void TopLevelWindowModel::refreshWindows()
794 DEBUG_MSG << "()";
796 m_windowModel.clear();
797 m_allSurfaces.clear();
799 if (!m_workspace || !m_applicationManager || !m_surfaceManager) return;
801 m_surfaceManager->forEachSurfaceInWorkspace(m_workspace->workspace(), [this](unity::shell::application::MirSurfaceInterface* surface) {
802 if (surface->parentSurface()) {
803 // Wrap it in a Window so that we keep focusedWindow() up to date.
804 Window *window = createWindow(surface);
805 connect(surface, &QObject::destroyed, window, [=](){
806 window->setSurface(nullptr);
807 window->deleteLater();
808 });
809 } else {
810 if (surface->type() == Mir::InputMethodType) {
811 setInputMethodWindow(createWindow(surface));
812 } else {
813 auto *application = m_applicationManager->findApplicationWithSurface(surface);
814 if (application) {
815 prependSurface(surface, application);
816 } else {
817 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
818 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
819 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
820 Window *promptWindow = createWindow(surface);
821 connect(surface, &QObject::destroyed, promptWindow, [=](){
822 promptWindow->setSurface(nullptr);
823 promptWindow->deleteLater();
824 });
825 }
826 }
827 }
828 });