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