on xenial help sign in
dynamic remove surface
a705d30Nick Dedekind
plugins/WindowManager/TopLevelWindowModel.cpp+56−1
@@ -35,7 +35,7 @@
35#include <qtmir/mirserverapplication.h>
35#include <qtmir/mirserverapplication.h>
36#include <qtmir/windowmodelnotifier.h>
36#include <qtmir/windowmodelnotifier.h>
37
37
38−Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel")
38+Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel", QtInfoMsg)
39
39
40#define DEBUG_MSG qCDebug(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
40#define DEBUG_MSG qCDebug(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
41#define INFO_MSG qCInfo(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
41#define INFO_MSG qCInfo(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
@@ -109,6 +109,8 @@ void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *s
109
109
110 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
110 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
111 this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
111 this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
112+ connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAboutToBeRemovedFromWorkspace,
113+ this, &TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace);
112
114
113 if (m_workspace && m_applicationManager) {
115 if (m_workspace && m_applicationManager) {
114 refreshWindows();
116 refreshWindows();
@@ -431,6 +433,59 @@ void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral
431 }
433 }
432}
434}
433
435
436+void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
437+ const QVector<unity::shell::application::MirSurfaceInterface *> surfaces)
438+{
439+ if (workspace != m_workspace->workspace()) return;
440+
441+ int start = -1;
442+ int end = -1;
443+ for (auto iter = surfaces.constBegin(); iter != surfaces.constEnd();) {
444+ auto surface = *iter;
445+ iter++;
446+
447+ // Do removals in adjacent blocks.
448+ start = end = indexOf(surface);
449+ if (start == -1) {
450+ // probably a child surface
451+ m_allSurfaces.remove(surface);
452+ continue;
453+ }
454+ while(iter != surfaces.constEnd()) {
455+ int index = indexOf(*iter);
456+ if (index != end+1) {
457+ break;
458+ }
459+ end++;
460+ iter++;
461+ }
462+
463+ if (m_modelState == IdleState) {
464+ beginRemoveRows(QModelIndex(), start, end);
465+ m_modelState = RemovingState;
466+ } else {
467+ Q_ASSERT(m_modelState == ResettingState);
468+ // No point in signaling anything if we're resetting the whole model
469+ }
470+
471+ for (int index = start; index <= end; index++) {
472+ auto window = m_windowModel[start].window;
473+ window->setSurface(nullptr);
474+ window->setFocused(false);
475+
476+ m_windowModel.removeAt(start);
477+ m_allSurfaces.remove(window->surface());
478+ }
479+
480+ if (m_modelState == RemovingState) {
481+ endRemoveRows();
482+ Q_EMIT countChanged();
483+ Q_EMIT listChanged();
484+ m_modelState = IdleState;
485+ }
486+ }
487+}
488+
434void TopLevelWindowModel::removeAt(int index)
489void TopLevelWindowModel::removeAt(int index)
435{
490{
436 if (m_modelState == IdleState) {
491 if (m_modelState == IdleState) {
plugins/WindowManager/TopLevelWindowModel.h+4−1
@@ -195,7 +195,10 @@ Q_SIGNALS:
195
195
196private Q_SLOTS:
196private Q_SLOTS:
197 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
197 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
198− void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace, const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
198+ void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
199+ const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
200+ void onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
201+ const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
199 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
202 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
200
203
201 void onModificationsStarted();
204 void onModificationsStarted();