on xenial help sign in
Mock fixes & test fixes
8cd3b33Nick Dedekind
plugins/WindowManager/TopLevelWindowModel.cpp+17−22
@@ -120,14 +120,10 @@ void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *s
120 m_surfaceManager = surfaceManager;
120 m_surfaceManager = surfaceManager;
121
121
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);
126−
127− connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
128− this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
129− connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAboutToBeRemovedFromWorkspace,
130− this, &TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace);
131 }
127 }
132
128
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)
383{
379{
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);
383+ return;
384+ }
386
385
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
426 }
425 }
427}
426}
428
427
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)
431{
429{
432− if (!m_workspace || workspace != m_workspace->workspace()) return;
433−
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;
446 }
442 }
@@ -538,6 +534,15 @@ void TopLevelWindowModel::setInputMethodWindow(Window *window)
538void TopLevelWindowModel::removeInputMethodWindow()
534void TopLevelWindowModel::removeInputMethodWindow()
539{
535{
540 if (m_inputMethodWindow) {
536 if (m_inputMethodWindow) {
537+ auto surface = m_inputMethodWindow->surface();
538+ if (surface) {
539+ m_allSurfaces.remove(surface);
540+ }
541+ if (m_focusedWindow == m_inputMethodWindow) {
542+ setFocusedWindow(nullptr);
543+ m_focusedWindowCleared = false;
544+ }
545+
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);
555 }
560 }
@@ -576,16 +581,6 @@ QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
576 }
581 }
577}
582}
578
583
579−int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
580−{
581− for (int i=0; i<m_windowModel.count(); i++) {
582− if (m_windowModel[i].window->surface() == surface) {
583− return i;
584− }
585− }
586− return -1;
587−}
588−
589int TopLevelWindowModel::generateId()
584int TopLevelWindowModel::generateId()
590{
585{
591 int id = m_nextId;
586 int id = m_nextId;
plugins/WindowManager/TopLevelWindowModel.h+1−3
@@ -174,8 +174,6 @@ Q_SIGNALS:
174private Q_SLOTS:
174private Q_SLOTS:
175 void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
175 void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
176 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
176 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
177− void onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
178− const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
179 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
177 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
180
178
181 void onModificationsStarted();
179 void onModificationsStarted();
@@ -192,9 +190,9 @@ private:
192 void setInputMethodWindow(Window *window);
190 void setInputMethodWindow(Window *window);
193 void setFocusedWindow(Window *window);
191 void setFocusedWindow(Window *window);
194 void removeInputMethodWindow();
192 void removeInputMethodWindow();
195− int findIndexOf(const unity::shell::application::MirSurfaceInterface *surface) const;
196 void deleteAt(int index);
193 void deleteAt(int index);
197 void removeAt(int index);
194 void removeAt(int index);
195+ void removeSurfaces(const QVector<unity::shell::application::MirSurfaceInterface *> surfaces);
198
196
199 void addApplication(unity::shell::application::ApplicationInfoInterface *application);
197 void addApplication(unity::shell::application::ApplicationInfoInterface *application);
200 void removeApplication(unity::shell::application::ApplicationInfoInterface *application);
198 void removeApplication(unity::shell::application::ApplicationInfoInterface *application);
tests/mocks/Unity/Application/SurfaceManager.cpp+25−10
@@ -73,9 +73,7 @@ SurfaceManager::~SurfaceManager()
73{
73{
74 DEBUG_MSG("");
74 DEBUG_MSG("");
75
75
76− if (m_virtualKeyboard) {
76+ releaseInputMethodSurface();
77− m_virtualKeyboard->setLive(false);
78− }
79
77
80 Q_ASSERT(m_instance == this);
78 Q_ASSERT(m_instance == this);
81 m_instance = nullptr;
79 m_instance = nullptr;
@@ -148,13 +146,14 @@ void SurfaceManager::registerSurface(MirSurface *surface)
148 this->onStateRequested(surface, state);
146 this->onStateRequested(surface, state);
149 });
147 });
150
148
151− const QString persistentId = surface->persistentId();
152 connect(surface, &QObject::destroyed, this, [=]() {
149 connect(surface, &QObject::destroyed, this, [=]() {
150+ auto iter = m_surfaceToWindow.find(surface);
151+ if (iter != m_surfaceToWindow.end()) {
153− WindowWrapper key = m_surfaceToWindow.take(surface);
152+ WindowWrapper key = m_surfaceToWindow.value(surface);
154− m_windowToSurface.remove(key);
153+ WindowManagementPolicy::instance()->removeWindow(key.window);
155− this->onSurfaceDestroyed(surface, persistentId);
154+ this->onSurfaceDestroyed(surface);
155+ }
156 });
156 });
157−
158}
157}
159
158
160void SurfaceManager::notifySurfaceCreated(unityapi::MirSurfaceInterface *surface)
159void SurfaceManager::notifySurfaceCreated(unityapi::MirSurfaceInterface *surface)
@@ -321,9 +320,17 @@ void SurfaceManager::onStateRequested(MirSurface *surface, Mir::State state)
321 DEBUG_MSG("("<<surface<<","<<state<<") ended");
320 DEBUG_MSG("("<<surface<<","<<state<<") ended");
322}
321}
323
322
324−void SurfaceManager::onSurfaceDestroyed(MirSurface *surface, const QString& persistentId)
323+void SurfaceManager::onSurfaceDestroyed(MirSurface *surface)
325{
324{
326 m_surfaces.removeAll(surface);
325 m_surfaces.removeAll(surface);
326+
327+ auto iter = m_surfaceToWindow.find(surface);
328+ if (iter != m_surfaceToWindow.end()) {
329+ WindowWrapper key = iter.value();
330+ m_windowToSurface.remove(key);
331+ m_surfaceToWindow.erase(iter);
332+ }
333+
327 if (m_focusedSurface == surface) {
334 if (m_focusedSurface == surface) {
328 m_focusedSurface = nullptr;
335 m_focusedSurface = nullptr;
329
336
@@ -335,7 +342,7 @@ void SurfaceManager::onSurfaceDestroyed(MirSurface *surface, const QString& pers
335 m_underModification = false;
342 m_underModification = false;
336 Q_EMIT modificationsEnded();
343 Q_EMIT modificationsEnded();
337 }
344 }
338− Q_EMIT surfaceDestroyed(persistentId);
345+ Q_EMIT surfaceRemoved(surface);
339}
346}
340
347
341void SurfaceManager::focusFirstAvailableSurface()
348void SurfaceManager::focusFirstAvailableSurface()
@@ -371,3 +378,11 @@ void SurfaceManager::createInputMethodSurface()
371 WindowManagementPolicy::instance()->addWindow(m_surfaceToWindow[m_virtualKeyboard].window);
378 WindowManagementPolicy::instance()->addWindow(m_surfaceToWindow[m_virtualKeyboard].window);
372 }
379 }
373}
380}
381+
382+void SurfaceManager::releaseInputMethodSurface()
383+{
384+ if (m_virtualKeyboard) {
385+ m_virtualKeyboard->setLive(false);
386+ m_virtualKeyboard = nullptr;
387+ }
388+}
tests/mocks/Unity/Application/SurfaceManager.h+2−3
@@ -91,10 +91,9 @@ public:
91
91
92public Q_SLOTS:
92public Q_SLOTS:
93 void createInputMethodSurface();
93 void createInputMethodSurface();
94+ void releaseInputMethodSurface();
94
95
95Q_SIGNALS:
96Q_SIGNALS:
96− void surfaceDestroyed(const QString& persistentSurfaceId);
97−
98 void newSurfaceMinimumWidthChanged(int value);
97 void newSurfaceMinimumWidthChanged(int value);
99 void newSurfaceMaximumWidthChanged(int value);
98 void newSurfaceMaximumWidthChanged(int value);
100 void newSurfaceMinimumHeightChanged(int value);
99 void newSurfaceMinimumHeightChanged(int value);
@@ -104,7 +103,7 @@ Q_SIGNALS:
104
103
105private Q_SLOTS:
104private Q_SLOTS:
106 void onStateRequested(MirSurface *surface, Mir::State state);
105 void onStateRequested(MirSurface *surface, Mir::State state);
107− void onSurfaceDestroyed(MirSurface *surface, const QString& persistentId);
106+ void onSurfaceDestroyed(MirSurface *surface);
108
107
109private:
108private:
110 void doRaise(unity::shell::application::MirSurfaceInterface *surface);
109 void doRaise(unity::shell::application::MirSurfaceInterface *surface);
tests/mocks/WindowManager/WindowManagementPolicy.cpp+14
@@ -73,6 +73,20 @@ void WindowManagementPolicy::addWindow(const miral::Window &window)
73 }
73 }
74}
74}
75
75
76+void WindowManagementPolicy::removeWindow(const miral::Window &window)
77+{
78+ WorkspaceWindows::iterator i = m_windows.begin();
79+ while (i != m_windows.end()) {
80+ if (i.value() == window) {
81+ Q_EMIT windowsAboutToBeRemovedFromWorkspace(i.key(), { window });
82+ i = m_windows.erase(i);
83+ } else {
84+ ++i;
85+ }
86+ }
87+ Q_EMIT windowRemoved(window);
88+}
89+
76void WindowManagementPolicy::forEachWindowInWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::function<void(const miral::Window &)> &callback)
90void WindowManagementPolicy::forEachWindowInWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::function<void(const miral::Window &)> &callback)
77{
91{
78 WorkspaceWindows::iterator i = m_windows.find(workspace);
92 WorkspaceWindows::iterator i = m_windows.find(workspace);
tests/mocks/WindowManager/WindowManagementPolicy.h+2
@@ -48,6 +48,7 @@ public:
48 void setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace) override;
48 void setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace) override;
49
49
50 void addWindow(const miral::Window& window);
50 void addWindow(const miral::Window& window);
51+ void removeWindow(const miral::Window& window);
51
52
52 void forEachWindowInWorkspace(std::shared_ptr<miral::Workspace> const &workspace,
53 void forEachWindowInWorkspace(std::shared_ptr<miral::Workspace> const &workspace,
53 std::function<void(miral::Window const&)> const &callback);
54 std::function<void(miral::Window const&)> const &callback);
@@ -59,6 +60,7 @@ public:
59
60
60Q_SIGNALS:
61Q_SIGNALS:
61 void windowAdded(const miral::Window& window);
62 void windowAdded(const miral::Window& window);
63+ void windowRemoved(const miral::Window& window);
62 void windowsAddedToWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
64 void windowsAddedToWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
63 void windowsAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
65 void windowsAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
64
66
tests/qmltests/ApplicationMenuDataLoader.qml+2−2
@@ -30,8 +30,8 @@ Object {
30 ApplicationMenuRegistry.RegisterSurfaceMenu(surface.persistentId, fakeMenuPath, fakeMenuPath, ":1");
30 ApplicationMenuRegistry.RegisterSurfaceMenu(surface.persistentId, fakeMenuPath, fakeMenuPath, ":1");
31 Indicators.UnityMenuModelCache.setCachedModelData(fakeMenuPath, generateTestData(4, 3, 2, 3, "menu"));
31 Indicators.UnityMenuModelCache.setCachedModelData(fakeMenuPath, generateTestData(4, 3, 2, 3, "menu"));
32 }
32 }
33− onSurfaceDestroyed: {
33+ onSurfaceRemoved: {
34− ApplicationMenuRegistry.UnregisterSurfaceMenu(persistentSurfaceId, "/app");
34+ ApplicationMenuRegistry.UnregisterSurfaceMenu(surface.persistentId, "/app");
35 }
35 }
36 }
36 }
37
37
tests/qmltests/Stage/tst_PhoneStage.qml+1
@@ -555,6 +555,7 @@ Item {
555 performEdgeSwipeToShowAppSpread();
555 performEdgeSwipeToShowAppSpread();
556
556
557 var appDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
557 var appDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
558+ verify(appDelegate);
558 var dragArea = findChild(appDelegate, "dragArea");
559 var dragArea = findChild(appDelegate, "dragArea");
559 verify(dragArea);
560 verify(dragArea);
560 tryCompare(dragArea, "closeable", true);
561 tryCompare(dragArea, "closeable", true);
tests/qmltests/Stage/tst_TabletStage.qml+2
@@ -26,6 +26,7 @@ import WindowManager 1.0
26import ".."
26import ".."
27import "../../../qml/Stage"
27import "../../../qml/Stage"
28import "../../../qml/Components"
28import "../../../qml/Components"
29+import "../../../qml/Components/PanelState"
29
30
30Rectangle {
31Rectangle {
31 id: root
32 id: root
@@ -57,6 +58,7 @@ Rectangle {
57 mode: "stagedWithSideStage"
58 mode: "stagedWithSideStage"
58 applicationManager: ApplicationManager
59 applicationManager: ApplicationManager
59 topLevelSurfaceList: root.topLevelSurfaceList
60 topLevelSurfaceList: root.topLevelSurfaceList
61+ panelState: PanelState {}
60
62
61 Component.onCompleted: {
63 Component.onCompleted: {
62 print("starting dash")
64 print("starting dash")
tests/utils/modules/Unity/Test/UnityTestCase.qml+1
@@ -654,5 +654,6 @@ TestCase {
654 tryCompare(application, "state", ApplicationInfo.Stopped);
654 tryCompare(application, "state", ApplicationInfo.Stopped);
655 }
655 }
656 compare(ApplicationManager.count, 0);
656 compare(ApplicationManager.count, 0);
657+ SurfaceManager.releaseInputMethodSurface();
657 }
658 }
658}
659}