Skip to content

Commit

Permalink
chore: sync change in waylib for TiledWorkspace
Browse files Browse the repository at this point in the history
  • Loading branch information
wineee committed Dec 22, 2023
1 parent 8a1736f commit 53b88e3
Showing 1 changed file with 118 additions and 42 deletions.
160 changes: 118 additions & 42 deletions src/treeland/quick/qml/TiledWorkspace.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Waylib.Server

Item {
id: root
required property Item activeFocusItem

function getSurfaceItemFromWaylandSurface(surface) {
let finder = function(props) {
if (!props.waylandSurface)
Expand All @@ -22,23 +22,35 @@ Item {
if (toplevel) {
return {
shell: toplevel,
item: toplevel
item: toplevel,
type: "toplevel"
}
}

let popup = QmlHelper.xdgSurfaceManager.getIf(popupComponent, finder)
if (popup) {
return {
shell: popup,
item: popup.xdgSurface,
type: "popup"
}
}

let layer = QmlHelper.layerSurfaceManager.getIf(layerComponent, finder)
if (layer) {
return {
shell: layer,
item: layer.surfaceItem
item: layer.surfaceItem,
type: "layer"
}
}

let popup = QmlHelper.xdgSurfaceManager.getIf(popupComponent, finder)
if (popup) {
let xwayland = QmlHelper.xwaylandSurfaceManager.getIf(xwaylandComponent, finder)
if (xwayland) {
return {
shell: popup,
item: popup.xdgSurface
shell: xwayland,
item: xwayland,
type: "xwayland"
}
}

Expand All @@ -61,7 +73,7 @@ Item {
}

XdgSurface {
id: surface
id: toplevelSurfaceItem

property var doDestroy: helper.doDestroy

Expand All @@ -70,25 +82,32 @@ Item {

Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumWidth: Math.max(surface.minimumSize.width, 100)
Layout.minimumHeight: Math.max(surface.minimumSize.height, 50)
Layout.maximumWidth: surface.maximumSize.width
Layout.maximumHeight: surface.maximumSize.height
Component.onCompleted: {
if (Layout.horizontalStretchFactor !== undefined) {
// introduced in Qt 6.5
Layout.horizontalStretchFactor = 1
Layout.minimumWidth: Math.max(toplevelSurfaceItem.minimumSize.width, 100)
Layout.minimumHeight: Math.max(toplevelSurfaceItem.minimumSize.height, 50)
Layout.maximumWidth: toplevelSurfaceItem.maximumSize.width
Layout.maximumHeight: toplevelSurfaceItem.maximumSize.height
Layout.horizontalStretchFactor: 1
Layout.verticalStretchFactor: 1

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

onEnterOutput: function(output) {
waylandSurface.surface.enterOutput(output)
TreeLandHelper.onSurfaceEnterOutput(waylandSurface, toplevelSurfaceItem, output)
}
if (Layout.verticalStretchFactor !== undefined) {
Layout.verticalStretchFactor = 1
onLeaveOutput: function(output) {
waylandSurface.surface.leaveOutput(output)
TreeLandHelper.onSurfaceLeaveOutput(waylandSurface, toplevelSurfaceItem, output)
}
}

TiledToplevelHelper {
id: helper

surface: surface
waylandSurface: surface.waylandSurface
surface: toplevelSurfaceItem
waylandSurface: toplevelSurfaceItem.waylandSurface
creator: toplevelComponent
}
}
Expand All @@ -106,29 +125,77 @@ 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.shell : root
parent: parentItem ? parentItem.item : root
visible: parentItem && parentItem.item.effectiveVisible
&& waylandSurface.surface.mapped && waylandSurface.WaylandSocket.rootSocket.enabled
x: {
if (!parentItem)
return surface.implicitPosition.x
return surface.implicitPosition.x / parentItem.item.surfaceSizeRatio + parentItem.item.contentItem.x
let retX = 0 // X coordinate relative to parent
let minX = 0
let maxX = root.width - xdgSurface.width
if (!parentItem) {
retX = popupSurfaceItem.implicitPosition.x
if (retX > maxX)
retX = maxX
if (retX < minX)
retX = minX
} else {
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")
retX = retX - xdgSurface.width - parent.width
else
retX = maxX - parentX
}
if (retX + parentX < minX)
retX = minX - parentX
}
return retX
}
y: {
if (!parentItem)
return surface.implicitPosition.y
return surface.implicitPosition.y / parentItem.item.surfaceSizeRatio + parentItem.item.contentItem.y
let retY = 0 // Y coordinate relative to parent
let minY = 0
let maxY = root.height - xdgSurface.height
if (!parentItem) {
retY = popupSurfaceItem.implicitPosition.y
if (retY > maxY)
retY = maxY
if (retY < minY)
retY = minY
} else {
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
if (retY + parentY < minY)
retY = minY - parentY
}
return retY
}
padding: 0
background: null
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 All @@ -148,37 +215,46 @@ Item {
}

XWaylandSurfaceItem {
id: surface
id: xwaylandSurfaceItem

required property XWaylandSurface waylandSurface
property var doDestroy: helper.doDestroy

surface: waylandSurface
resizeMode: SurfaceItem.SizeToSurface
// TODO: Support popup/menu
positionMode: surface.effectiveVisible ? XWaylandSurfaceItem.PositionToSurface : XWaylandSurfaceItem.ManualPosition
positionMode: xwaylandSurfaceItem.effectiveVisible ? XWaylandSurfaceItem.PositionToSurface : XWaylandSurfaceItem.ManualPosition
z: (waylandSurface && waylandSurface.isActivated) ? 1 : 0

Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumWidth: Math.max(surface.minimumSize.width, 100)
Layout.minimumHeight: Math.max(surface.minimumSize.height, 50)
Layout.maximumWidth: surface.maximumSize.width
Layout.maximumHeight: surface.maximumSize.height
Component.onCompleted: {
if (Layout.horizontalStretchFactor !== undefined) {
// introduced in Qt 6.5
Layout.horizontalStretchFactor = 1
Layout.minimumWidth: Math.max(xwaylandSurfaceItem.minimumSize.width, 100)
Layout.minimumHeight: Math.max(xwaylandSurfaceItem.minimumSize.height, 50)
Layout.maximumWidth: xwaylandSurfaceItem.maximumSize.width
Layout.maximumHeight: xwaylandSurfaceItem.maximumSize.height
Layout.horizontalStretchFactor: 1
Layout.verticalStretchFactor: 1

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

onEnterOutput: function(output) {
if (xwaylandSurfaceItem.waylandSurface.surface)
xwaylandSurfaceItem.waylandSurface.surface.enterOutput(output);
TreeLandHelper.onSurfaceEnterOutput(waylandSurface, xwaylandSurfaceItem, output)
}
if (Layout.verticalStretchFactor !== undefined) {
Layout.verticalStretchFactor = 1
onLeaveOutput: function(output) {
if (xwaylandSurfaceItem.waylandSurface.surface)
xwaylandSurfaceItem.waylandSurface.surface.leaveOutput(output);
TreeLandHelper.onSurfaceLeaveOutput(waylandSurface, xwaylandSurfaceItem, output)
}
}

TiledToplevelHelper {
id: helper

surface: surface
surface: xwaylandSurfaceItem
waylandSurface: surface.waylandSurface
creator: xwaylandComponent
}
Expand Down

0 comments on commit 53b88e3

Please sign in to comment.