on xenial help sign in
Let the windowmanager handle closing of all apps
35e53efMarius Gripsgard
plugins/WindowManager/TopLevelWindowModel.cpp+16−2
@@ -436,7 +436,13 @@ void TopLevelWindowModel::removeAt(int index)
436 setFocusedWindow(nullptr);
436 setFocusedWindow(nullptr);
437 }
437 }
438
438
439+ if (m_closingAllApps) {
440+ if (m_windowModel.isEmpty()) {
441+ Q_EMIT closedAllWindows();
442+ }
443+ }
444+
439− INFO_MSG << " after " << toString();
445+ INFO_MSG << " after " << toString() << " apps left " << m_windowModel.count();
440}
446}
441
447
442void TopLevelWindowModel::setInputMethodWindow(Window *window)
448void TopLevelWindowModel::setInputMethodWindow(Window *window)
@@ -725,4 +731,12 @@ void TopLevelWindowModel::activateNullWindow()
725{
731{
726 if (!m_nullWindow->focused())
732 if (!m_nullWindow->focused())
727 m_nullWindow->activate();
733 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:
169 */
169 */
170 Q_INVOKABLE void activateNullWindow();
170 Q_INVOKABLE void activateNullWindow();
171
171
172+ /**
173+ * @brief Closes all windows, emits closedAllWindows when done
174+ */
175+ Q_INVOKABLE void closeAllWindows();
176+
172Q_SIGNALS:
177Q_SIGNALS:
173 void countChanged();
178 void countChanged();
174 void inputMethodSurfaceChanged(unity::shell::application::MirSurfaceInterface* inputMethodSurface);
179 void inputMethodSurfaceChanged(unity::shell::application::MirSurfaceInterface* inputMethodSurface);
@@ -185,6 +190,8 @@ Q_SIGNALS:
185
190
186 void nextIdChanged();
191 void nextIdChanged();
187
192
193+ void closedAllWindows();
194+
188private Q_SLOTS:
195private Q_SLOTS:
189 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
196 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
190 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
197 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
@@ -267,6 +274,8 @@ private:
267 // Valid between modificationsStarted and modificationsEnded
274 // Valid between modificationsStarted and modificationsEnded
268 bool m_focusedWindowChanged{false};
275 bool m_focusedWindowChanged{false};
269 Window *m_newlyFocusedWindow{nullptr};
276 Window *m_newlyFocusedWindow{nullptr};
277+
278+ bool m_closingAllApps{false};
270};
279};
271
280
272#endif // TOPLEVELWINDOWMODEL_H
281#endif // TOPLEVELWINDOWMODEL_H
qml/Components/Dialogs.qml+29−21
@@ -33,15 +33,6 @@ MouseArea {
33
33
34 // to be set from outside, useful mostly for testing purposes
34 // to be set from outside, useful mostly for testing purposes
35 property var unitySessionService: DBusUnitySessionService
35 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− }
45 property string usageScenario
36 property string usageScenario
46 property size screenSize: Qt.size(Screen.width, Screen.height)
37 property size screenSize: Qt.size(Screen.width, Screen.height)
47 property bool hasKeyboard: false
38 property bool hasKeyboard: false
@@ -52,6 +43,15 @@ MouseArea {
52 d.showPowerDialog();
43 d.showPowerDialog();
53 }
44 }
54
45
46+ property var doOnClosedAllWindows: function() {}
47+ Connections {
48+ target: topLevelSurfaceList
49+
50+ onClosedAllWindows: {
51+ doOnClosedAllWindows();
52+ }
53+ }
54+
55 onUsageScenarioChanged: {
55 onUsageScenarioChanged: {
56 // if we let the user switch manually to desktop mode, don't display the warning dialog
56 // if we let the user switch manually to desktop mode, don't display the warning dialog
57 // see MenuItemFactory.qml, for the Desktop Mode switch logic
57 // see MenuItemFactory.qml, for the Desktop Mode switch logic
@@ -222,9 +222,11 @@ MouseArea {
222 focus: true
222 focus: true
223 text: i18n.tr("Yes")
223 text: i18n.tr("Yes")
224 onClicked: {
224 onClicked: {
225− root.closeAllApps();
225+ topLevelSurfaceList.closeAllWindows();
226+ doOnClosedAllWindows = function() {
226− unitySessionService.reboot();
227+ unitySessionService.reboot();
227− rebootDialog.hide();
228+ rebootDialog.hide();
229+ }
228 }
230 }
229 color: theme.palette.normal.negative
231 color: theme.palette.normal.negative
230 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
232 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
@@ -243,9 +245,11 @@ MouseArea {
243 focus: true
245 focus: true
244 text: i18n.ctr("Button: Power off the system", "Power off")
246 text: i18n.ctr("Button: Power off the system", "Power off")
245 onClicked: {
247 onClicked: {
246− root.closeAllApps();
248+ topLevelSurfaceList.closeAllWindows();
249+ doOnClosedAllWindows = function() {
247− powerDialog.hide();
250+ powerDialog.hide();
248− root.powerOffClicked();
251+ root.powerOffClicked();
252+ }
249 }
253 }
250 color: theme.palette.normal.negative
254 color: theme.palette.normal.negative
251 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
255 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
@@ -254,9 +258,11 @@ MouseArea {
254 width: parent.width
258 width: parent.width
255 text: i18n.ctr("Button: Restart the system", "Restart")
259 text: i18n.ctr("Button: Restart the system", "Restart")
256 onClicked: {
260 onClicked: {
257− root.closeAllApps();
261+ topLevelSurfaceList.closeAllWindows();
262+ doOnClosedAllWindows = function() {
258− unitySessionService.reboot();
263+ unitySessionService.reboot();
259− powerDialog.hide();
264+ powerDialog.hide();
265+ }
260 }
266 }
261 }
267 }
262 Button {
268 Button {
@@ -296,9 +302,11 @@ MouseArea {
296 }
302 }
297
303
298 onLogoutReady: {
304 onLogoutReady: {
299− root.closeAllApps();
305+ topLevelSurfaceList.closeAllWindows();
306+ doOnClosedAllWindows = function() {
300− Qt.quit();
307+ Qt.quit();
301− unitySessionService.endSession();
308+ unitySessionService.endSession();
309+ }
302 }
310 }
303 }
311 }
304}
312}
tests/qmltests/Components/tst_Dialogs.qml−1
@@ -66,7 +66,6 @@ Rectangle {
66 id: dialogs
66 id: dialogs
67 anchors.fill: parent
67 anchors.fill: parent
68 unitySessionService: fakeUnitySession
68 unitySessionService: fakeUnitySession
69− closeAllApps: function() {}
70 }
69 }
71 }
70 }
72
71