@@ -198,6 +198,7 @@ void TopLevelWindowModel::prependSurface(unityapi::MirSurfaceInterface *surface,
198 ModelEntry &entry = m_windowModel[i];
198 ModelEntry &entry = m_windowModel[i];
199 if (entry.application == application && entry.window->surface() == nullptr) {
199 if (entry.application == application && entry.window->surface() == nullptr) {
200 entry.window->setSurface(surface);
200 entry.window->setSurface(surface);
201+ m_allSurfaces.insert(surface);
201 connectSurface(surface);
202 connectSurface(surface);
202 INFO_MSG << " appId=" << application->appId() << " surface=" << surface
203 INFO_MSG << " appId=" << application->appId() << " surface=" << surface
203 << ", filling out placeholder. after: " << toString();
204 << ", filling out placeholder. after: " << toString();
@@ -224,8 +225,8 @@ void TopLevelWindowModel::prependSurfaceHelper(unityapi::MirSurfaceInterface *su
224 Window *window = createWindow(surface);
225 Window *window = createWindow(surface);
226 m_windowModel.prepend(ModelEntry(window, application));
227 m_windowModel.prepend(ModelEntry(window, application));
227− m_allSurfaces.insert(surface);
228 if (surface) {
228 if (surface) {
229+ m_allSurfaces.insert(surface);
229 connectSurface(surface);
230 connectSurface(surface);
@@ -436,7 +437,7 @@ void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::sha
436 m_allSurfaces.remove(surface);
437 m_allSurfaces.remove(surface);
437 continue;
438 continue;
439− while(iter != surfaces.constEnd()) {
440+ while(iter != surfaces.constEnd()) {
440 int index = indexOf(*iter);
441 int index = indexOf(*iter);
441 if (index != end+1) {
442 if (index != end+1) {
@@ -459,7 +460,7 @@ void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::sha
459 window->setFocused(false);
460 window->setFocused(false);
461 m_windowModel.removeAt(start);
462 m_windowModel.removeAt(start);
462− m_allSurfaces.remove(window->surface());
463+ m_allSurfaces.remove(surface);
465 if (m_modelState == RemovingState) {
466 if (m_modelState == RemovingState) {
@@ -482,12 +483,13 @@ void TopLevelWindowModel::removeAt(int index)
484 auto window = m_windowModel[index].window;
485 auto window = m_windowModel[index].window;
486+ auto surface = window->surface();
486 window->setSurface(nullptr);
488 window->setSurface(nullptr);
487 window->setFocused(false);
489 window->setFocused(false);
489 m_windowModel.removeAt(index);
491 m_windowModel.removeAt(index);
490− m_allSurfaces.remove(window->surface());
492+ m_allSurfaces.remove(surface);
492 if (m_modelState == RemovingState) {
494 if (m_modelState == RemovingState) {
493 endRemoveRows();
495 endRemoveRows();
@@ -794,34 +796,32 @@ void TopLevelWindowModel::refreshWindows()
794 m_windowModel.clear();
796 m_windowModel.clear();
795 m_allSurfaces.clear();
797 m_allSurfaces.clear();
797− if (!m_workspace || !m_applicationManager) return;
799+ if (!m_workspace || !m_applicationManager || !m_surfaceManager) return;
798− WMPolicyInterface::instance()->forEachWindowInWorkspace(m_workspace->workspace(), [this](const miral::Window &window) {
800+
799− auto surface = m_surfaceManager->surfaceFor(window);
801+ m_surfaceManager->forEachSurfaceInWorkspace(m_workspace->workspace(), [this](unity::shell::application::MirSurfaceInterface* surface) {
801− if (surface->parentSurface()) {
802+ if (surface->parentSurface()) {
802− // Wrap it in a Window so that we keep focusedWindow() up to date.
803+ // Wrap it in a Window so that we keep focusedWindow() up to date.
803− Window *window = createWindow(surface);
804+ Window *window = createWindow(surface);
804− connect(surface, &QObject::destroyed, window, [=](){
805+ connect(surface, &QObject::destroyed, window, [=](){
805− window->setSurface(nullptr);
806+ window->setSurface(nullptr);
806− window->deleteLater();
807+ window->deleteLater();
810+ if (surface->type() == Mir::InputMethodType) {
811+ setInputMethodWindow(createWindow(surface));
809− if (surface->type() == Mir::InputMethodType) {
813+ auto *application = m_applicationManager->findApplicationWithSurface(surface);
810− setInputMethodWindow(createWindow(surface));
814+ if (application) {
815+ prependSurface(surface, application);
812− auto *application = m_applicationManager->findApplicationWithSurface(surface);
814− prependSurface(surface, application);
816− // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
817+ // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
817− // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
818+ // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
818− // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
819+ // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
819− Window *promptWindow = createWindow(surface);
820+ Window *promptWindow = createWindow(surface);
820− connect(surface, &QObject::destroyed, promptWindow, [=](){
821+ connect(surface, &QObject::destroyed, promptWindow, [=](){
821− promptWindow->setSurface(nullptr);
822+ promptWindow->setSurface(nullptr);
822− promptWindow->deleteLater();
823+ promptWindow->deleteLater();