Skip to content

Commit

Permalink
Fix xwayland's position request
Browse files Browse the repository at this point in the history
  • Loading branch information
wineee authored and zccrs committed Oct 30, 2024
1 parent d7c5a93 commit 6e88ca5
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 183 deletions.
3 changes: 3 additions & 0 deletions examples/tinywl/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ void Helper::init()
wrapper->setNoTitleBar(false);
if (xwayland->decorationsType() != WXWaylandSurface::DecorationsNoBorder)
wrapper->setNoDecoration(false);
} else {
wrapper->setNoTitleBar(true);
wrapper->setNoDecoration(true);
}
};
connect(xwayland, &WXWaylandSurface::bypassManagerChanged, this, updateDecorationTitleBar);
Expand Down
2 changes: 2 additions & 0 deletions examples/tinywl/rootsurfacecontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ void RootSurfaceContainer::beginMoveResize(SurfaceWrapper *surface, Qt::Edges ed
moveResizeState.surface = surface;
moveResizeState.startGeometry = surface->geometry();
moveResizeState.resizeEdges = edges;
surface->setXwaylandPositionFromSurface(false);
surface->setPositionAutomatic(false);
}

Expand Down Expand Up @@ -200,6 +201,7 @@ void RootSurfaceContainer::endMoveResize()

ensureSurfaceNormalPositionValid(moveResizeState.surface);

moveResizeState.surface->setXwaylandPositionFromSurface(true);
moveResizeState.surface = nullptr;
Q_EMIT moveResizeFinised();
}
Expand Down
33 changes: 33 additions & 0 deletions examples/tinywl/surfacewrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SurfaceWrapper::SurfaceWrapper(QmlEngine *qmlEngine, WToplevelSurface *shellSurf
, m_titleBarState(TitleBarState::Default)
, m_noCornerRadius(false)
, m_alwaysOnTop(false)
, m_xwaylandPositionFromSurface(true)
{
QQmlEngine::setContextForObject(this, qmlEngine->rootContext());

Expand Down Expand Up @@ -76,6 +77,30 @@ SurfaceWrapper::SurfaceWrapper(QmlEngine *qmlEngine, WToplevelSurface *shellSurf
m_surfaceItem->setFocusPolicy(Qt::NoFocus);
#endif
}

if (type == Type::XWayland) {
auto xwaylandSurface = qobject_cast<WXWaylandSurface *>(shellSurface);
auto xwaylandSurfaceItem = qobject_cast<WXWaylandSurfaceItem*>(m_surfaceItem);

connect(xwaylandSurfaceItem, &WXWaylandSurfaceItem::implicitPositionChanged, this, [this, xwaylandSurfaceItem]() {
if (m_xwaylandPositionFromSurface)
moveNormalGeometryInOutput(xwaylandSurfaceItem->implicitPosition());
});

connect(this, &QQuickItem::xChanged, xwaylandSurface, [this, xwaylandSurfaceItem]() {
xwaylandSurfaceItem->moveTo(position(), !m_xwaylandPositionFromSurface);
});

connect(this, &QQuickItem::yChanged, xwaylandSurface, [this, xwaylandSurfaceItem]() {
xwaylandSurfaceItem->moveTo(position(), !m_xwaylandPositionFromSurface);
});

auto requestPos = xwaylandSurface->requestConfigureGeometry().topLeft();
if (!requestPos.isNull()) {
m_positionAutomatic = false;
moveNormalGeometryInOutput(xwaylandSurfaceItem->implicitPosition());
}
}
}

SurfaceWrapper::~SurfaceWrapper()
Expand Down Expand Up @@ -573,6 +598,8 @@ void SurfaceWrapper::onAnimationReady()

void SurfaceWrapper::onAnimationFinished()
{
setXwaylandPositionFromSurface(true);

Q_ASSERT(m_geometryAnimation);
m_geometryAnimation->deleteLater();
}
Expand All @@ -590,6 +617,7 @@ bool SurfaceWrapper::startStateChangeAnimation(State targetState, const QRectF &
ok = connect(m_geometryAnimation, SIGNAL(finished()), this, SLOT(onAnimationFinished()));
Q_ASSERT(ok);

setXwaylandPositionFromSurface(false);
ok = QMetaObject::invokeMethod(m_geometryAnimation, "start");
Q_ASSERT(ok);
return ok;
Expand Down Expand Up @@ -965,3 +993,8 @@ void SurfaceWrapper::updateExplicitAlwaysOnTop()
for (const auto& sub : std::as_const(m_subSurfaces))
sub->updateExplicitAlwaysOnTop();
}

void SurfaceWrapper::setXwaylandPositionFromSurface(bool value)
{
m_xwaylandPositionFromSurface = value;
}
3 changes: 3 additions & 0 deletions examples/tinywl/surfacewrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class SurfaceWrapper : public QQuickItem
bool showOnAllWorkspace() const;
void setShowOnAllWorkspace(bool showOnAllWorkspace);

void setXwaylandPositionFromSurface(bool value);

public Q_SLOTS:
// for titlebar
void requestMinimize();
Expand Down Expand Up @@ -262,4 +264,5 @@ public Q_SLOTS:
uint m_titleBarState:2;
uint m_noCornerRadius:1;
uint m_alwaysOnTop:1;
uint m_xwaylandPositionFromSurface:1;
};
Loading

0 comments on commit 6e88ca5

Please sign in to comment.