on bcbc40d help sign in
unity8/plugins/WindowManager/TopLevelWindowModel.cpp
845 lines 27 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 m_focusedWindowChanged = true;
262 m_newlyFocusedWindow = window;
263 } else if (m_focusedWindow == window) {
264 m_focusedWindowChanged = true;
265 } else {
266 // don't clear the focused window if you were not there in the first place
267 // happens when a filled window gets replaced with an empty one (no surface) as the focused window.
268 }
269 }
270 });
272 connect(window, &Window::closeRequested, this, [this, window]() {
273 if (!window->surface()) {
274 // do things ourselves as miral doesn't know about this window
275 int id = window->id();
276 int index = indexForId(id);
277 bool focusOther = false;
278 Q_ASSERT(index >= 0);
279 if (window->focused()) {
280 focusOther = true;
281 }
282 m_windowModel[index].application->close();
283 if (focusOther) {
284 activateTopMostWindowWithoutId(id);
285 }
286 }
287 });
289 connect(window, &Window::emptyWindowActivated, this, [this, window]() {
290 activateEmptyWindow(window);
291 });
294void TopLevelWindowModel::activateEmptyWindow(Window *window)
296 Q_ASSERT(!window->surface());
297 DEBUG_MSG << "(" << window << ")";
299 // miral doesn't know about empty windows (ie, windows that are not backed up by MirSurfaces)
300 // So we have to activate them ourselves (instead of asking SurfaceManager to do it for us).
302 window->setFocused(true);
303 raiseId(window->id());
304 Window *previousWindow = m_focusedWindow;
305 setFocusedWindow(window);
306 if (previousWindow && previousWindow->surface() && previousWindow->surface()->focused()) {
307 m_surfaceManager->activate(nullptr);
308 }
311void TopLevelWindowModel::connectSurface(unityapi::MirSurfaceInterface *surface)
313 connect(surface, &unityapi::MirSurfaceInterface::liveChanged, this, [this, surface](bool live){
314 if (!live) {
315 onSurfaceDied(surface);
316 }
317 });
318 connect(surface, &QObject::destroyed, this, [this, surface](){ this->onSurfaceDestroyed(surface); });
321void TopLevelWindowModel::onSurfaceDied(unityapi::MirSurfaceInterface *surface)
323 if (surface->type() == Mir::InputMethodType) {
324 removeInputMethodWindow();
325 return;
326 }
328 int i = indexOf(surface);
329 if (i == -1) {
330 return;
331 }
333 auto application = m_windowModel[i].application;
335 // can't be starting if it already has a surface
336 Q_ASSERT(application->state() != unityapi::ApplicationInfoInterface::Starting);
338 if (application->state() == unityapi::ApplicationInfoInterface::Running) {
339 m_windowModel[i].removeOnceSurfaceDestroyed = true;
340 } else {
341 // assume it got killed by the out-of-memory daemon.
342 //
343 // So leave entry in the model and only remove its surface, so shell can display a screenshot
344 // in its place.
345 m_windowModel[i].removeOnceSurfaceDestroyed = false;
346 }
349void TopLevelWindowModel::onSurfaceDestroyed(unityapi::MirSurfaceInterface *surface)
351 int i = indexOf(surface);
352 if (i == -1) {
353 return;
354 }
356 if (m_windowModel[i].removeOnceSurfaceDestroyed) {
357 removeAt(i);
358 } else {
359 auto window = m_windowModel[i].window;
360 window->setSurface(nullptr);
361 window->setFocused(false);
362 m_allSurfaces.remove(surface);
363 INFO_MSG << " Removed surface from entry. After: " << toString();
364 }
367Window *TopLevelWindowModel::createWindow(unityapi::MirSurfaceInterface *surface)
369 int id = generateId();
370 Window *qmlWindow = new Window(id, this);
371 connectWindow(qmlWindow);
372 if (surface) {
373 qmlWindow->setSurface(surface);
374 }
375 return qmlWindow;
379void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface */*surface*/)
383void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
384 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
386 if (!m_workspace || !m_applicationManager) return;
387 if (workspace != m_workspace->workspace()) return;
389 Q_FOREACH(auto surface, surfaces) {
390 if (m_allSurfaces.contains(surface)) continue;
392 if (surface->parentSurface()) {
393 // Wrap it in a Window so that we keep focusedWindow() up to date.
394 Window *window = createWindow(surface);
395 connect(surface, &QObject::destroyed, window, [=](){
396 window->setSurface(nullptr);
397 window->deleteLater();
398 });
399 } else {
400 if (surface->type() == Mir::InputMethodType) {
401 setInputMethodWindow(createWindow(surface));
402 } else {
403 auto *application = m_applicationManager->findApplicationWithSurface(surface);
404 if (application) {
405 prependSurface(surface, application);
406 } else {
407 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
408 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
409 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
410 Window *promptWindow = createWindow(surface);
411 connect(surface, &QObject::destroyed, promptWindow, [=](){
412 promptWindow->setSurface(nullptr);
413 promptWindow->deleteLater();
414 });
415 }
416 }
417 }
418 }
421void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
422 const QVector<unity::shell::application::MirSurfaceInterface *> surfaces)
424 if (!m_workspace || workspace != m_workspace->workspace()) return;
426 int start = -1;
427 int end = -1;
428 for (auto iter = surfaces.constBegin(); iter != surfaces.constEnd();) {
429 auto surface = *iter;
430 iter++;
432 // Do removals in adjacent blocks.
433 start = end = indexOf(surface);
434 if (start == -1) {
435 // probably a child surface
436 m_allSurfaces.remove(surface);
437 continue;
438 }
439 while(iter != surfaces.constEnd()) {
440 int index = indexOf(*iter);
441 if (index != end+1) {
442 break;
443 }
444 end++;
445 iter++;
446 }
448 if (m_modelState == IdleState) {
449 beginRemoveRows(QModelIndex(), start, end);
450 m_modelState = RemovingState;
451 } else {
452 Q_ASSERT(m_modelState == ResettingState);
453 // No point in signaling anything if we're resetting the whole model
454 }
456 for (int index = start; index <= end; index++) {
457 auto window = m_windowModel[start].window;
458 window->setSurface(nullptr);
459 window->setFocused(false);
461 m_windowModel.removeAt(start);
462 m_allSurfaces.remove(surface);
463 }
465 if (m_modelState == RemovingState) {
466 endRemoveRows();
467 Q_EMIT countChanged();
468 Q_EMIT listChanged();
469 m_modelState = IdleState;
470 }
471 }
474void TopLevelWindowModel::removeAt(int index)
476 if (m_modelState == IdleState) {
477 beginRemoveRows(QModelIndex(), index, index);
478 m_modelState = RemovingState;
479 } else {
480 Q_ASSERT(m_modelState == ResettingState);
481 // No point in signaling anything if we're resetting the whole model
482 }
484 auto window = m_windowModel[index].window;
485 auto surface = window->surface();
487 window->setSurface(nullptr);
488 window->setFocused(false);
490 m_windowModel.removeAt(index);
491 m_allSurfaces.remove(surface);
493 if (m_modelState == RemovingState) {
494 endRemoveRows();
495 Q_EMIT countChanged();
496 Q_EMIT listChanged();
497 m_modelState = IdleState;
498 }
500 disconnect(window, 0, this, 0);
501 if (m_focusedWindow == window) {
502 setFocusedWindow(nullptr);
503 }
504 if (m_newlyFocusedWindow == window) {
505 m_focusedWindowChanged = false;
506 m_newlyFocusedWindow = nullptr;
507 }
508 delete window;
510 INFO_MSG << " after " << toString();
513void TopLevelWindowModel::setInputMethodWindow(Window *window)
515 if (m_inputMethodWindow) {
516 qWarning("Multiple Input Method Surfaces created, removing the old one!");
517 delete m_inputMethodWindow;
518 }
519 m_inputMethodWindow = window;
520 Q_EMIT inputMethodSurfaceChanged(m_inputMethodWindow->surface());
523void TopLevelWindowModel::removeInputMethodWindow()
525 if (m_inputMethodWindow) {
526 delete m_inputMethodWindow;
527 m_inputMethodWindow = nullptr;
528 Q_EMIT inputMethodSurfaceChanged(nullptr);
529 }
532void TopLevelWindowModel::onSurfacesRaised(const QVector<unityapi::MirSurfaceInterface*> &surfaces)
534 DEBUG_MSG << "(" << surfaces << ")";
535 const int raiseCount = surfaces.size();
536 for (int i = 0; i < raiseCount; i++) {
537 int fromIndex = findIndexOf(surfaces[i]);
538 if (fromIndex != -1) {
539 move(fromIndex, 0);
540 }
541 }
544int TopLevelWindowModel::rowCount(const QModelIndex &/*parent*/) const
546 return m_windowModel.count();
549QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
551 if (index.row() < 0 || index.row() >= m_windowModel.size())
552 return QVariant();
554 if (role == WindowRole) {
555 Window *window = m_windowModel.at(index.row()).window;
556 return QVariant::fromValue(window);
557 } else if (role == ApplicationRole) {
558 return QVariant::fromValue(m_windowModel.at(index.row()).application);
559 } else {
560 return QVariant();
561 }
564int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
566 for (int i=0; i<m_windowModel.count(); i++) {
567 if (m_windowModel[i].window->surface() == surface) {
568 return i;
569 }
570 }
571 return -1;
574int TopLevelWindowModel::generateId()
576 int id = m_nextId;
577 m_nextId = nextFreeId(nextId(id), id);
578 return id;
581int TopLevelWindowModel::nextId(int id) const
583 if (id == m_maxId) {
584 return id = 1;
585 } else {
586 return id + 1;
587 }
590int TopLevelWindowModel::nextFreeId(int candidateId, const int latestId)
592 int firstCandidateId = candidateId;
594 while (indexForId(candidateId) != -1 || candidateId == latestId) {
595 candidateId = nextId(candidateId);
597 if (candidateId == firstCandidateId) {
598 qFatal("TopLevelWindowModel: run out of window ids.");
599 }
600 }
602 return candidateId;
605QString TopLevelWindowModel::toString()
607 QString str;
608 for (int i = 0; i < m_windowModel.count(); ++i) {
609 auto item = m_windowModel.at(i);
611 QString itemStr = QString("(index=%1,appId=%2,surface=0x%3,id=%4)")
612 .arg(QString::number(i),
613 item.application->appId(),
614 QString::number((qintptr)item.window->surface(), 16),
615 QString::number(item.window->id()));
617 if (i > 0) {
618 str.append(",");
619 }
620 str.append(itemStr);
621 }
622 return str;
625int TopLevelWindowModel::indexOf(unityapi::MirSurfaceInterface *surface)
627 for (int i = 0; i < m_windowModel.count(); ++i) {
628 if (m_windowModel.at(i).window->surface() == surface) {
629 return i;
630 }
631 }
632 return -1;
635int TopLevelWindowModel::indexForId(int id) const
637 for (int i = 0; i < m_windowModel.count(); ++i) {
638 if (m_windowModel[i].window->id() == id) {
639 return i;
640 }
641 }
642 return -1;
645Window *TopLevelWindowModel::windowAt(int index) const
647 if (index >=0 && index < m_windowModel.count()) {
648 return m_windowModel[index].window;
649 } else {
650 return nullptr;
651 }
654unityapi::MirSurfaceInterface *TopLevelWindowModel::surfaceAt(int index) const
656 if (index >=0 && index < m_windowModel.count()) {
657 return m_windowModel[index].window->surface();
658 } else {
659 return nullptr;
660 }
663unityapi::ApplicationInfoInterface *TopLevelWindowModel::applicationAt(int index) const
665 if (index >=0 && index < m_windowModel.count()) {
666 return m_windowModel[index].application;
667 } else {
668 return nullptr;
669 }
672int TopLevelWindowModel::idAt(int index) const
674 if (index >=0 && index < m_windowModel.count()) {
675 return m_windowModel[index].window->id();
676 } else {
677 return 0;
678 }
681void TopLevelWindowModel::raiseId(int id)
683 if (m_modelState == IdleState) {
684 DEBUG_MSG << "(id=" << id << ") - do it now.";
685 doRaiseId(id);
686 } else {
687 DEBUG_MSG << "(id=" << id << ") - Model busy (modelState=" << m_modelState << "). Try again in the next event loop.";
688 // The model has just signalled some change. If we have a Repeater responding to this update, it will get nuts
689 // if we perform yet another model change straight away.
690 //
691 // A bad sympton of this problem is a Repeater.itemAt(index) call returning null event though Repeater.count says
692 // the index is definitely within bounds.
693 QMetaObject::invokeMethod(this, "raiseId", Qt::QueuedConnection, Q_ARG(int, id));
694 }
697void TopLevelWindowModel::doRaiseId(int id)
699 int fromIndex = indexForId(id);
700 // can't raise something that doesn't exist or that it's already on top
701 if (fromIndex != -1 && fromIndex != 0) {
702 auto surface = m_windowModel[fromIndex].window->surface();
703 if (surface) {
704 m_surfaceManager->raise(surface);
705 } else {
706 // move it ourselves. Since there's no mir::scene::Surface/miral::Window, there's nothing
707 // miral can do about it.
708 move(fromIndex, 0);
709 }
710 }
713void TopLevelWindowModel::setFocusedWindow(Window *window)
715 if (window != m_focusedWindow) {
716 INFO_MSG << "(" << window << ")";
718 Window* previousWindow = m_focusedWindow;
720 m_focusedWindow = window;
721 Q_EMIT focusedWindowChanged(m_focusedWindow);
723 if (previousWindow && previousWindow->focused() && !previousWindow->surface()) {
724 // do it ourselves. miral doesn't know about this window
725 previousWindow->setFocused(false);
726 }
727 }
730unityapi::MirSurfaceInterface* TopLevelWindowModel::inputMethodSurface() const
732 return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
735Window* TopLevelWindowModel::focusedWindow() const
737 return m_focusedWindow;
740void TopLevelWindowModel::move(int from, int to)
742 if (from == to) return;
743 DEBUG_MSG << " from=" << from << " to=" << to;
745 if (from >= 0 && from < m_windowModel.size() && to >= 0 && to < m_windowModel.size()) {
746 QModelIndex parent;
747 /* When moving an item down, the destination index needs to be incremented
748 by one, as explained in the documentation:
749 http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */
751 Q_ASSERT(m_modelState == IdleState);
752 m_modelState = MovingState;
754 beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
755#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
756 const auto &window = m_windowModel.takeAt(from);
757 m_windowModel.insert(to, window);
758#else
759 m_windowModel.move(from, to);
760#endif
761 endMoveRows();
763 Q_EMIT listChanged();
764 m_modelState = IdleState;
766 INFO_MSG << " after " << toString();
767 }
769void TopLevelWindowModel::onModificationsStarted()
773void TopLevelWindowModel::onModificationsEnded()
775 if (m_focusedWindowChanged) {
776 setFocusedWindow(m_newlyFocusedWindow);
777 }
778 // reset
779 m_focusedWindowChanged = false;
780 m_newlyFocusedWindow = nullptr;
783void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
785 DEBUG_MSG << "(" << forbiddenId << ")";
787 for (int i = 0; i < m_windowModel.count(); ++i) {
788 Window *window = m_windowModel[i].window;
789 if (window->id() != forbiddenId) {
790 window->activate();
791 }
792 }
795void TopLevelWindowModel::refreshWindows()
797 DEBUG_MSG << "()";
798 clear();
800 if (!m_workspace || !m_applicationManager || !m_surfaceManager) return;
802 m_surfaceManager->forEachSurfaceInWorkspace(m_workspace->workspace(), [this](unity::shell::application::MirSurfaceInterface* surface) {
803 if (surface->parentSurface()) {
804 // Wrap it in a Window so that we keep focusedWindow() up to date.
805 Window *window = createWindow(surface);
806 connect(surface, &QObject::destroyed, window, [=](){
807 window->setSurface(nullptr);
808 window->deleteLater();
809 });
810 } else {
811 if (surface->type() == Mir::InputMethodType) {
812 setInputMethodWindow(createWindow(surface));
813 } else {
814 auto *application = m_applicationManager->findApplicationWithSurface(surface);
815 if (application) {
816 prependSurface(surface, application);
817 } else {
818 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
819 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
820 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
821 Window *promptWindow = createWindow(surface);
822 connect(surface, &QObject::destroyed, promptWindow, [=](){
823 promptWindow->setSurface(nullptr);
824 promptWindow->deleteLater();
825 });
826 }
827 }
828 }
829 });
832void TopLevelWindowModel::clear()
834 DEBUG_MSG << "()";
836 while(m_windowModel.count() > 0) {
837 ModelEntry entry = m_windowModel.takeAt(0);
838 disconnect(entry.window, 0, this, 0);
839 delete entry.window;
840 }
841 m_allSurfaces.clear();
842 setFocusedWindow(nullptr);
843 m_focusedWindowChanged = false;
844 m_newlyFocusedWindow = nullptr;