@@ -120,14 +120,10 @@ void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *s
120 m_surfaceManager = surfaceManager;
120 m_surfaceManager = surfaceManager;
122 if (m_surfaceManager) {
122 if (m_surfaceManager) {
123+ connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace, this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
123 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
124 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
124 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
125 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
125 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
126 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
127− connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
128− this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
129− connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAboutToBeRemovedFromWorkspace,
130− this, &TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace);
133 refreshWindows();
129 refreshWindows();
@@ -382,7 +378,10 @@ void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral
382 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
378 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
384 if (!m_workspace || !m_applicationManager) return;
380 if (!m_workspace || !m_applicationManager) return;
385− if (workspace != m_workspace->workspace()) return;
381+ if (workspace != m_workspace->workspace()) {
382+ removeSurfaces(surfaces);
387 Q_FOREACH(auto surface, surfaces) {
386 Q_FOREACH(auto surface, surfaces) {
388 if (m_allSurfaces.contains(surface)) continue;
387 if (m_allSurfaces.contains(surface)) continue;
@@ -426,11 +425,8 @@ void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral
429−void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
430− const QVector<unity::shell::application::MirSurfaceInterface *> surfaces)
428+void TopLevelWindowModel::removeSurfaces(const QVector<unity::shell::application::MirSurfaceInterface *> surfaces)
432− if (!m_workspace || workspace != m_workspace->workspace()) return;
434 int start = -1;
430 int start = -1;
435 int end = -1;
431 int end = -1;
436 for (auto iter = surfaces.constBegin(); iter != surfaces.constEnd();) {
432 for (auto iter = surfaces.constBegin(); iter != surfaces.constEnd();) {
@@ -440,7 +436,7 @@ void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::sha
440 // Do removals in adjacent blocks.
436 // Do removals in adjacent blocks.
441 start = end = indexOf(surface);
437 start = end = indexOf(surface);
442 if (start == -1) {
438 if (start == -1) {
443− // probably a child surface
439+ // could be a child surface
444 m_allSurfaces.remove(surface);
440 m_allSurfaces.remove(surface);
445 continue;
441 continue;
@@ -538,6 +534,15 @@ void TopLevelWindowModel::setInputMethodWindow(Window *window)
538void TopLevelWindowModel::removeInputMethodWindow()
534void TopLevelWindowModel::removeInputMethodWindow()
540 if (m_inputMethodWindow) {
536 if (m_inputMethodWindow) {
537+ auto surface = m_inputMethodWindow->surface();
539+ m_allSurfaces.remove(surface);
541+ if (m_focusedWindow == m_inputMethodWindow) {
542+ setFocusedWindow(nullptr);
543+ m_focusedWindowCleared = false;
541 delete m_inputMethodWindow;
546 delete m_inputMethodWindow;
542 m_inputMethodWindow = nullptr;
547 m_inputMethodWindow = nullptr;
543 Q_EMIT inputMethodSurfaceChanged(nullptr);
548 Q_EMIT inputMethodSurfaceChanged(nullptr);
@@ -549,7 +554,7 @@ void TopLevelWindowModel::onSurfacesRaised(const QVector<unityapi::MirSurfaceInt
549 DEBUG_MSG << "(" << surfaces << ")";
554 DEBUG_MSG << "(" << surfaces << ")";
550 const int raiseCount = surfaces.size();
555 const int raiseCount = surfaces.size();
551 for (int i = 0; i < raiseCount; i++) {
556 for (int i = 0; i < raiseCount; i++) {
552− int fromIndex = findIndexOf(surfaces[i]);
557+ int fromIndex = indexOf(surfaces[i]);
553 if (fromIndex != -1) {
558 if (fromIndex != -1) {
554 move(fromIndex, 0);
559 move(fromIndex, 0);
@@ -576,16 +581,6 @@ QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
579−int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
581− for (int i=0; i<m_windowModel.count(); i++) {
582− if (m_windowModel[i].window->surface() == surface) {
589int TopLevelWindowModel::generateId()
584int TopLevelWindowModel::generateId()
591 int id = m_nextId;
586 int id = m_nextId;