Skip to content

fix(xwayland): sync cursor global position to X server - #1430

Merged
zccrs merged 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/xwayland-cursor-sync
Sep 29, 2026
Merged

zccrs merged 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/xwayland-cursor-sync

Conversation

@deepin-wm

@deepin-wm deepin-wm commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

参照 #1426 的做法,直接在 WXWayland(waylib)里实现,无需 compositor 层介入。

问题

Xwayland 只在指针位于 X 窗口上时通过 wl_pointer 事件获知指针位置。当光标移动到原生 Wayland 窗口上时,X 侧的全局指针坐标停留在离开 X 窗口时的旧值,依赖全局坐标的 X window(如 XQueryPointer 的调用方)表现异常。

修复

waylib/src/server/protocols/wxwayland.cpp(+71):

  • 监听 seat cursor 的 positionChanged,光标移动时通过现有 xwm 连接 xcb_warp_pointer 将 X 指针同步到真实光标位置;
  • setSeat() 切换 seat 时重新绑定;events.ready 后同步一次初始位置(seat 可能先于 Xwayland 启动设置);
  • 指针位于 X 窗口上时坐标本已一致,warp 为 no-op;连接挂在 WXWayland 上,实例销毁时自动断开。

Log: 同步光标全局坐标到 Xwayland,使依赖光标全局坐标的 X window 表现正常

Summary by Sourcery

Keep Xwayland pointer coordinates synchronized with the actual cursor position.

Bug Fixes:

  • Synchronize Xwayland’s global pointer position with the compositor cursor while it moves across native Wayland surfaces, fixing stale coordinates reported to X clients.

Enhancements:

  • Rebind cursor tracking when the Xwayland seat changes and synchronize the initial position when the Xwayland connection becomes ready.

@sourcery-ai

sourcery-ai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Hooks each WXWayland instance to the seat cursor’s positionChanged signal and uses xcb_warp_pointer on the Xwayland root window to keep XQueryPointer and similar clients up to date while the cursor is over native Wayland surfaces.

Sequence diagram for synchronizing the cursor position with Xwayland

sequenceDiagram
    participant Cursor as WCursor
    participant Shell as ShellHandler
    participant XWayland as WXWayland
    participant XServer as XServer
    participant Client as XClient

    Cursor->>Shell: positionChanged
    Shell->>XWayland: xcbConnection()
    Shell->>XWayland: xcbScreen()
    Shell->>XServer: xcb_warp_pointer(root, qRound(pos.x()), qRound(pos.y()))
    Shell->>XServer: xcb_flush()
    Client->>XServer: XQueryPointer()
    XServer-->>Client: Current global cursor position
Loading

File-Level Changes

Change Details Files
Synchronize each Xwayland instance’s X pointer state with the compositor cursor position.
  • Subscribe to WCursor position changes when creating WXWayland instances.
  • Warp the X server pointer to rounded global cursor coordinates and flush the XCB connection.
  • Skip synchronization when the XCB connection or screen is unavailable; rely on QObject lifetime cleanup for disconnection.
src/core/shellhandler.cpp
src/core/shellhandler.h

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 1 issue

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

## Individual Comments

### Comment 1
<location path="src/core/shellhandler.cpp" line_range="549-563" />
<code_context>
     return xwayland;
 }

+void ShellHandler::syncXWaylandCursorPosition(WXWayland *xwayland, const QPointF &pos)
+{
+    auto *connection = xwayland->xcbConnection();
+    auto *screen = xwayland->xcbScreen();
+    if (!connection || !screen)
+        return;
+
+    // Warp the X pointer to the real cursor position. This only changes the
+    // X server's pointer state, not the real cursor. Warping to the current
+    // position is a no-op, so it is also safe while the pointer is over an
+    // Xwayland surface (Xwayland already tracks the position in that case).
+    xcb_warp_pointer(connection, XCB_NONE, screen->root,
+                     0, 0, 0, 0, qRound(pos.x()), qRound(pos.y()));
+    xcb_flush(connection);
+}
+
 void ShellHandler::removeXWayland(WXWayland *xwayland)
</code_context>
<issue_to_address>
**issue (bug_risk):** The function passes the compositor cursor's layout coordinates directly to `xcb_warp_pointer`, although the Xwayland desktop geometry can use scaled output coordinates. When an output has a scale or scale override different from 1, X clients receive a pointer position that is offset/scaled incorrectly instead of the real global position.

**Triggers:** When the Xwayland output geometry is scaled relative to the compositor output geometry, as indicated by the existing `outputGeometry`/`treelandGeometry` scaling in `updateXWaylandDesktopProperties`.

**Suggested fix:** Transform the cursor position from the compositor layout coordinate space into Xwayland's global coordinate space, applying the relevant output scale and offset before warping.
</issue_to_address>

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

Comment thread src/core/shellhandler.cpp Outdated

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 review overview

🟡 Changes recommended

空 seat 和服务重启路径仍会导致崩溃或同步失效 / Null-seat and server-restart paths can still crash or disable synchronization.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

该 PR 在现有 WXWayland wrapper 中同步 Wayland 光标位置到 Xwayland;wlroots 提供原生实现,Treeland 通过 ShellHandler 接入。
This PR synchronizes the Wayland cursor position to Xwayland within the existing WXWayland wrapper.

Changes:

  • 监听 WCursor::positionChanged 并通过 XCB 更新坐标 / Watches cursor movement and updates X coordinates through XCB.
  • seat 切换及 Xwayland ready 时重新绑定和同步 / Rebinds and synchronizes on seat changes and Xwayland readiness.
File Description
waylib/​src/​server/​protocols/​wxwayland.cpp 添加 Xwayland 光标坐标同步 / Adds Xwayland cursor-coordinate synchronization.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread waylib/src/server/protocols/wxwayland.cpp Outdated
@deepin-wm
deepin-wm force-pushed the fix/xwayland-cursor-sync branch from f846e32 to 92587c0 Compare September 29, 2026 06:21
zccrs
zccrs previously approved these changes Sep 29, 2026
Xwayland only learns the pointer position from wl_pointer events while
the pointer is over an X window. When the cursor moves over a native
Wayland surface, X clients querying the global cursor position (e.g.
via XQueryPointer) keep seeing stale coordinates, which breaks X
windows that rely on them.

Follow the same approach as the keyboard modifiers sync: do it inside
WXWayland. Watch the seat cursor's positionChanged, rebind on
setSeat(), and warp the X pointer through the existing xwm connection
on every cursor move. When the pointer is over an Xwayland surface the
position already matches, so the warp is a no-op.

Log: 同步光标全局坐标到 Xwayland,使依赖光标全局坐标的 X window 表现正常
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm, zccrs

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

@zccrs
zccrs merged commit 5fe9fd7 into linuxdeepin:master Sep 29, 2026
10 checks passed
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.

4 participants