Skip to content

fix(xwayland): sync X11 window position on compositor-driven moves - #1757

Open
wineee wants to merge 1 commit into
linuxdeepin:masterfrom
wineee:fix-xwayland
Open

wineee wants to merge 1 commit into
linuxdeepin:masterfrom
wineee:fix-xwayland

Conversation

@wineee

@wineee wineee commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

SurfaceWrapper::setup() previously passed !m_xwaylandPositionFromSurface
as configSurface to WXWaylandSurfaceItem::moveTo(), and
m_xwaylandPositionFromSurface defaults to true (and is restored to true
after interactive move/resize and animations). Consequently, any
compositor-driven move that does not toggle m_xwaylandPositionFromSurface
— such as RootSurfaceContainer::moveSurfacesToOutput() when unplugging an
external screen, ensureSurfaceNormalPositionValid(), output layout
clamping, or state geometry updates — moved only the QtQuick item while
leaving the X11 window at stale off-screen coordinates, causing pointer
hit-testing in Xwayland to hit the root window (X cursor, no mouse input).

In addition, WXWaylandSurfaceItemPrivate::configureSurface() dropped
configure requests whenever !q->isVisible() without replaying them when
the item became visible again.

  1. Track client-initiated position updates separately in SurfaceWrapper
    via m_applyingXwaylandImplicitPosition (using QScopedValueRollback
    when applying implicitPosition), while keeping
    m_xwaylandPositionFromSurface for inbound implicitPositionChanged
    gating. All other xChanged/yChanged updates now pass
    configSurface = true to WXWaylandSurfaceItem::moveTo().
  2. Track pendingConfigure / pendingConfigureSize in
    WXWaylandSurfaceItem (guarded by positionConfigured || hasExplicitSize
    so hidden proxy items do not overwrite the real X11 window position) and
    replay the pending configure when ItemVisibleHasChanged transitions to
    visible.

fix(xwayland): 在合成器主动移动窗口时同步 X11 窗口坐标

此前 SurfaceWrapper::setup() 在 xChanged/yChanged 中向
WXWaylandSurfaceItem::moveTo() 传入 !m_xwaylandPositionFromSurface,而
m_xwaylandPositionFromSurface 默认为 true 并在拖拽/动画结束后复位为 true。
这导致合成器主动发起但未显式关闭该标记的移动(如拔掉外接屏时
RootSurfaceContainer::moveSurfacesToOutput()、边界约束
ensureSurfaceNormalPositionValid()、输出布局重排及最大化/全屏/平铺几
何更新)只移动了 QtQuick 项位置而没有向 Xwayland 发送 configure,X11
窗口坐标仍留在已移除屏幕区域外,导致鼠标命中 root 窗口(光标变为 X 号且
鼠标事件失效)。

此外,WXWaylandSurfaceItemPrivate::configureSurface() 在 item 不可见时
直接丢弃 configure 请求,窗口恢复可见后也不会补发。

  1. 在 SurfaceWrapper 中新增 m_applyingXwaylandImplicitPosition(仅在应用
    来自客户端的 implicitPosition 时通过 QScopedValueRollback 置位),
    保留 m_xwaylandPositionFromSurface 控制入向同步,使所有合成器主动移动
    都会向 WXWaylandSurfaceItem::moveTo() 传入 configSurface = true。
  2. 在 WXWaylandSurfaceItem 中记录不可见期间被跳过的
    pendingConfigure / pendingConfigureSize(仅当 positionConfigured
    或存在显式尺寸更新时记录,避免隐藏的代理 item 在可见时覆盖真实窗口坐
    标),并在 ItemVisibleHasChanged 变为可见时补发 configure。

Log: 修复双屏拔掉外接屏等合成器移动 X11 窗口后 X11 坐标未同步导致鼠标事件失效的问题
Influence: X11 窗口在多屏拔插、边界修正、布局重排及隐藏后恢复显示时均可正确同步 X11 坐标与指针命中

Summary by Sourcery

Keep XWayland window geometry synchronized during compositor moves and visibility changes.

