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