on xenial help sign in
workspace switcher now working
02d6bc0Michael Zanetti
plugins/WindowManager/Screens.cpp+10
@@ -67,6 +67,16 @@ int Screens::rowCount(const QModelIndex &) const
67 return count();
67 return count();
68}
68}
69
69
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+
70int Screens::count() const
80int Screens::count() const
71{
81{
72 return m_screens.size();
82 return m_screens.size();
plugins/WindowManager/Screens.h+3
@@ -49,6 +49,9 @@ public:
49 QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
49 QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
50 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
50 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
51
51
52+ Q_INVOKABLE int indexOf(Screen*) const;
53+ Q_INVOKABLE Screen* get(int index) const;
54+
52 int count() const;
55 int count() const;
53 QVariant activeScreen() const;
56 QVariant activeScreen() const;
54
57
plugins/WindowManager/WorkspaceModel.h+1−1
@@ -47,7 +47,7 @@ public:
47 void remove(Workspace* workspace);
47 void remove(Workspace* workspace);
48 virtual void move(int from, int to);
48 virtual void move(int from, int to);
49
49
50− int indexOf(Workspace *workspace) const;
50+ Q_INVOKABLE int indexOf(Workspace *workspace) const;
51 Q_INVOKABLE Workspace* get(int index) const;
51 Q_INVOKABLE Workspace* get(int index) const;
52
52
53 // From QAbstractItemModel
53 // From QAbstractItemModel
qml/Stage/Spread/ScreensAndWorkspaces.qml+1
@@ -149,6 +149,7 @@ Item {
149 background: root.background
149 background: root.background
150
150
151 workspaceModel: model.screen.workspaces
151 workspaceModel: model.screen.workspaces
152+ readOnly: false
152
153
153 onCommitScreenSetup: Screens.sync(root.screensProxy)
154 onCommitScreenSetup: Screens.sync(root.screensProxy)
154 onCloseSpread: root.closeSpread();
155 onCloseSpread: root.closeSpread();
qml/Stage/Spread/WorkspacePreview.qml+9
@@ -19,6 +19,7 @@ Item {
19 property bool containsDragLeft: false
19 property bool containsDragLeft: false
20 property bool containsDragRight: false
20 property bool containsDragRight: false
21 property bool isActive: false
21 property bool isActive: false
22+ property bool isSelected: false
22
23
23 Image {
24 Image {
24 source: previewSpace.background
25 source: previewSpace.background
@@ -75,6 +76,14 @@ Item {
75 visible: previewSpace.isActive
76 visible: previewSpace.isActive
76 }
77 }
77
78
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+
78 Rectangle {
87 Rectangle {
79 anchors.fill: parent
88 anchors.fill: parent
80 anchors.rightMargin: parent.width / 2
89 anchors.rightMargin: parent.width / 2
qml/Stage/Spread/Workspaces.qml+5−2
@@ -15,6 +15,8 @@ Item {
15 property QtObject screen: null
15 property QtObject screen: null
16 property alias workspaceModel: listView.model
16 property alias workspaceModel: listView.model
17 property var background // TODO: should be stored in the workspace data
17 property var background // TODO: should be stored in the workspace data
18+ property int selectedIndex: -1
19+ property bool readOnly: true
18
20
19 signal commitScreenSetup();
21 signal commitScreenSetup();
20 signal closeSpread();
22 signal closeSpread();
@@ -250,12 +252,12 @@ Item {
250 containsDragLeft: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "left"
252 containsDragLeft: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "left"
251 containsDragRight: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "right"
253 containsDragRight: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "right"
252 isActive: model.workspace.active
254 isActive: model.workspace.active
255+ isSelected: index === root.selectedIndex
253 workspace: model.workspace
256 workspace: model.workspace
254 }
257 }
255 MouseArea {
258 MouseArea {
256 anchors.fill: parent
259 anchors.fill: parent
257 onClicked: {
260 onClicked: {
258− print("clickkkked!")
259 model.workspace.activate();
261 model.workspace.activate();
260 }
262 }
261 onDoubleClicked: {
263 onDoubleClicked: {
@@ -271,7 +273,7 @@ Item {
271 hoverEnabled: true
273 hoverEnabled: true
272 height: units.gu(4)
274 height: units.gu(4)
273 width: height
275 width: height
274− visible: listView.count > 1
276+ visible: !root.readOnly && listView.count > 1
275
277
276 onClicked: {
278 onClicked: {
277 model.workspace.unassign();
279 model.workspace.unassign();
@@ -305,6 +307,7 @@ Item {
305 propagateComposedEvents: true
307 propagateComposedEvents: true
306 anchors.leftMargin: listView.leftMargin
308 anchors.leftMargin: listView.leftMargin
307 anchors.rightMargin: listView.rightMargin
309 anchors.rightMargin: listView.rightMargin
310+ enabled: !root.readOnly
308
311
309 property int draggedIndex: -1
312 property int draggedIndex: -1
310
313
qml/Stage/Stage.qml+8−21
@@ -228,15 +228,17 @@ FocusScope {
228 GlobalShortcut {
228 GlobalShortcut {
229 id: showWorkspaceSwitcherShortcutLeft
229 id: showWorkspaceSwitcherShortcutLeft
230 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Left
230 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Left
231+ active: !workspaceSwitcher.active
231 onTriggered: {
232 onTriggered: {
232− workspaceSwitcher.left()
233+ workspaceSwitcher.showLeft()
233 }
234 }
234 }
235 }
235 GlobalShortcut {
236 GlobalShortcut {
236 id: showWorkspaceSwitcherShortcutRight
237 id: showWorkspaceSwitcherShortcutRight
237 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Right
238 shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Right
239+ active: !workspaceSwitcher.active
238 onTriggered: {
240 onTriggered: {
239− workspaceSwitcher.right()
241+ workspaceSwitcher.showRight()
240 }
242 }
241 }
243 }
242
244
@@ -1955,25 +1957,10 @@ FocusScope {
1955 anchors.centerIn: parent
1957 anchors.centerIn: parent
1956 height: units.gu(20)
1958 height: units.gu(20)
1957 background: root.background
1959 background: root.background
1958− opacity: shown ? 1 : 0
1960+ onActiveChanged: {
1959− visible: opacity > 0
1961+ if (!active) {
1960− Behavior on opacity { UbuntuNumberAnimation {} }
1962+ appContainer.focus = true;
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− }
1963+ }
1971−
1972− function left() {
1973− show()
1974− }
1975− function right() {
1976− show();
1977 }
1964 }
1978 }
1965 }
1979
1966
qml/Stage/WorkspaceSwitcher.qml+95
@@ -25,10 +25,104 @@ UbuntuShape {
25
25
26 backgroundColor: "#F2111111"
26 backgroundColor: "#F2111111"
27 width: screensRow.childrenRect.width + units.gu(4)
27 width: screensRow.childrenRect.width + units.gu(4)
28+ opacity: d.shown ? 1 : 0
29+ visible: opacity > 0
30+ Behavior on opacity { UbuntuNumberAnimation {} }
28
31
29 property var screensProxy: Screens.createProxy();
32 property var screensProxy: Screens.createProxy();
30 property string background
33 property string background
31
34
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+
32 Row {
126 Row {
33 id: screensRow
127 id: screensRow
34 anchors {
128 anchors {
@@ -75,6 +169,7 @@ UbuntuShape {
75 anchors.horizontalCenter: parent.horizontalCenter
169 anchors.horizontalCenter: parent.horizontalCenter
76 screen: model.screen
170 screen: model.screen
77 background: root.background
171 background: root.background
172+ selectedIndex: d.highlightedScreenIndex == index ? d.highlightedWorkspaceIndex : -1
78
173
79 workspaceModel: model.screen.workspaces
174 workspaceModel: model.screen.workspaces
80 }
175 }