Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix can't drag surface to other output #78

Merged
merged 3 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/treeland/quick/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ import TreeLand.Greeter
Item {
id :root

function getOutputDelegateFromWaylandOutput(output) {
let finder = function(props) {
if (!props.waylandOutput)
return false
if (props.waylandOutput === output)
return true
}

return QmlHelper.outputManager.getIf(outputDelegateCreator, finder)
}

WaylandServer {
id: server

Expand Down Expand Up @@ -163,7 +152,7 @@ Item {

output.enableAdaptiveSync(states[i].adaptive_sync_enabled);
if (!onlyTest) {
let outputDelegate = getOutputDelegateFromWaylandOutput(output);
let outputDelegate = output.OutputItem.item
outputDelegate.setTransform(states[i].transform)
outputDelegate.setScale(states[i].scale)
outputDelegate.setOutputPosition(states[i].x, states[i].y)
Expand Down Expand Up @@ -373,13 +362,11 @@ Item {
id: stackLayout
visible: true
anchors.fill: parent
activeFocusItem: renderWindow.activeFocusItem
}

TiledWorkspace {
visible: !stackLayout.visible
anchors.fill: parent
activeFocusItem: renderWindow.activeFocusItem
}
}
}
Expand Down
126 changes: 89 additions & 37 deletions src/treeland/quick/qml/StackWorkspace.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import TreeLand.Utils

Item {
id: root
required property Item activeFocusItem
function getSurfaceItemFromWaylandSurface(surface) {
let finder = function(props) {
if (!props.waylandSurface)
Expand Down Expand Up @@ -82,31 +81,58 @@ Item {
}

XdgSurface {
id: surface
id: toplevelSurfaceItem

property var doDestroy: helper.doDestroy
property var cancelMinimize: helper.cancelMinimize
property var surfaceDecorationMapper: surface.waylandSurface.XdgDecorationManager
property var personalizationMapper: surface.waylandSurface.PersonalizationManager
property var surfaceDecorationMapper: toplevelSurfaceItem.waylandSurface.XdgDecorationManager
property var personalizationMapper: toplevelSurfaceItem.waylandSurface.PersonalizationManager
property int outputCounter: 0

topPadding: decoration.enable ? decoration.topMargin : 0
bottomPadding: decoration.enable ? decoration.bottomMargin : 0
leftPadding: decoration.enable ? decoration.leftMargin : 0
rightPadding: decoration.enable ? decoration.rightMargin : 0

OutputLayoutItem {
anchors.fill: parent
layout: QmlHelper.layout

onEnterOutput: function(output) {
waylandSurface.surface.enterOutput(output)
TreeLandHelper.onSurfaceEnterOutput(waylandSurface, toplevelSurfaceItem, output)
outputCounter++

if (outputCounter == 1) {
let outputDelegate = output.OutputItem.item
toplevelSurfaceItem.x = outputDelegate.x
+ TreeLandHelper.getLeftExclusiveMargin(waylandSurface)
+ 10
toplevelSurfaceItem.y = outputDelegate.y
+ TreeLandHelper.getTopExclusiveMargin(waylandSurface)
+ 10
}
}
onLeaveOutput: function(output) {
waylandSurface.surface.leaveOutput(output)
TreeLandHelper.onSurfaceLeaveOutput(waylandSurface, toplevelSurfaceItem, output)
outputCounter--
}
}

WindowDecoration {
property var enable: surfaceDecorationMapper.serverDecorationEnabled

id: decoration
anchors.fill: parent
z: surface.contentItem.z - 1
z: toplevelSurfaceItem.contentItem.z - 1
visible: enable
}

StackToplevelHelper {
id: helper
surface: surface
waylandSurface: surface.waylandSurface
surface: toplevelSurfaceItem
waylandSurface: toplevelSurfaceItem.waylandSurface
dockModel: dock.model
switcherModel: switcher.model
creator: toplevelComponent
Expand All @@ -115,7 +141,7 @@ Item {

Image {
id: background
z: surface.contentItem.z - 2
z: toplevelSurfaceItem.contentItem.z - 2
visible: personalizationMapper.backgroundWallpaper
source: "file:///usr/share/wallpapers/deepin/desktop.jpg"
fillMode: Image.PreserveAspectCrop
Expand All @@ -137,7 +163,7 @@ Item {
required property WaylandXdgSurface waylandSurface
property string type

property alias xdgSurface: surface
property alias xdgSurface: popupSurfaceItem
property var parentItem: root.getSurfaceItemFromWaylandSurface(waylandSurface.parentSurface)

parent: parentItem ? parentItem.item : root
Expand All @@ -148,13 +174,13 @@ Item {
let minX = 0
let maxX = root.width - xdgSurface.width
if (!parentItem) {
retX = surface.implicitPosition.x
retX = popupSurfaceItem.implicitPosition.x
if (retX > maxX)
retX = maxX
if (retX < minX)
retX = minX
} else {
retX = surface.implicitPosition.x / parentItem.item.surfaceSizeRatio + parentItem.item.contentItem.x
retX = popupSurfaceItem.implicitPosition.x / parentItem.item.surfaceSizeRatio + parentItem.item.contentItem.x
let parentX = parent.mapToItem(root, 0, 0).x
if (retX + parentX > maxX) {
if (parentItem.type === "popup")
Expand All @@ -172,13 +198,13 @@ Item {
let minY = 0
let maxY = root.height - xdgSurface.height
if (!parentItem) {
retY = surface.implicitPosition.y
retY = popupSurfaceItem.implicitPosition.y
if (retY > maxY)
retY = maxY
if (retY < minY)
retY = minY
} else {
retY = surface.implicitPosition.y / parentItem.item.surfaceSizeRatio + parentItem.item.contentItem.y
retY = popupSurfaceItem.implicitPosition.y / parentItem.item.surfaceSizeRatio + parentItem.item.contentItem.y
let parentY = parent.mapToItem(root, 0, 0).y
if (retY + parentY > maxY)
retY = maxY - parentY
Expand All @@ -192,8 +218,22 @@ Item {
closePolicy: Popup.CloseOnPressOutside

XdgSurface {
id: surface
id: popupSurfaceItem
waylandSurface: popup.waylandSurface

OutputLayoutItem {
anchors.fill: parent
layout: QmlHelper.layout

onEnterOutput: function(output) {
waylandSurface.surface.enterOutput(output)
TreeLandHelper.onSurfaceEnterOutput(waylandSurface, popupSurfaceItem, output)
}
onLeaveOutput: function(output) {
waylandSurface.surface.leaveOutput(output)
TreeLandHelper.onSurfaceLeaveOutput(waylandSurface, popupSurfaceItem, output)
}
}
}

onClosed: {
Expand Down Expand Up @@ -228,21 +268,22 @@ Item {
}

XWaylandSurfaceItem {
id: surface
id: xwaylandSurfaceItem

required property XWaylandSurface waylandSurface
property var doDestroy: helper.doDestroy
property var cancelMinimize: helper.cancelMinimize
property var surfaceParent: root.getSurfaceItemFromWaylandSurface(waylandSurface.parentXWaylandSurface)
property int outputCounter: 0

surface: waylandSurface
parentSurfaceItem: surfaceParent ? surfaceParent.item : null
z: waylandSurface.bypassManager ? 1 : 0 // TODO: make to enum type
positionMode: {
if (!surface.effectiveVisible)
if (!xwaylandSurfaceItem.effectiveVisible)
return XWaylandSurfaceItem.ManualPosition

return (TreeLandHelper.movingItem === surface || resizeMode === SurfaceItem.SizeToSurface)
return (TreeLandHelper.movingItem === xwaylandSurfaceItem || resizeMode === SurfaceItem.SizeToSurface)
? XWaylandSurfaceItem.PositionToSurface
: XWaylandSurfaceItem.PositionFromSurface
}
Expand All @@ -262,8 +303,8 @@ Item {
}

onEffectiveVisibleChanged: {
if (surface.effectiveVisible)
surface.move(XWaylandSurfaceItem.PositionToSurface)
if (xwaylandSurfaceItem.effectiveVisible)
xwaylandSurfaceItem.move(XWaylandSurfaceItem.PositionToSurface)
}

// TODO: ensure the event to WindowDecoration before WSurfaceItem::eventItem on surface's edges
Expand All @@ -275,36 +316,47 @@ Item {
&& waylandSurface.decorationsType !== XWaylandSurface.DecorationsNoBorder

anchors.fill: parent
z: surface.contentItem.z - 1
z: xwaylandSurfaceItem.contentItem.z - 1
visible: enable
}

StackToplevelHelper {
id: helper
surface: surface
waylandSurface: surface.waylandSurface
dockModel: dock.model
creator: xwaylandComponent
decoration: decoration
}

OutputLayoutItem {
anchors.fill: parent
layout: QmlHelper.layout

onEnterOutput: function(output) {
if (surface.waylandSurface.surface)
surface.waylandSurface.surface.enterOutput(output);
TreeLandHelper.onSurfaceEnterOutput(waylandSurface, surface, output)
surfaceItem.x = TreeLandHelper.getLeftExclusiveMargin(waylandSurface) + 10
surfaceItem.y = TreeLandHelper.getTopExclusiveMargin(waylandSurface) + 10
if (xwaylandSurfaceItem.waylandSurface.surface)
xwaylandSurfaceItem.waylandSurface.surface.enterOutput(output);
TreeLandHelper.onSurfaceEnterOutput(waylandSurface, xwaylandSurfaceItem, output)

outputCounter++

if (outputCounter == 1) {
let outputDelegate = output.OutputItem.item
xwaylandSurfaceItem.x = outputDelegate.x
+ TreeLandHelper.getLeftExclusiveMargin(waylandSurface)
+ 10
xwaylandSurfaceItem.y = outputDelegate.y
+ TreeLandHelper.getTopExclusiveMargin(waylandSurface)
+ 10
}
}
onLeaveOutput: function(output) {
if (surface.waylandSurface.surface)
surface.waylandSurface.surface.leaveOutput(output);
TreeLandHelper.onSurfaceLeaveOutput(waylandSurface, surface, output)
if (xwaylandSurfaceItem.waylandSurface.surface)
xwaylandSurfaceItem.waylandSurface.surface.leaveOutput(output);
TreeLandHelper.onSurfaceLeaveOutput(waylandSurface, xwaylandSurfaceItem, output)
outputCounter--
}
}

StackToplevelHelper {
id: helper
surface: xwaylandSurfaceItem
waylandSurface: xwaylandSurfaceItem.waylandSurface
dockModel: dock.model
creator: xwaylandComponent
decoration: decoration
}
}
}

Expand Down
Loading