on xenial help sign in
rework workspace switcher for up/down navigation for screens
e058685Michael Zanetti
qml/Stage/Spread/Workspaces.qml+4
@@ -80,6 +80,10 @@ Item {
80 }
80 }
81 }
81 }
82
82
83+ onSelectedIndexChanged: {
84+ listView.positionViewAtIndex(selectedIndex, ListView.Center);
85+ }
86+
83 Item {
87 Item {
84 // We need to clip the listview as it has left/right margins and it would
88 // We need to clip the listview as it has left/right margins and it would
85 // overlap with items next to it and eat mouse input. However, we can't
89 // overlap with items next to it and eat mouse input. However, we can't
qml/Stage/Stage.qml+19
@@ -265,6 +265,24 @@ FocusScope {
265 workspaceSwitcher.showRight()
265 workspaceSwitcher.showRight()
266 }
266 }
267 }
267 }
268+ GlobalShortcut {
269+ id: showWorkspaceSwitcherShortcutUp
270+ shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Up
271+ active: !workspaceSwitcher.active
272+ onTriggered: {
273+ root.focus = true;
274+ workspaceSwitcher.showUp()
275+ }
276+ }
277+ GlobalShortcut {
278+ id: showWorkspaceSwitcherShortcutDown
279+ shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Down
280+ active: !workspaceSwitcher.active
281+ onTriggered: {
282+ root.focus = true;
283+ workspaceSwitcher.showDown()
284+ }
285+ }
268
286
269 QtObject {
287 QtObject {
270 id: priv
288 id: priv
@@ -2027,6 +2045,7 @@ FocusScope {
2027 id: workspaceSwitcher
2045 id: workspaceSwitcher
2028 anchors.centerIn: parent
2046 anchors.centerIn: parent
2029 height: units.gu(20)
2047 height: units.gu(20)
2048+ width: root.width - units.gu(8)
2030 background: root.background
2049 background: root.background
2031 onActiveChanged: {
2050 onActiveChanged: {
2032 if (!active) {
2051 if (!active) {
qml/Stage/WorkspaceSwitcher.qml+86−71
@@ -20,11 +20,9 @@ import "Spread"
20import WindowManager 1.0
20import WindowManager 1.0
21import Unity.Application 0.1
21import Unity.Application 0.1
22
22
23−UbuntuShape {
23+Item {
24 id: root
24 id: root
25
25
26− backgroundColor: "#F2111111"
27− width: screensRow.childrenRect.width + units.gu(4)
28 opacity: d.shown ? 1 : 0
26 opacity: d.shown ? 1 : 0
29 visible: opacity > 0
27 visible: opacity > 0
30 Behavior on opacity { UbuntuNumberAnimation {} }
28 Behavior on opacity { UbuntuNumberAnimation {} }
@@ -36,11 +34,19 @@ UbuntuShape {
36
34
37 function showLeft() {
35 function showLeft() {
38 show();
36 show();
39− d.decreaseHighlight();
37+ d.previousWorkspace();
40 }
38 }
41 function showRight() {
39 function showRight() {
42 show();
40 show();
43− d.increaseHighlight();
41+ d.nextWorkspace();
42+ }
43+ function showUp() {
44+ show();
45+ d.previousScreen();
46+ }
47+ function showDown() {
48+ show();
49+ d.nextScreen();
44 }
50 }
45
51
46 function show() {
52 function show() {
@@ -64,27 +70,27 @@ UbuntuShape {
64 property bool altPressed: false
70 property bool altPressed: false
65 property bool ctrlPressed: false
71 property bool ctrlPressed: false
66
72
73+ property int rowHeight: root.height - units.gu(4)
74+
67 property int highlightedScreenIndex: -1
75 property int highlightedScreenIndex: -1
68 property int highlightedWorkspaceIndex: -1
76 property int highlightedWorkspaceIndex: -1
69
77
70− function increaseHighlight() {
78+ function previousWorkspace() {
79+ highlightedWorkspaceIndex = Math.max(highlightedWorkspaceIndex - 1, 0);
80+ }
81+ function nextWorkspace() {
71 var screen = screensProxy.get(highlightedScreenIndex);
82 var screen = screensProxy.get(highlightedScreenIndex);
72− highlightedWorkspaceIndex++
73− if (highlightedWorkspaceIndex >= screen.workspaces.count) {
83+ highlightedWorkspaceIndex = Math.min(highlightedWorkspaceIndex + 1, screen.workspaces.count - 1);
74− highlightedScreenIndex = (highlightedScreenIndex + 1) % screensProxy.count;
75− highlightedWorkspaceIndex = 0;
76− }
77 }
84 }
78− function decreaseHighlight() {
85+ function previousScreen() {
79− highlightedWorkspaceIndex--;
86+ highlightedScreenIndex = Math.max(highlightedScreenIndex - 1, 0);
80− if (highlightedWorkspaceIndex < 0) {
81− highlightedScreenIndex--;
87+ var screen = screensProxy.get(highlightedScreenIndex);
82− if (highlightedScreenIndex < 0) {
88+ highlightedWorkspaceIndex = Math.min(highlightedWorkspaceIndex, screen.workspaces.count - 1)
89+ }
90+ function nextScreen() {
83− highlightedScreenIndex = screensProxy.count - 1
91+ highlightedScreenIndex = Math.min(highlightedScreenIndex + 1, screensProxy.count - 1);
84− }
85− var screen = screensProxy.get(highlightedScreenIndex);
92+ var screen = screensProxy.get(highlightedScreenIndex);
86− highlightedWorkspaceIndex = screen.workspaces.count -1;
93+ highlightedWorkspaceIndex = Math.min(highlightedWorkspaceIndex, screen.workspaces.count - 1)
87− }
88 }
94 }
89 }
95 }
90
96
@@ -95,14 +101,18 @@ UbuntuShape {
95 }
101 }
96
102
97 Keys.onPressed: {
103 Keys.onPressed: {
98− hideTimer.restart();
99 switch (event.key) {
104 switch (event.key) {
100 case Qt.Key_Left:
105 case Qt.Key_Left:
101− d.decreaseHighlight();
106+ d.previousWorkspace();
102 break;
107 break;
103 case Qt.Key_Right:
108 case Qt.Key_Right:
104− d.increaseHighlight();
109+ d.nextWorkspace()
110+ break;
111+ case Qt.Key_Up:
112+ d.previousScreen();
105 break;
113 break;
114+ case Qt.Key_Down:
115+ d.nextScreen();
106 }
116 }
107 }
117 }
108 Keys.onReleased: {
118 Keys.onReleased: {
@@ -116,7 +126,6 @@ UbuntuShape {
116 }
126 }
117
127
118 if (!d.altPressed && !d.ctrlPressed) {
128 if (!d.altPressed && !d.ctrlPressed) {
119− print("starting hidetimer")
120 d.active = false;
129 d.active = false;
121 hideTimer.start();
130 hideTimer.start();
122 focus = false;
131 focus = false;
@@ -124,56 +133,62 @@ UbuntuShape {
124 }
133 }
125 }
134 }
126
135
127− Row {
136+ UbuntuShape {
128− id: screensRow
137+ backgroundColor: "#F2111111"
129− anchors {
138+ clip: true
139+ width: Math.min(parent.width, screensColumn.width + units.gu(4))
140+ anchors.horizontalCenter: parent.horizontalCenter
141+ height: parent.height
142+
143+ Column {
144+ id: screensColumn
145+ anchors {
130− top: parent.top; topMargin: units.gu(2)
146+ top: parent.top; topMargin: units.gu(2) - d.highlightedScreenIndex * (d.rowHeight + screensColumn.spacing)
131− left: parent.left; leftMargin: units.gu(2)
147+ left: parent.left; leftMargin: units.gu(2)
132− }
148+ }
149+ width: screensRepeater.itemAt(d.highlightedScreenIndex).width
133− spacing: units.gu(2)
150+ spacing: units.gu(2)
134−
151+ Behavior on anchors.topMargin { UbuntuNumberAnimation {} }
152+ Behavior on width { UbuntuNumberAnimation {} }
153+
135− Repeater {
154+ Repeater {
155+ id: screensRepeater
136− model: screensProxy
156+ model: screensProxy
137−
157+
138− delegate: Item {
158+ delegate: Item {
139− height: root.height - units.gu(4)
159+ height: d.rowHeight
140− width: workspaces.width
160+ width: workspaces.width
141−
161+ anchors.horizontalCenter: parent.horizontalCenter
142− UbuntuShape {
162+ opacity: d.highlightedScreenIndex == index ? 1 : 0
163+ Behavior on opacity { UbuntuNumberAnimation {} }
164+
165+ UbuntuShape {
143− id: header
166+ id: header
144− anchors { left: parent.left; top: parent.top; right: parent.right }
167+ anchors { left: parent.left; top: parent.top; right: parent.right }
145− height: units.gu(4)
168+ height: units.gu(4)
146− backgroundColor: "white"
169+ backgroundColor: "white"
147−
170+
148− Label {
171+ Label {
149− anchors { left: parent.left; top: parent.top; right: parent.right; margins: units.gu(1) }
172+ anchors { left: parent.left; top: parent.top; right: parent.right; margins: units.gu(1) }
150− text: model.screen.name
173+ text: model.screen.name
151− color: UbuntuColors.ash
174+ color: UbuntuColors.ash
152− }
153− }
154−
155− Workspaces {
156− id: workspaces
157− height: parent.height - header.height - units.gu(2)
158− width: {
159− var width = 0;
160− if (screensProxy.count == 1) {
161− width = Math.min(implicitWidth, root.width - units.gu(8));
162− } else {
163− width = Math.min(implicitWidth, model.screen.active ? root.width - units.gu(48) : units.gu(40))
164 }
175 }
165− return Math.max(workspaces.minimumWidth, width);
166 }
176 }
167
177
168− Behavior on width { UbuntuNumberAnimation {} }
178+ Workspaces {
179+ id: workspaces
180+ height: parent.height - header.height - units.gu(2)
181+ width: Math.min(implicitWidth, root.width - units.gu(4))
182+
169− anchors.bottom: parent.bottom
183+ anchors.bottom: parent.bottom
170− anchors.bottomMargin: units.gu(1)
184+ anchors.bottomMargin: units.gu(1)
171− anchors.horizontalCenter: parent.horizontalCenter
185+ anchors.horizontalCenter: parent.horizontalCenter
172− screen: model.screen
186+ screen: model.screen
173− background: root.background
187+ background: root.background
174− selectedIndex: d.highlightedScreenIndex == index ? d.highlightedWorkspaceIndex : -1
188+ selectedIndex: d.highlightedScreenIndex == index ? d.highlightedWorkspaceIndex : -1
175
189
176− workspaceModel: model.screen.workspaces
190+ workspaceModel: model.screen.workspaces
191+ }
177 }
192 }
178 }
193 }
179 }
194 }