Lomiri
Loading...
Searching...
No Matches
WorkspaceSwitcher.qml
1/*
2 * Copyright (C) 2014-2016 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16
17import QtQuick 2.15
18import Lomiri.Components 1.3
19import "Spread"
20import WindowManager 1.0
21import QtMir.Application 0.1
22
23Item {
24 id: root
25
26 opacity: d.shown ? 1 : 0
27 visible: opacity > 0
28 Behavior on opacity { LomiriNumberAnimation {} }
29
30 property var screensProxy: Screens.createProxy();
31 property string background
32 property bool launcherLockedVisible: false
33 property real topPanelHeight
34
35 readonly property alias active: d.active
36
37 function showLeft() {
38 show();
39 d.previousWorkspace();
40 }
41 function showRight() {
42 show();
43 d.nextWorkspace();
44 }
45 function showUp() {
46 show();
47 d.previousScreen();
48 }
49 function showDown() {
50 show();
51 d.nextScreen();
52 }
53 function showLeftMoveApp(appSurface) {
54 d.currentAppSurface = appSurface
55 show();
56 d.previousWorkspace();
57 }
58 function showRightMoveApp(appSurface) {
59 d.currentAppSurface = appSurface
60 show();
61 d.nextWorkspace();
62 }
63 function showUpMoveApp(appSurface) {
64 d.currentAppSurface = appSurface
65 show();
66 d.previousScreen();
67 }
68 function showDownMoveApp(appSurface) {
69 d.currentAppSurface = appSurface
70 show();
71 d.nextScreen();
72 }
73
74 function show() {
75 hideTimer.stop();
76 d.altPressed = true;
77 d.ctrlPressed = true;
78 if (d.currentAppSurface) {
79 d.shiftPressed = true;
80 }
81 d.active = true;
82 d.shown = true;
83 focus = true;
84
85 d.highlightedScreenIndex = screensProxy.activeScreen;
86 var activeScreen = screensProxy.get(screensProxy.activeScreen);
87 d.highlightedWorkspaceIndex = activeScreen.workspaces.indexOf(activeScreen.currentWorkspace)
88 }
89
90 QtObject {
91 id: d
92
93 property bool active: false
94 property bool shown: false
95 property bool altPressed: false
96 property bool ctrlPressed: false
97 property bool shiftPressed: false
98 property var currentAppSurface: null
99
100 property int rowHeight: root.height - units.gu(4)
101
102 property int highlightedScreenIndex: -1
103 property int highlightedWorkspaceIndex: -1
104
105 function previousWorkspace() {
106 highlightedWorkspaceIndex = Math.max(highlightedWorkspaceIndex - 1, 0);
107 }
108 function nextWorkspace() {
109 var screen = screensProxy.get(highlightedScreenIndex);
110 highlightedWorkspaceIndex = Math.min(highlightedWorkspaceIndex + 1, screen.workspaces.count - 1);
111 }
112 function previousScreen() {
113 highlightedScreenIndex = Math.max(highlightedScreenIndex - 1, 0);
114 var screen = screensProxy.get(highlightedScreenIndex);
115 highlightedWorkspaceIndex = Math.min(highlightedWorkspaceIndex, screen.workspaces.count - 1)
116 }
117 function nextScreen() {
118 highlightedScreenIndex = Math.min(highlightedScreenIndex + 1, screensProxy.count - 1);
119 var screen = screensProxy.get(highlightedScreenIndex);
120 highlightedWorkspaceIndex = Math.min(highlightedWorkspaceIndex, screen.workspaces.count - 1)
121 }
122 }
123
124 Timer {
125 id: hideTimer
126 interval: 300
127 onTriggered: d.shown = false;
128 }
129
130 Keys.onPressed: {
131 switch (event.key) {
132 case Qt.Key_Left:
133 d.previousWorkspace();
134 break;
135 case Qt.Key_Right:
136 d.nextWorkspace()
137 break;
138 case Qt.Key_Up:
139 d.previousScreen();
140 break;
141 case Qt.Key_Down:
142 d.nextScreen();
143 }
144 }
145 Keys.onReleased: {
146 switch (event.key) {
147 case Qt.Key_Alt:
148 d.altPressed = false;
149 break;
150 case Qt.Key_Control:
151 d.ctrlPressed = false;
152 break;
153 case Qt.Key_Shift:
154 d.shiftPressed = false;
155 break;
156 }
157
158 if (!d.altPressed && !d.ctrlPressed && !d.shiftPressed) {
159 if (d.currentAppSurface) {
160 let _workspace = screensProxy.get(d.highlightedScreenIndex).workspaces.get(d.highlightedWorkspaceIndex)
161 WorkspaceManager.moveSurfaceToWorkspace(d.currentAppSurface, _workspace);
162 d.currentAppSurface = null
163 }
164 d.active = false;
165 hideTimer.start();
166 focus = false;
167 screensProxy.get(d.highlightedScreenIndex).workspaces.get(d.highlightedWorkspaceIndex).activate();
168 }
169 }
170
171 LomiriShape {
172 backgroundColor: "#F2111111"
173 clip: true
174 width: Math.min(parent.width, screensColumn.width + units.gu(4))
175 anchors.horizontalCenter: parent.horizontalCenter
176 height: parent.height
177
178 Column {
179 id: screensColumn
180 anchors {
181 top: parent.top; topMargin: units.gu(2) - d.highlightedScreenIndex * (d.rowHeight + screensColumn.spacing)
182 left: parent.left; leftMargin: units.gu(2)
183 }
184 width: screensRepeater.itemAt(d.highlightedScreenIndex).width
185 spacing: units.gu(2)
186 Behavior on anchors.topMargin { LomiriNumberAnimation {} }
187 Behavior on width { LomiriNumberAnimation {} }
188
189 Repeater {
190 id: screensRepeater
191 model: screensProxy
192
193 delegate: Item {
194 height: d.rowHeight
195 width: workspaces.width
196 anchors.horizontalCenter: parent.horizontalCenter
197 opacity: d.highlightedScreenIndex == index ? 1 : 0
198 Behavior on opacity { LomiriNumberAnimation {} }
199
200 LomiriShape {
201 id: header
202 anchors { left: parent.left; top: parent.top; right: parent.right }
203 height: units.gu(4)
204 backgroundColor: "white"
205
206 Label {
207 anchors { left: parent.left; top: parent.top; right: parent.right; margins: units.gu(1) }
208 text: model.screen.name
209 color: LomiriColors.ash
210 }
211 }
212
213 Workspaces {
214 id: workspaces
215 height: parent.height - header.height - units.gu(2)
216 width: Math.min(implicitWidth, root.width - units.gu(4))
217
218 anchors.bottom: parent.bottom
219 anchors.bottomMargin: units.gu(1)
220 anchors.horizontalCenter: parent.horizontalCenter
221 screen: model.screen
222 background: root.background
223 selectedIndex: d.highlightedScreenIndex == index ? d.highlightedWorkspaceIndex : -1
224
225 workspaceModel: model.screen.workspaces
226 launcherLockedVisible: root.launcherLockedVisible
227 topPanelHeight: root.topPanelHeight
228 }
229 }
230 }
231 }
232 }
233}