Bug Fixes:

  • Synchronize X11 window coordinates with compositor-driven moves, preventing stale positions from breaking pointer hit-testing after output changes, layout adjustments, and geometry updates.
  • Replay position or size configuration requests skipped while an XWayland item is hidden when it becomes visible again.
  • Prevent proxy surface wrappers from resizing a shared surface.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wineee

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Track and replay XWayland configure requests while the surface item is hidden, preserving the correct position and resize behavior on replay.

  • waylib/src/server/qtquick/wxwaylandsurfaceitem.cpp L34-54, L89-96, L295-309 (+5 small edits)
  • waylib/src/server/qtquick/wxwaylandsurfaceitem.h L48

Separate client-originated implicit-position updates from compositor-driven moves so compositor moves configure XWayland, and prevent proxy wrappers from resizing the shared surface.

  • src/surface/surfacewrapper.cpp L557-560, L583-587 (+2 small edits)
  • src/surface/surfacewrapper.h L717-718, L747-751
  • waylib/examples/tinywl/surfacewrapper.cpp L18-19, L104-115, L121
  • waylib/examples/tinywl/surfacewrapper.h L271-274

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 7 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/surface/surfacewrapper.cpp" line_range="558" />
<code_context>
                 [this, xwaylandSurfaceItem]() {
-                    if (m_xwaylandPositionFromSurface)
+                    if (m_xwaylandPositionFromSurface) {
+                        QScopedValueRollback<bool> guard(m_applyingXwaylandImplicitPosition, true);
                         moveNormalGeometryInOutput(xwaylandSurfaceItem->implicitPosition());
+                    }
</code_context>
<issue_to_address>
**Client moves get echoed back**

When an inbound XWayland position update retargets an active geometry animation, `QScopedValueRollback` restores `m_applyingXwaylandImplicitPosition` when the handler returns, before `m_geometryAnimation` changes `x` or `y`; the change signals then call `moveTo(..., true)` and send intermediate compositor positions to XWayland instead of preserving the client-requested position.

Keep inbound-position suppression active for animation-driven `x`/`y` changes, not just while setting the animation target.

Also at `src/surface/surfacewrapper.cpp:583`.
</issue_to_address>

### Comment 2
<location path="waylib/src/server/qtquick/wxwaylandsurfaceitem.cpp" line_range="39-40" />
<code_context>
+    if (!q->xwaylandSurface())
         return;
+    if (!q->isVisible()) {
+        if (positionConfigured || hasExplicitSize) {
+            pendingConfigure = true;
+            if (hasExplicitSize)
+                pendingConfigureSize = newGeometry.size();
</code_context>
<issue_to_address>
**Accepted requests get no configure**

When a hidden, not-yet-position-configured XWayland item receives an accepted position-only request or a configure request without an explicit size, `configureSurface()` leaves `pendingConfigure` false because neither `positionConfigured` nor `hasExplicitSize` is true; `itemChange()` then skips replaying the request when the item becomes visible, so the client receives no configure notification.

Set `pendingConfigure` for every accepted configure request received while the item is hidden.
</issue_to_address>

### Comment 3
<location path="waylib/src/server/qtquick/wxwaylandsurfaceitem.cpp" line_range="42" />
<code_context>
+        if (positionConfigured || hasExplicitSize) {
+            pendingConfigure = true;
+            if (hasExplicitSize)
+                pendingConfigureSize = newGeometry.size();
+        }
+        return;
</code_context>
<issue_to_address>
**Hidden configure replays stale size**

When a hidden item has an explicit-size configure pending and then receives a configure with a newer expected size but no explicit size, `pendingConfigureSize` retains the earlier size, and `itemChange()` prefers it over `expectSurfaceSize()` when replaying the configure; the X11 window therefore receives the stale size.

Update `pendingConfigureSize` to the latest expected size when handling each hidden configure, including those without an explicit size.
</issue_to_address>

### Comment 4
<location path="waylib/src/server/qtquick/wxwaylandsurfaceitem.cpp" line_range="39-43" />
<code_context>
+    if (!q->xwaylandSurface())
         return;
+    if (!q->isVisible()) {
+        if (positionConfigured || hasExplicitSize) {
+            pendingConfigure = true;
+            if (hasExplicitSize)
+                pendingConfigureSize = newGeometry.size();
+        }
+        return;
+    }
</code_context>
<issue_to_address>
**Hidden proxy resize can reset X11 position**

When a hidden proxy item receives an explicit resize and is later shown, when a hidden proxy item receives an explicit resize before becoming visible, `hasExplicitSize` sets `pendingConfigure` even though `positionConfigured` is false. The visibility handler then configures the shared XWayland surface using the proxy’s `explicitSurfacePosition()`, which is not synchronized by the non-proxy-only position connections, so the real window receives the proxy’s stale position.

Do not replay a proxy’s explicit-size configure with its own position; keep the real surface position when replaying size-only updates or exclude proxy items from configure replay.
</issue_to_address>

### Comment 5
<location path="src/surface/surfacewrapper.cpp" line_range="583" />
<code_context>

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

</code_context>
<issue_to_address>
**Diagonal moves send intermediate coordinates**

When a compositor-driven move changes both x and y, a compositor move that changes both axes invokes both callbacks, and each calls `moveTo()` with configuration enabled. `WXWaylandSurfaceItem::updatePosition()` therefore sends one configure with the new first-axis coordinate and stale second-axis coordinate, then another with the final position; Xwayland clients receive an unnecessary intermediate position.

Coalesce axis changes and configure Xwayland once with the completed position update.

Also at `src/surface/surfacewrapper.cpp:588`.
</issue_to_address>

### Comment 6
<location path="src/surface/surfacewrapper.cpp" line_range="583" />
<code_context>

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

</code_context>
<issue_to_address>
**Example keeps stale move behavior**

When the tinywl example handles a compositor-driven XWayland move while `m_xwaylandPositionFromSurface` is true, the tinywl example retains the old `!m_xwaylandPositionFromSurface` gating, so compositor-driven moves there still move only the QtQuick item and leave the X11 window at its old coordinates.

Apply the same inbound-update guard distinction to the tinywl example's XWayland position handlers.
</issue_to_address>

### Comment 7
<location path="src/surface/surfacewrapper.cpp" line_range="583" />
<code_context>

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

</code_context>
<issue_to_address>
**X11 configure behavior lacks wire tests**

When compositor-driven movement or visibility restoration triggers the new configure paths, `moveTo()` and the visibility-restoration path call `WXWaylandSurface::configure()`, which sends XWayland configure notifications, but the change adds no protocol-wire test for either path. Regressions in compositor-driven X11 position synchronization therefore go undetected.

Add a test that observes the resulting X11 configure/position behavior on the wire for compositor-driven moves and deferred configure replay.

Also at `waylib/src/server/qtquick/wxwaylandsurfaceitem.cpp:287`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/surface/surfacewrapper.cpp Resolved
Comment thread src/surface/surfacewrapper.cpp Resolved
Comment thread src/surface/surfacewrapper.cpp Resolved
Comment thread src/surface/surfacewrapper.cpp Resolved
@wineee
wineee requested an adaptive review from Copilot December 3, 2026 06:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A moderate active issue remains because replaying a pending resize can overwrite the real X11 window position with stale or default coordinates.

1 open issue

Review effort: Lite

SurfaceWrapper::setup() previously passed `!m_xwaylandPositionFromSurface`
as `configSurface` to `WXWaylandSurfaceItem::moveTo()`, and
`m_xwaylandPositionFromSurface` defaults to true (and is restored to true
after interactive move/resize and animations). Consequently, any
compositor-driven move that does not toggle `m_xwaylandPositionFromSurface`
— such as `RootSurfaceContainer::moveSurfacesToOutput()` when unplugging an
external screen, `ensureSurfaceNormalPositionValid()`, output layout
clamping, or state geometry updates — moved only the QtQuick item while
leaving the X11 window at stale off-screen coordinates, causing pointer
hit-testing in Xwayland to hit the root window (X cursor, no mouse input).

In addition, `WXWaylandSurfaceItemPrivate::configureSurface()` dropped
configure requests whenever `!q->isVisible()` without replaying them when
the item became visible again.

1. Track client-initiated position updates separately in `SurfaceWrapper`
   (and sync the `tinywl` example `SurfaceWrapper`) via
   `m_applyingXwaylandImplicitPosition` (using `QScopedValueRollback` when
   applying `implicitPosition`), while keeping `m_xwaylandPositionFromSurface`
   for inbound `implicitPositionChanged` gating. All other `xChanged`/
   `yChanged` updates now pass `configSurface = true` to
   `WXWaylandSurfaceItem::moveTo()`.
2. Track `pendingConfigure` / `pendingConfigureSize` in
   `WXWaylandSurfaceItem` (guarded by `positionConfigured || hasExplicitSize`;
   clearing `pendingConfigureSize` on non-`ManualResize` position-only updates
   so dynamic resize modes recompute on replay) and replay the pending
   configure when `ItemVisibleHasChanged` transitions to visible.
3. Add `configurePosition()` in `WXWaylandSurfaceItemPrivate` so
   `doResizeSurface()` and replay fall back to
   `xwaylandSurface()->geometry().topLeft()` when `!positionConfigured`,
   and guard `SurfaceWrapper::resize()` against `m_isProxy` so proxy
   wrappers never resize or overwrite the shared X11 window's position.

fix(xwayland): 在合成器主动移动窗口时同步 X11 窗口坐标

此前 `SurfaceWrapper::setup()` 在 `xChanged`/`yChanged` 中向
`WXWaylandSurfaceItem::moveTo()` 传入 `!m_xwaylandPositionFromSurface`,而
`m_xwaylandPositionFromSurface` 默认为 true 并在拖拽/动画结束后复位为 true。
这导致合成器主动发起但未显式关闭该标记的移动(如拔掉外接屏时
`RootSurfaceContainer::moveSurfacesToOutput()`、边界约束
`ensureSurfaceNormalPositionValid()`、输出布局重排及最大化/全屏/平铺几
何更新)只移动了 QtQuick 项位置而没有向 Xwayland 发送 `configure`,X11
窗口坐标仍留在已移除屏幕区域外,导致鼠标命中 root 窗口(光标变为 X 号且
鼠标事件失效)。

此外,`WXWaylandSurfaceItemPrivate::configureSurface()` 在 item 不可见时
直接丢弃 configure 请求,窗口恢复可见后也不会补发。

1. 在 `SurfaceWrapper`(并同步至 `tinywl` 示例的 `SurfaceWrapper`)中新增
   `m_applyingXwaylandImplicitPosition`(仅在应用来自客户端的
   `implicitPosition` 时通过 `QScopedValueRollback` 置位),保留
   `m_xwaylandPositionFromSurface` 控制入向同步,使所有合成器主动移动都会
   向 `WXWaylandSurfaceItem::moveTo()` 传入 `configSurface = true`。
2. 在 `WXWaylandSurfaceItem` 中记录不可见期间被跳过的
   `pendingConfigure` / `pendingConfigureSize`(仅当 `positionConfigured`
   或存在显式尺寸更新时记录;在非 `ManualResize` 下收到仅位置更新时清空
   旧的 `pendingConfigureSize` 以便可见时按最新期望尺寸重算),并在
   `ItemVisibleHasChanged` 变为可见时补发 `configure`。
3. 新增 `WXWaylandSurfaceItemPrivate::configurePosition()`,在
   `!positionConfigured` 时由 `doResizeSurface()` 与补发路径回退到
   `xwaylandSurface()->geometry().topLeft()`,并在
   `SurfaceWrapper::resize()` 中拦截 `m_isProxy`,防止代理 wrapper 通过
   共享 surface 覆盖或篡改真实 X11 窗口尺寸与坐标。

Log: 修复双屏拔掉外接屏等合成器移动 X11 窗口后 X11 坐标未同步导致鼠标事件失效的问题
Influence: X11 窗口在多屏拔插、边界修正、布局重排及隐藏后恢复显示时均可正确同步 X11 坐标与指针命中,且代理窗口不会覆盖真实窗口坐标
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants