on xenial help sign in
add feature to drop to the left/right of a workspace
commitabaacf058cbea8b4eb112d2f7f8d9219f397a97c authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 15 Mar 2017, 10:22 (10 years ago) parent888c73c
4 files changed+63−17
qml/Stage/Spread/ScreensAndWorkspaces.qml+3 qml/Stage/Spread/WorkspacePreview.qml+18−5 qml/Stage/Spread/Workspaces.qml+36−8 qml/Stage/Stage.qml+6−4
qml/Stage/Spread/ScreensAndWorkspaces.qml+3
@@ -12,6 +12,8 @@ Item {
1212
1313 property var screensProxy: Screens.createProxy();
1414
15+ signal closeSpread();
16+
1517 Row {
1618 id: row
1719 anchors.bottom: parent.bottom
@@ -120,6 +122,7 @@ Item {
120122 workspaceModel: model.screen.workspaces
121123
122124 onCommitScreenSetup: Screens.sync(root.screensProxy)
125+ onCloseSpread: root.closeSpread();
123126 }
124127 }
125128 }
qml/Stage/Spread/WorkspacePreview.qml+18−5
@@ -14,7 +14,8 @@ Item {
1414
1515 property real previewScale: previewSpace.height / previewSpace.screenHeight
1616
17− property bool containsDrag: false
17+ property bool containsDragLeft: false
18+ property bool containsDragRight: false
1819 property bool isActive: false
1920
2021 Image {
@@ -81,10 +82,22 @@ Item {
8182
8283 Rectangle {
8384 anchors.fill: parent
84− border.color: UbuntuColors.blue
85− border.width: units.gu(.5)
86− color: "transparent"
87− visible: previewSpace.containsDrag
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"
97+ height: units.gu(4)
98+ width: height
99+ anchors.centerIn: parent
100+ }
88101 }
89102}
90103
qml/Stage/Spread/Workspaces.qml+36−8
@@ -13,6 +13,7 @@ Item {
1313 property var background // TODO: should be stored in the workspace data
1414
1515 signal commitScreenSetup();
16+ signal closeSpread();
1617
1718 DropArea {
1819 anchors.fill: root
@@ -20,15 +21,14 @@ Item {
2021 keys: ['workspace']
2122
2223 onEntered: {
23− var index = listView.getDropIndex(drag);
24− drag.source.workspace.assign(workspaceModel, index)
25− listView.dropItemIndex = index;
24+ listView.updateDropProperties(drag);
25+ drag.source.workspace.assign(workspaceModel, listView.hoveredWorkspaceIndex)
2626 drag.source.inDropArea = true;
2727 }
2828
2929 onPositionChanged: {
30− var index = listView.getDropIndex(drag);
31− if (listView.dropItemIndex == index) return;
30+ listView.updateDropProperties(drag);
31+ if (listView.dropItemIndex == listView.hoveredWorkspaceIndex) return;
3232 listView.model.move(listView.dropItemIndex, index, 1);
3333 listView.dropItemIndex = index;
3434 }
@@ -36,6 +36,7 @@ Item {
3636 onExited: {
3737 drag.source.workspace.unassign()
3838 listView.dropItemIndex = -1;
39+ listView.hoveredWorkspaceIndex = -1;
3940 drag.source.inDropArea = false;
4041 }
4142
@@ -51,7 +52,7 @@ Item {
5152
5253 onPositionChanged: {
5354 listView.progressiveScroll(drag.x)
54− listView.hoveredWorkspaceIndex = listView.getDropIndex(drag)
55+ listView.updateDropProperties(drag)
5556 }
5657 onExited: {
5758 listView.hoveredWorkspaceIndex = -1
@@ -62,6 +63,10 @@ Item {
6263 var workspace = listView.model.get(listView.hoveredWorkspaceIndex);
6364 WorkspaceManager.moveSurfaceToWorkspace(surface, workspace);
6465 drop.accept(Qt.MoveAction)
66+ if (listView.hoveredHalf == "right") {
67+ workspace.activate();
68+ root.closeSpread();
69+ }
6570 listView.hoveredWorkspaceIndex = -1
6671 }
6772 }
@@ -84,6 +89,7 @@ Item {
8489 property real realContentX: contentX - originX + leftMargin
8590 property int dropItemIndex: -1
8691 property int hoveredWorkspaceIndex: -1
92+ property string hoveredHalf: "" // left or right
8793
8894 function getDropIndex(drag) {
8995 var coords = mapToItem(listView.contentItem, drag.x, drag.y)
@@ -94,6 +100,23 @@ Item {
94100 return index;
95101 }
96102
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+
97120 function progressiveScroll(mouseX) {
98121 var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.leftMargin * 2 - listView.foldingAreaWidth * 2)))
99122 listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
@@ -195,13 +218,18 @@ Item {
195218 width: listView.itemWidth
196219 background: root.background
197220 screenHeight: screen.availableModes[screen.currentModeIndex].size.height
198− containsDrag: listView.hoveredWorkspaceIndex == index
221+ containsDragLeft: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "left"
222+ containsDragRight: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "right"
199223 isActive: model.workspace.active
200224 }
201225 MouseArea {
202226 anchors.fill: parent
203227 onClicked: {
204− model.workspace.activate()
228+ model.workspace.activate();
229+ }
230+ onDoubleClicked: {
231+ model.workspace.activate();
232+ root.closeSpread();
205233 }
206234 }
207235
qml/Stage/Stage.qml+6−4
@@ -571,10 +571,12 @@ FocusScope {
571571 ScreensAndWorkspaces {
572572 id: screensAndWorkspaces
573573 anchors { left: parent.left; top: parent.top; right: parent.right; leftMargin: root.leftMargin }
574− height: parent.height / 3
574+ height: parent.height * .3
575575 background: root.background
576576 opacity: 0
577577 visible: opacity > 0
578+
579+ onCloseSpread: priv.goneToSpread = false;
578580 }
579581
580582 Spread {
@@ -763,8 +765,9 @@ FocusScope {
763765 MirSurfaceItem {
764766 id: fakeDragItem
765767 property real previewScale: .5
766− width: implicitWidth * previewScale
767− height: implicitHeight * previewScale
768+ height: (screensAndWorkspaces.height - units.gu(8)) / 2
769+ // w : h = iw : ih
770+ width: implicitWidth * height / implicitHeight
768771 surfaceWidth: -1
769772 surfaceHeight: -1
770773 opacity: surface != null ? 1 : 0
@@ -987,7 +990,6 @@ FocusScope {
987990 function claimFocus() {
988991 if (root.state == "spread") {
989992 spreadItem.highlightedIndex = index
990− priv.goneToSpread = false;
991993 }
992994 if (root.mode == "stagedWithSideStage") {
993995 if (appDelegate.stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {