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 committed Oct 25, 2024
1 parent d2467a6 commit 939da19
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 182 deletions.
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(false);
moveResizeState.surface = nullptr;
Q_EMIT moveResizeFinised();
}
Expand Down
51 changes: 51 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,48 @@ 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);


xwaylandSurface->safeConnect(&WXWaylandSurface::requestConfigure, this, [this,xwaylandSurfaceItem](QRect geometry, WXWaylandSurface::ConfigureFlags flags) {
if (m_xwaylandPositionFromSurface &&
flags.testAnyFlag(WXWaylandSurface::ConfigureFlag::XCB_CONFIG_WINDOW_POSITION)) {
//setPositionAutomatic(false);
moveNormalGeometryInOutput({
geometry.x() - xwaylandSurfaceItem->topPadding(),
geometry.y() - xwaylandSurfaceItem->leftPadding(),
});
}
});

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

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

// xwaylandSurface->requestConfigureFlags().testAnyFlags(WXWaylandSurface::ConfigureFlag::XCB_CONFIG_WINDOW_POSITION)
auto requestPos = xwaylandSurface->requestConfigureGeometry().topLeft();

if (!requestPos.isNull()) {
m_positionAutomatic = false;

//auto requestPos = xwaylandSurface->requestConfigureGeometry().topLeft();
moveNormalGeometryInOutput({
requestPos.x() - xwaylandSurfaceItem->topPadding(),
requestPos.y() - xwaylandSurfaceItem->leftPadding(),
});
}
qDebug() << "233333" << xwaylandSurface->requestConfigureFlags() << xwaylandSurface->requestConfigureGeometry();

}
}

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

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

Q_ASSERT(m_geometryAnimation);
m_geometryAnimation->deleteLater();
}
Expand All @@ -590,6 +635,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 +1011,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 939da19

Please sign in to comment.