on xenial help sign in
add feature to drop to the left/right of a workspace
abaacf0Michael Zanetti
qml/Stage/Spread/ScreensAndWorkspaces.qml+3
@@ -12,6 +12,8 @@ Item {
12
12
13 property var screensProxy: Screens.createProxy();
13 property var screensProxy: Screens.createProxy();
14
14
15+ signal closeSpread();
16+
15 Row {
17 Row {
16 id: row
18 id: row
17 anchors.bottom: parent.bottom
19 anchors.bottom: parent.bottom
@@ -120,6 +122,7 @@ Item {
120 workspaceModel: model.screen.workspaces
122 workspaceModel: model.screen.workspaces
121
123
122 onCommitScreenSetup: Screens.sync(root.screensProxy)
124 onCommitScreenSetup: Screens.sync(root.screensProxy)
125+ onCloseSpread: root.closeSpread();
123 }
126 }
124 }
127 }
125 }
128 }
qml/Stage/Spread/WorkspacePreview.qml+18−5
@@ -14,7 +14,8 @@ Item {
14
14
15 property real previewScale: previewSpace.height / previewSpace.screenHeight
15 property real previewScale: previewSpace.height / previewSpace.screenHeight
16
16
17− property bool containsDrag: false
17+ property bool containsDragLeft: false
18+ property bool containsDragRight: false
18 property bool isActive: false
19 property bool isActive: false
19
20
20 Image {
21 Image {
@@ -81,10 +82,22 @@ Item {
81
82
82 Rectangle {
83 Rectangle {
83 anchors.fill: parent
84 anchors.fill: parent
84− border.color: UbuntuColors.blue
85+ anchors.rightMargin: parent.width / 2
86+ color: "#55000000"
87+ visible: previewSpace.containsDragLeft
88+ }
89+ Rectangle {
90+ anchors.fill: parent
91+ anchors.leftMargin: parent.width / 2
92+ color: "#55000000"
93+ visible: previewSpace.containsDragRight
94+
95+ Icon {
96+ source: "../graphics/multi-monitor_leave.png"
85− border.width: units.gu(.5)
97+ height: units.gu(4)
86− color: "transparent"
98+ width: height
87− visible: previewSpace.containsDrag
99+ anchors.centerIn: parent
100+ }
88 }
101 }
89}
102}
90
103
qml/Stage/Spread/Workspaces.qml+36−8
@@ -13,6 +13,7 @@ Item {
13 property var background // TODO: should be stored in the workspace data
13 property var background // TODO: should be stored in the workspace data
14
14
15 signal commitScreenSetup();
15 signal commitScreenSetup();
16+ signal closeSpread();
16
17
17 DropArea {
18 DropArea {
18 anchors.fill: root
19 anchors.fill: root
@@ -20,15 +21,14 @@ Item {
20 keys: ['workspace']
21 keys: ['workspace']
21
22
22 onEntered: {
23 onEntered: {
23− var index = listView.getDropIndex(drag);
24+ listView.updateDropProperties(drag);
24− drag.source.workspace.assign(workspaceModel, index)
25+ drag.source.workspace.assign(workspaceModel, listView.hoveredWorkspaceIndex)
25− listView.dropItemIndex = index;
26 drag.source.inDropArea = true;
26 drag.source.inDropArea = true;
27 }
27 }
28
28
29 onPositionChanged: {
29 onPositionChanged: {
30− var index = listView.getDropIndex(drag);
30+ listView.updateDropProperties(drag);
31− if (listView.dropItemIndex == index) return;
31+ if (listView.dropItemIndex == listView.hoveredWorkspaceIndex) return;
32 listView.model.move(listView.dropItemIndex, index, 1);
32 listView.model.move(listView.dropItemIndex, index, 1);
33 listView.dropItemIndex = index;
33 listView.dropItemIndex = index;
34 }
34 }
@@ -36,6 +36,7 @@ Item {
36 onExited: {
36 onExited: {
37 drag.source.workspace.unassign()
37 drag.source.workspace.unassign()
38 listView.dropItemIndex = -1;
38 listView.dropItemIndex = -1;
39+ listView.hoveredWorkspaceIndex = -1;
39 drag.source.inDropArea = false;
40 drag.source.inDropArea = false;
40 }
41 }
41
42
@@ -51,7 +52,7 @@ Item {
51
52
52 onPositionChanged: {
53 onPositionChanged: {
53 listView.progressiveScroll(drag.x)
54 listView.progressiveScroll(drag.x)
54− listView.hoveredWorkspaceIndex = listView.getDropIndex(drag)
55+ listView.updateDropProperties(drag)
55 }
56 }
56 onExited: {
57 onExited: {
57 listView.hoveredWorkspaceIndex = -1
58 listView.hoveredWorkspaceIndex = -1
@@ -62,6 +63,10 @@ Item {
62 var workspace = listView.model.get(listView.hoveredWorkspaceIndex);
63 var workspace = listView.model.get(listView.hoveredWorkspaceIndex);
63 WorkspaceManager.moveSurfaceToWorkspace(surface, workspace);
64 WorkspaceManager.moveSurfaceToWorkspace(surface, workspace);
64 drop.accept(Qt.MoveAction)
65 drop.accept(Qt.MoveAction)
66+ if (listView.hoveredHalf == "right") {
67+ workspace.activate();
68+ root.closeSpread();
69+ }
65 listView.hoveredWorkspaceIndex = -1
70 listView.hoveredWorkspaceIndex = -1
66 }
71 }
67 }
72 }
@@ -84,6 +89,7 @@ Item {
84 property real realContentX: contentX - originX + leftMargin
89 property real realContentX: contentX - originX + leftMargin
85 property int dropItemIndex: -1
90 property int dropItemIndex: -1
86 property int hoveredWorkspaceIndex: -1
91 property int hoveredWorkspaceIndex: -1
92+ property string hoveredHalf: "" // left or right
87
93
88 function getDropIndex(drag) {
94 function getDropIndex(drag) {
89 var coords = mapToItem(listView.contentItem, drag.x, drag.y)
95 var coords = mapToItem(listView.contentItem, drag.x, drag.y)
@@ -94,6 +100,23 @@ Item {
94 return index;
100 return index;
95 }
101 }
96
102
103+ function updateDropProperties(drag) {
104+ var coords = mapToItem(listView.contentItem, drag.x, drag.y)
105+ var index = Math.floor(drag.x + listView.realContentX) / (listView.itemWidth + listView.spacing);
106+ if (index < 0) {
107+ listView.hoveredWorkspaceIndex = -1;
108+ listView.hoveredHalf = "";
109+ return;
110+ }
111+
112+ var upperLimit = dropItemIndex == -1 ? listView.count : listView.count - 1
113+ if (index > upperLimit) index = upperLimit;
114+ listView.hoveredWorkspaceIndex = index;
115+ print("updating drag:", (drag.x + listView.realContentX) % (listView.itemWidth + listView.spacing))
116+ var pixelsInTile = (drag.x + listView.realContentX) % (listView.itemWidth + listView.spacing);
117+ listView.hoveredHalf = (pixelsInTile / listView.itemWidth) < .5 ? "left" : "right";
118+ }
119+
97 function progressiveScroll(mouseX) {
120 function progressiveScroll(mouseX) {
98 var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.leftMargin * 2 - listView.foldingAreaWidth * 2)))
121 var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.leftMargin * 2 - listView.foldingAreaWidth * 2)))
99 listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
122 listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
@@ -195,13 +218,18 @@ Item {
195 width: listView.itemWidth
218 width: listView.itemWidth
196 background: root.background
219 background: root.background
197 screenHeight: screen.availableModes[screen.currentModeIndex].size.height
220 screenHeight: screen.availableModes[screen.currentModeIndex].size.height
221+ containsDragLeft: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "left"
198− containsDrag: listView.hoveredWorkspaceIndex == index
222+ containsDragRight: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "right"
199 isActive: model.workspace.active
223 isActive: model.workspace.active
200 }
224 }
201 MouseArea {
225 MouseArea {
202 anchors.fill: parent
226 anchors.fill: parent
203 onClicked: {
227 onClicked: {
204− model.workspace.activate()
228+ model.workspace.activate();
229+ }
230+ onDoubleClicked: {
231+ model.workspace.activate();
232+ root.closeSpread();
205 }
233 }
206 }
234 }
207
235
qml/Stage/Stage.qml+6−4
@@ -571,10 +571,12 @@ FocusScope {
571 ScreensAndWorkspaces {
571 ScreensAndWorkspaces {
572 id: screensAndWorkspaces
572 id: screensAndWorkspaces
573 anchors { left: parent.left; top: parent.top; right: parent.right; leftMargin: root.leftMargin }
573 anchors { left: parent.left; top: parent.top; right: parent.right; leftMargin: root.leftMargin }
574− height: parent.height / 3
574+ height: parent.height * .3
575 background: root.background
575 background: root.background
576 opacity: 0
576 opacity: 0
577 visible: opacity > 0
577 visible: opacity > 0
578+
579+ onCloseSpread: priv.goneToSpread = false;
578 }
580 }
579
581
580 Spread {
582 Spread {
@@ -763,8 +765,9 @@ FocusScope {
763 MirSurfaceItem {
765 MirSurfaceItem {
764 id: fakeDragItem
766 id: fakeDragItem
765 property real previewScale: .5
767 property real previewScale: .5
766− width: implicitWidth * previewScale
768+ height: (screensAndWorkspaces.height - units.gu(8)) / 2
769+ // w : h = iw : ih
767− height: implicitHeight * previewScale
770+ width: implicitWidth * height / implicitHeight
768 surfaceWidth: -1
771 surfaceWidth: -1
769 surfaceHeight: -1
772 surfaceHeight: -1
770 opacity: surface != null ? 1 : 0
773 opacity: surface != null ? 1 : 0
@@ -987,7 +990,6 @@ FocusScope {
987 function claimFocus() {
990 function claimFocus() {
988 if (root.state == "spread") {
991 if (root.state == "spread") {
989 spreadItem.highlightedIndex = index
992 spreadItem.highlightedIndex = index
990− priv.goneToSpread = false;
991 }
993 }
992 if (root.mode == "stagedWithSideStage") {
994 if (root.mode == "stagedWithSideStage") {
993 if (appDelegate.stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
995 if (appDelegate.stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {