2 * Copyright (C) 2017 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18import Lomiri.Components 1.3
19import Lomiri.Components.Popups 1.3
20import WindowManager 1.0
21import QtMir.Application 0.1
28 property string background
30 property var screensProxy: Screens.createProxy();
32 property QtObject activeWorkspace: null
34 property string mode : "staged"
39 id: deviceConfiguration
44 anchors.bottom: parent.bottom
45 anchors.horizontalCenter: parent.horizontalCenter
46 Behavior on anchors.horizontalCenterOffset { NumberAnimation { duration: LomiriAnimation.SlowDuration } }
49 property var selectedIndex: undefined
55 height: root.height - units.gu(6)
56 width: workspaces.width
57 visible: (deviceConfiguration.category == "phone" && index !== 0) || deviceConfiguration.category != "phone"
61 anchors { left: parent.left; top: parent.top; right: parent.right }
65 property bool isCurrent: {
66 // another screen is selected.
67 if (row.selectedIndex != undefined && row.selectedIndex != index) return false;
69 // this screen is active.
70 if (WMScreen.active && WMScreen.isSameAs(model.screen) && WMScreen.currentWorkspace.isSameAs(activeWorkspace)) return true;
71 if (model.screen.workspaces.indexOf(activeWorkspace) >= 0) return true;
77 property bool isSelected: screenMA.containsMouse
78 onIsSelectedChanged: {
80 row.selectedIndex = Qt.binding(function() { return index; });
81 } else if (row.selectedIndex === index) {
82 row.selectedIndex = undefined;
88 backgroundColor: "white"
89 opacity: header.isCurrent || header.isSelected ? 1.0 : 0.5
97 workspaces.workspaceModel.insert(workspaces.workspaceModel.count, {text: drag.source.text})
98 drag.source.inDropArea = true;
102 workspaces.workspaceModel.remove(workspaces.workspaceModel.count - 1, 1)
103 drag.source.inDropArea = false;
107 drag.source.inDropArea = false;
113 anchors.margins: units.gu(1)
116 text: model.screen.name
117 color: header.isCurrent || header.isSelected ? "black" : "white"
121 text: model.screen.outputTypeName
122 color: header.isCurrent || header.isSelected ? "black" : "white"
127 text: screen.availableModes[screen.currentModeIndex].size.width + "x" + screen.availableModes[screen.currentModeIndex].size.height
128 color: header.isCurrent || header.isSelected ? "black" : "white"
141 source: "image://theme/select"
142 color: header.isCurrent || header.isSelected ? "black" : "white"
143 visible: model.screen.active
152 var obj = screensMenuComponent.createObject(header)
153 obj.open(mouseX, mouseY)
158 id: screensMenuComponent
162 height: contentColumn.childrenRect.height
163 backgroundColor: "white"
165 function open(mouseX, mouseY) {
166 x = Math.max(0, Math.min(mouseX - width / 2, parent.width - width))
167 y = mouseY + units.gu(1)
173 screensMenu.destroy()
181 height: layout.height
182 highlightColor: "transparent"
185 title.text: qsTr("Add workspace")
189 screen.workspaces.addWorkspace();
190 Screens.sync(root.screensProxy);
191 screensMenu.destroy();
201 height: parent.height - header.height - units.gu(2)
204 if (screensProxy.count == 1) {
205 width = Math.min(implicitWidth, root.width - units.gu(8));
207 width = Math.min(implicitWidth, model.screen.active ? root.width - units.gu(48) : units.gu(40))
209 return Math.max(workspaces.minimumWidth, width);
212 Behavior on width { LomiriNumberAnimation {} }
213 anchors.bottom: parent.bottom
214 anchors.bottomMargin: units.gu(1)
215 anchors.horizontalCenter: parent.horizontalCenter
217 background: root.background
219 workspaceModel: model.screen.workspaces
220 activeWorkspace: root.activeWorkspace
223 onCommitScreenSetup: Screens.sync(root.screensProxy)
224 onCloseSpread: root.closeSpread();
227 root.activeWorkspace = workspace;
235 anchors { left: parent.left; top: parent.top; bottom: parent.bottom; topMargin: units.gu(6); bottomMargin: units.gu(1) }
238 visible: (row.width - root.width + units.gu(10)) / 2 - row.anchors.horizontalCenterOffset > units.gu(5)
243 onPressed: mouse.accepted = false;
248 keys: ["application", "workspace"]
252 anchors { right: parent.right; top: parent.top; bottom: parent.bottom; topMargin: units.gu(6); bottomMargin: units.gu(1) }
255 visible: (row.width - root.width + units.gu(10)) / 2 + row.anchors.horizontalCenterOffset > units.gu(5)
260 onPressed: mouse.accepted = false;
263 id: rightFakeDropArea
265 keys: ["application", "workspace"]
270 running: leftScrollArea.containsMouse || rightScrollArea.containsMouse || leftFakeDropArea.containsDrag || rightFakeDropArea.containsDrag
271 interval: LomiriAnimation.SlowDuration
272 triggeredOnStart: true
274 var newOffset = row.anchors.horizontalCenterOffset;
275 var maxOffset = Math.max((row.width - root.width + units.gu(10)) / 2, 0);
276 if (leftScrollArea.containsMouse || leftFakeDropArea.containsDrag) {
277 newOffset += units.gu(20)
279 newOffset -= units.gu(20)
281 newOffset = Math.max(-maxOffset, Math.min(maxOffset, newOffset));
282 row.anchors.horizontalCenterOffset = newOffset;