on xenial help sign in
workspace switcher now working
commit02d6bc0c2501b1580947eaabd3edc2eec3c18a0f authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 23 Mar 2017, 18:30 (10 years ago) parent211fde5
8 files changed+132−24
plugins/WindowManager/Screens.cpp+10 plugins/WindowManager/Screens.h+3 plugins/WindowManager/WorkspaceModel.h+1−1 qml/Stage/Spread/ScreensAndWorkspaces.qml+1 qml/Stage/Spread/WorkspacePreview.qml+9 qml/Stage/Spread/Workspaces.qml+5−2 qml/Stage/Stage.qml+8−21 qml/Stage/WorkspaceSwitcher.qml+95
plugins/WindowManager/Screens.cpp+10
@@ -67,6 +67,16 @@ int Screens::rowCount(const QModelIndex &) const
6767 return count();
6868}
6969
70+int Screens::indexOf(Screen *screen) const
71+{
72+ return m_screens.indexOf(screen);
73+}
74+
75+Screen *Screens::get(int index) const
76+{
77+ return m_screens.at(index);
78+}
79+
7080int Screens::count() const
7181{
7282 return m_screens.size();
plugins/WindowManager/Screens.h+3
@@ -49,6 +49,9 @@ public:
4949 QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
5050 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
5151
52+ Q_INVOKABLE int indexOf(Screen*) const;
53+ Q_INVOKABLE Screen* get(int index) const;
54+
5255 int count() const;
5356 QVariant activeScreen() const;
5457
plugins/WindowManager/WorkspaceModel.h+1−1
@@ -47,7 +47,7 @@ public:
4747 void remove(Workspace* workspace);
4848 virtual void move(int from, int to);
4949
50− int indexOf(Workspace *workspace) const;
50+ Q_INVOKABLE int indexOf(Workspace *workspace) const;
5151 Q_INVOKABLE Workspace* get(int index) const;
5252
5353 // From QAbstractItemModel
qml/Stage/Spread/ScreensAndWorkspaces.qml+1
@@ -149,6 +149,7 @@ Item {
149149 background: root.background
150150
151151 workspaceModel: model.screen.workspaces
152+ readOnly: false
152153
153154 onCommitScreenSetup: Screens.sync(root.screensProxy)
154155 onCloseSpread: root.closeSpread();
qml/Stage/Spread/WorkspacePreview.qml+9
@@ -19,6 +19,7 @@ Item {
1919 property bool containsDragLeft: false
2020 property bool containsDragRight: false
2121 property bool isActive: false
22+ property bool isSelected: false
2223
2324 Image {
2425 source: previewSpace.background
@@ -75,6 +76,14 @@ Item {
7576 visible: previewSpace.isActive
7677 }
7778
79+ Rectangle {
80+ anchors.fill: parent
81+ border.color: UbuntuColors.blue
82+ border.width: units.gu(.5)
83+ color: "transparent"
84+ visible: previewSpace.isSelected
85+ }
86+
7887 Rectangle {
7988 anchors.fill: parent
8089 anchors.rightMargin: parent.width / 2
qml/Stage/Spread/Workspaces.qml+5−2
@@ -15,6 +15,8 @@ Item {
1515 property QtObject screen: null
1616 property alias workspaceModel: listView.model
1717 property var background // TODO: should be stored in the workspace data
18+ property int selectedIndex: -1
19+ property bool readOnly: true
1820
1921 signal commitScreenSetup();
2022 signal closeSpread();
@@ -250,12 +252,12 @@ Item {
250252 containsDragLeft: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "left"
251253 containsDragRight: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "right"
252254 isActive: model.workspace.active
255+ isSelected: index === root.selectedIndex
253256 workspace: model.workspace
254257 }
255258 MouseArea {
256259 anchors.fill: parent
257260 onClicked: {
258− print("clickkkked!")
259261 model.workspace.activate();
260262 }
261263 onDoubleClicked: {
@@ -271,7 +273,7 @@ Item {
271273 hoverEnabled: true
272274 height: units.gu(4)
273275 width: height
274− visible: listView.count > 1
276+ visible: !root.readOnly && listView.count > 1
275277
276278 onClicked: {
277279 model.workspace.unassign();
@@ -305,6 +307,7 @@ Item {
305307 propagateComposedEvents: true
306308 anchors.leftMargin: listView.leftMargin
307309 anchors.rightMargin: listView.rightMargin
310+ enabled: !root.readOnly
308311
309312 property int draggedIndex: -1
310313
qml/Stage/Stage.qml+8−21
@@ -228,15 +228,17 @@ FocusScope {
228228 GlobalShortcut {
229229 id: showWorkspaceSwitcherShortcutLeft
230230 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Left
231+ active: !workspaceSwitcher.active
231232 onTriggered: {
232− workspaceSwitcher.left()
233+ workspaceSwitcher.showLeft()
233234 }
234235 }
235236 GlobalShortcut {
236237 id: showWorkspaceSwitcherShortcutRight
237238 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Right
239+ active: !workspaceSwitcher.active
238240 onTriggered: {
239− workspaceSwitcher.right()
241+ workspaceSwitcher.showRight()
240242 }
241243 }
242244
@@ -1955,25 +1957,10 @@ FocusScope {
19551957 anchors.centerIn: parent
19561958 height: units.gu(20)
19571959 background: root.background
1958− opacity: shown ? 1 : 0
1959− visible: opacity > 0
1960− Behavior on opacity { UbuntuNumberAnimation {} }
1961− property bool shown: false
1962− function show() {
1963− shown = true;
1964− hideTimer.start();
1965− }
1966− Timer {
1967− id: hideTimer
1968− interval: 3000
1969− onTriggered: workspaceSwitcher.shown = false;
1970− }
1971−
1972− function left() {
1973− show()
1974− }
1975− function right() {
1976− show();
1960+ onActiveChanged: {
1961+ if (!active) {
1962+ appContainer.focus = true;
1963+ }
19771964 }
19781965 }
19791966
qml/Stage/WorkspaceSwitcher.qml+95
@@ -25,10 +25,104 @@ UbuntuShape {
2525
2626 backgroundColor: "#F2111111"
2727 width: screensRow.childrenRect.width + units.gu(4)
28+ opacity: d.shown ? 1 : 0
29+ visible: opacity > 0
30+ Behavior on opacity { UbuntuNumberAnimation {} }
2831
2932 property var screensProxy: Screens.createProxy();
3033 property string background
3134
35+ readonly property alias active: d.active
36+
37+ function showLeft() {
38+ show();
39+ d.decreaseHighlight();
40+ }
41+ function showRight() {
42+ show();
43+ d.increaseHighlight();
44+ }
45+
46+ function show() {
47+ hideTimer.stop();
48+ d.altPressed = true;
49+ d.ctrlPressed = true;
50+ d.active = true;
51+ d.shown = true;
52+ focus = true;
53+
54+ d.highlightedScreenIndex = screensProxy.activeScreen;
55+ var activeScreen = screensProxy.get(screensProxy.activeScreen);
56+ d.highlightedWorkspaceIndex = activeScreen.workspaces.indexOf(activeScreen.currentWorkspace)
57+ }
58+
59+ QtObject {
60+ id: d
61+
62+ property bool active: false
63+ property bool shown: false
64+ property bool altPressed: false
65+ property bool ctrlPressed: false
66+
67+ property int highlightedScreenIndex: -1
68+ property int highlightedWorkspaceIndex: -1
69+
70+ function increaseHighlight() {
71+ var screen = screensProxy.get(highlightedScreenIndex);
72+ highlightedWorkspaceIndex++
73+ if (highlightedWorkspaceIndex >= screen.workspaces.count) {
74+ highlightedScreenIndex = (highlightedScreenIndex + 1) % screensProxy.count;
75+ highlightedWorkspaceIndex = 0;
76+ }
77+ }
78+ function decreaseHighlight() {
79+ highlightedWorkspaceIndex--;
80+ if (highlightedWorkspaceIndex < 0) {
81+ highlightedScreenIndex--;
82+ if (highlightedScreenIndex < 0) {
83+ highlightedScreenIndex = screensProxy.count - 1
84+ }
85+ var screen = screensProxy.get(highlightedScreenIndex);
86+ highlightedWorkspaceIndex = screen.workspaces.count -1;
87+ }
88+ }
89+ }
90+
91+ Timer {
92+ id: hideTimer
93+ interval: 1000
94+ onTriggered: d.shown = false;
95+ }
96+
97+ Keys.onPressed: {
98+ hideTimer.restart();
99+ switch (event.key) {
100+ case Qt.Key_Left:
101+ d.decreaseHighlight();
102+ break;
103+ case Qt.Key_Right:
104+ d.increaseHighlight();
105+ break;
106+ }
107+ }
108+ Keys.onReleased: {
109+ switch (event.key) {
110+ case Qt.Key_Alt:
111+ d.altPressed = false;
112+ break;
113+ case Qt.Key_Control:
114+ d.ctrlPressed = false;
115+ break;
116+ }
117+ if (!d.altPressed && !d.ctrlPressed) {
118+ print("starting hidetimer")
119+ d.active = false;
120+ hideTimer.start();
121+ focus = false;
122+ screensProxy.get(d.highlightedScreenIndex).workspaces.get(d.highlightedWorkspaceIndex).activate();
123+ }
124+ }
125+
32126 Row {
33127 id: screensRow
34128 anchors {
@@ -75,6 +169,7 @@ UbuntuShape {
75169 anchors.horizontalCenter: parent.horizontalCenter
76170 screen: model.screen
77171 background: root.background
172+ selectedIndex: d.highlightedScreenIndex == index ? d.highlightedWorkspaceIndex : -1
78173
79174 workspaceModel: model.screen.workspaces
80175 }