on xenial help sign in
Let the windowmanager handle closing of all apps

This moves the closing of all apps into the window manager where it uses the right calls to close applications.

commit35e53ef7ac70cb5eba0279adc4de401f23235398 authorMarius Gripsgard <marius@ubports.com> dateSat 29 Jun 2019, 21:00 (7 years ago) parent2bfacda
4 files changed+54−24
plugins/WindowManager/TopLevelWindowModel.cpp+16−2 plugins/WindowManager/TopLevelWindowModel.h+9 qml/Components/Dialogs.qml+29−21 tests/qmltests/Components/tst_Dialogs.qml−1
plugins/WindowManager/TopLevelWindowModel.cpp+16−2
@@ -436,7 +436,13 @@ void TopLevelWindowModel::removeAt(int index)
436436 setFocusedWindow(nullptr);
437437 }
438438
439− INFO_MSG << " after " << toString();
439+ if (m_closingAllApps) {
440+ if (m_windowModel.isEmpty()) {
441+ Q_EMIT closedAllWindows();
442+ }
443+ }
444+
445+ INFO_MSG << " after " << toString() << " apps left " << m_windowModel.count();
440446}
441447
442448void TopLevelWindowModel::setInputMethodWindow(Window *window)
@@ -725,4 +731,12 @@ void TopLevelWindowModel::activateNullWindow()
725731{
726732 if (!m_nullWindow->focused())
727733 m_nullWindow->activate();
728−}
734+}
735+
736+void TopLevelWindowModel::closeAllWindows()
737+{
738+ m_closingAllApps = true;
739+ for (auto win : m_windowModel) {
740+ win.window->close();
741+ }
742+}
plugins/WindowManager/TopLevelWindowModel.h+9
@@ -169,6 +169,11 @@ public:
169169 */
170170 Q_INVOKABLE void activateNullWindow();
171171
172+ /**
173+ * @brief Closes all windows, emits closedAllWindows when done
174+ */
175+ Q_INVOKABLE void closeAllWindows();
176+
172177Q_SIGNALS:
173178 void countChanged();
174179 void inputMethodSurfaceChanged(unity::shell::application::MirSurfaceInterface* inputMethodSurface);
@@ -185,6 +190,8 @@ Q_SIGNALS:
185190
186191 void nextIdChanged();
187192
193+ void closedAllWindows();
194+
188195private Q_SLOTS:
189196 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
190197 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
@@ -267,6 +274,8 @@ private:
267274 // Valid between modificationsStarted and modificationsEnded
268275 bool m_focusedWindowChanged{false};
269276 Window *m_newlyFocusedWindow{nullptr};
277+
278+ bool m_closingAllApps{false};
270279};
271280
272281#endif // TOPLEVELWINDOWMODEL_H
qml/Components/Dialogs.qml+29−21
@@ -33,15 +33,6 @@ MouseArea {
3333
3434 // to be set from outside, useful mostly for testing purposes
3535 property var unitySessionService: DBusUnitySessionService
36− property var closeAllApps: function() {
37− while (true) {
38− var app = ApplicationManager.get(0);
39− if (app === null) {
40− break;
41− }
42− ApplicationManager.stopApplication(app.appId);
43− }
44− }
4536 property string usageScenario
4637 property size screenSize: Qt.size(Screen.width, Screen.height)
4738 property bool hasKeyboard: false
@@ -52,6 +43,15 @@ MouseArea {
5243 d.showPowerDialog();
5344 }
5445
46+ property var doOnClosedAllWindows: function() {}
47+ Connections {
48+ target: topLevelSurfaceList
49+
50+ onClosedAllWindows: {
51+ doOnClosedAllWindows();
52+ }
53+ }
54+
5555 onUsageScenarioChanged: {
5656 // if we let the user switch manually to desktop mode, don't display the warning dialog
5757 // see MenuItemFactory.qml, for the Desktop Mode switch logic
@@ -222,9 +222,11 @@ MouseArea {
222222 focus: true
223223 text: i18n.tr("Yes")
224224 onClicked: {
225− root.closeAllApps();
226− unitySessionService.reboot();
227− rebootDialog.hide();
225+ topLevelSurfaceList.closeAllWindows();
226+ doOnClosedAllWindows = function() {
227+ unitySessionService.reboot();
228+ rebootDialog.hide();
229+ }
228230 }
229231 color: theme.palette.normal.negative
230232 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
@@ -243,9 +245,11 @@ MouseArea {
243245 focus: true
244246 text: i18n.ctr("Button: Power off the system", "Power off")
245247 onClicked: {
246− root.closeAllApps();
247− powerDialog.hide();
248− root.powerOffClicked();
248+ topLevelSurfaceList.closeAllWindows();
249+ doOnClosedAllWindows = function() {
250+ powerDialog.hide();
251+ root.powerOffClicked();
252+ }
249253 }
250254 color: theme.palette.normal.negative
251255 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
@@ -254,9 +258,11 @@ MouseArea {
254258 width: parent.width
255259 text: i18n.ctr("Button: Restart the system", "Restart")
256260 onClicked: {
257− root.closeAllApps();
258− unitySessionService.reboot();
259− powerDialog.hide();
261+ topLevelSurfaceList.closeAllWindows();
262+ doOnClosedAllWindows = function() {
263+ unitySessionService.reboot();
264+ powerDialog.hide();
265+ }
260266 }
261267 }
262268 Button {
@@ -296,9 +302,11 @@ MouseArea {
296302 }
297303
298304 onLogoutReady: {
299− root.closeAllApps();
300− Qt.quit();
301− unitySessionService.endSession();
305+ topLevelSurfaceList.closeAllWindows();
306+ doOnClosedAllWindows = function() {
307+ Qt.quit();
308+ unitySessionService.endSession();
309+ }
302310 }
303311 }
304312}
tests/qmltests/Components/tst_Dialogs.qml−1
@@ -66,7 +66,6 @@ Rectangle {
6666 id: dialogs
6767 anchors.fill: parent
6868 unitySessionService: fakeUnitySession
69− closeAllApps: function() {}
7069 }
7170 }
7271