@@ -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