Skip to content

fix: handle XWayland transient resize and parent association#1033

Closed
LFRon wants to merge 1 commit into
linuxdeepin:masterfrom
LFRon:fix/xwayland-dialog-popup
Closed

fix: handle XWayland transient resize and parent association#1033
LFRon wants to merge 1 commit into
linuxdeepin:masterfrom
LFRon:fix/xwayland-dialog-popup

Conversation

@LFRon

@LFRon LFRon commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

该PR用于修复两个连锁问题: 1. 微信左上角搜索框打开之后立刻消失 2. 我用GPT-5.5让微信搜索框能显示后窗口大小不能改变

Ensure XWayland transient surfaces wait for parent Wayland surface association before being reparented, avoiding premature fallback to the workspace container.

Apply mapped XWayland configure request sizes directly to the wrapper geometry so override-redirect dialog surfaces can receive their requested height on first show. Guard the geometry-change resize path to avoid feeding the same configure size back recursively.

Also expose XWayland parent surfaces through WToplevelSurface and add an explicit geometry configure entry point for XWayland surface items.

Summary by Sourcery

Fix XWayland transient dialog parenting and resize handling to keep transient windows attached to their parents and respect their requested sizes without recursive configure loops.

Bug Fixes:

  • Ensure surface wrappers are only reparented when a valid parent container exists and fall back to the workspace container safely when no parent is available.
  • Delay reparenting of XWayland transient surfaces until their parent Wayland surface is known, preventing premature attachment to the workspace container.
  • Apply XWayland configure-request sizes directly to wrapper geometry so override-redirect dialogs receive the correct initial size and avoid recursive geometryChange-triggered resizes.
  • Propagate parent surface changes from XWayland parent surfaces to WToplevelSurface and ensure connections are cleaned up on release to prevent stale signals.

Enhancements:

  • Expose XWayland parent surfaces via WToplevelSurface and add an explicit geometry configure entry point on WXWaylandSurfaceItem for fine-grained X11 dialog management.
  • Guard SurfaceWrapper geometry changes with a flag and initialize pending state defaults to keep internal state consistent during XWayland-driven resizes.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LFRon

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

@deepin-ci-robot

Copy link
Copy Markdown

Hi @LFRon. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai

sourcery-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Ensures XWayland transient surfaces only reparent once their Wayland parent is known, and applies XWayland configure-request sizes directly to the wrapper geometry while preventing recursive resize feedback, plus exposes parent surfaces and explicit geometry configuration hooks for XWayland surfaces/items.

Sequence diagram for XWayland configure-request driven resize

sequenceDiagram
    participant WXWaylandSurface
    participant SurfaceWrapper
    participant WXWaylandSurfaceItem

    WXWaylandSurface->>SurfaceWrapper: requestConfigure(flags)
    SurfaceWrapper->>SurfaceWrapper: [flags has XCB_CONFIG_WINDOW_SIZE]
    SurfaceWrapper->>SurfaceWrapper: updateSurfaceSizeRatio()
    SurfaceWrapper->>WXWaylandSurface: requestConfigureGeometry()
    WXWaylandSurface-->>SurfaceWrapper: requestGeometry
    SurfaceWrapper->>WXWaylandSurface: geometry()
    WXWaylandSurface-->>SurfaceWrapper: currentBufferSize
    SurfaceWrapper->>WXWaylandSurfaceItem: surfaceSizeRatio()
    WXWaylandSurfaceItem-->>SurfaceWrapper: surfaceSizeRatio
    SurfaceWrapper->>SurfaceWrapper: compute requestedSceneSize
    SurfaceWrapper->>SurfaceWrapper: setNormalGeometry(requestedNormalGeometry)
    SurfaceWrapper->>SurfaceWrapper: [isNormal && !m_geometryAnimation]
    SurfaceWrapper->>SurfaceWrapper: m_applyingXwaylandConfigureRequestSize = true
    SurfaceWrapper->>SurfaceWrapper: setSize(requestedSceneSize)
    SurfaceWrapper->>SurfaceWrapper: m_applyingXwaylandConfigureRequestSize = false
    SurfaceWrapper->>WXWaylandSurfaceItem: configureSurfaceGeometry(configureGeometry)

    SurfaceWrapper->>SurfaceWrapper: geometryChange(newGeo, oldGeo)
    SurfaceWrapper->>SurfaceWrapper: [widthValid && heightValid && !m_applyingXwaylandConfigureRequestSize]
    SurfaceWrapper->>SurfaceWrapper: resize(newGeometry.size())
Loading

File-Level Changes

Change Details Files
Make wrapper reparenting robust to missing or invalid parent XWayland/Wayland surfaces and avoid premature fallback to the workspace container.
  • Add null checks for wrapper and its shell/surface before reparenting.
  • Resolve parent wrapper/container defensively and only add as subsurface when both wrapper and container are valid and not self.
  • Factor fallback logic so wrappers without a valid parent are attached or kept in the workspace container without redundant moves.
src/core/shellhandler.cpp
Ensure XWayland wrappers wait for a valid parent Wayland surface before reparenting and connect parent-surface changes safely via QPointer.
  • Wrap the parent-surface update lambda with QPointer captures for ShellHandler, SurfaceWrapper, and WXWaylandSurface to avoid use-after-free.
  • Ignore callbacks if the wrapper's shellSurface no longer matches the WXWaylandSurface or the surface is not yet created.
  • Defer reparenting when a parent XWayland surface exists but its Wayland surface is not yet associated, and connect parentSurfaceChanged to the wrapper instead of the handler.
src/core/shellhandler.cpp
Apply XWayland configure-request sizes directly to SurfaceWrapper geometry and avoid recursive resize feedback loops.
  • Handle WXWaylandSurface::requestConfigure on SurfaceWrapper to compute scene size from requested buffer size and surfaceSizeRatio, including padding.
  • Skip updates when size is invalid, unchanged, or the surface is bypassing the manager, and update normalGeometry / geometry animation appropriately.
  • Mark a new m_applyingXwaylandConfigureRequestSize flag while applying configure-request-driven size, and guard geometryChange-based resize() calls with this flag to prevent feeding back the same configure.
  • Propagate configureGeometry back to WXWaylandSurfaceItem via a new configureSurfaceGeometry API when the buffer size changes and the wrapper controls position.
src/surface/surfacewrapper.cpp
src/surface/surfacewrapper.h
waylib/src/server/qtquick/wxwaylandsurfaceitem.cpp
waylib/src/server/qtquick/wxwaylandsurfaceitem.h
Expose XWayland parent surfaces and ensure parent-surface-change signals are wired correctly for transients.
  • Track a connection to the parent WToplevelSurface::surfaceChanged signal inside WXWaylandSurfacePrivate and clean it up in instantRelease and when updating parents.
  • Emit parentSurfaceChanged only when the underlying WSurface actually changes, and wire parent->surfaceChanged to this signal on parent updates.
  • Expose parentSurface() on WXWaylandSurface as a WToplevelSurface override returning the parent XWayland surface’s WSurface.
waylib/src/server/protocols/wxwaylandsurface.cpp
waylib/src/server/protocols/wxwaylandsurface.h
Minor robustness and defaults for XWayland-related types.
  • Default m_pendingState to State::Normal in SurfaceWrapper to avoid undefined initial state.
  • Include missing Qt headers (QMetaObject, QRect, QMetaEnum) required by new APIs and connections in WXWayland-related files.
src/surface/surfacewrapper.h
waylib/src/server/protocols/wxwayland.cpp
waylib/src/server/protocols/wxwaylandsurface.cpp
waylib/src/server/qtquick/wxwaylandsurfaceitem.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 left some high level feedback:

  • The XWayland requestConfigure handling lambda inside SurfaceWrapper::setup has grown quite complex (size-ratio computations, early returns, geometry updates, recursive guards); consider extracting it into a dedicated member function to improve readability and make future changes less error-prone.
  • In WXWaylandSurfacePrivate::updateParent, parentSurfaceChanged can now be emitted both explicitly (when oldParentSurface != newParentSurface) and via the new connection to the parent’s surfaceChanged signal; double-check whether this can lead to duplicate notifications for listeners and whether you want to centralize that emission in one place.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The XWayland `requestConfigure` handling lambda inside `SurfaceWrapper::setup` has grown quite complex (size-ratio computations, early returns, geometry updates, recursive guards); consider extracting it into a dedicated member function to improve readability and make future changes less error-prone.
- In `WXWaylandSurfacePrivate::updateParent`, `parentSurfaceChanged` can now be emitted both explicitly (when `oldParentSurface != newParentSurface`) and via the new connection to the parent’s `surfaceChanged` signal; double-check whether this can lead to duplicate notifications for listeners and whether you want to centralize that emission in one place.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-bot

deepin-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.8.12
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1036

@LFRon LFRon force-pushed the fix/xwayland-dialog-popup branch 2 times, most recently from 408e166 to da22ee0 Compare June 23, 2026 04:20

@zccrs zccrs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

看代码改了很多,不过应该不全是有效代码。这个问题的根因是啥?光看代码没看出来改动逻辑是什么。

[this, xwaylandSurfaceItem]() {
const QPointF implicitPosition = xwaylandSurfaceItem->implicitPosition();
if (m_xwaylandPositionFromSurface)
moveNormalGeometryInOutput(xwaylandSurfaceItem->implicitPosition());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这个改动有必要吗?

Comment thread src/surface/surfacewrapper.cpp Outdated
moveNormalGeometryInOutput(implicitPosition);
});

connect(xwaylandSurface,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

为什么会单独连接它?有requestConfigure时就会触发 &WXWaylandSurfaceItem::implicitPositionChanged 和 WSurfaceItem::implicitWidthChanged 和 WSurfaceItem::implicitHeightChanged

@LFRon LFRon force-pushed the fix/xwayland-dialog-popup branch 2 times, most recently from 4d69145 to 9fbf966 Compare June 25, 2026 07:16
@deepin-bot

deepin-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.8.13
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1063

@LFRon LFRon force-pushed the fix/xwayland-dialog-popup branch 2 times, most recently from 3a68039 to 97f8be9 Compare June 26, 2026 13:31
@LFRon

LFRon commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

看代码改了很多,不过应该不全是有效代码。这个问题的根因是啥?光看代码没看出来改动逻辑是什么。

VirtualBox 菜单瞬间关闭的根因不是动画,也不是菜单 surface 本身坏了,而是 XWayland override-redirect 菜单弹出时,鼠标按钮还按着,treeland 让 pointer focus 立刻从原窗口切到新菜单 surface。wlroots 在 pointer focus surface 变化时会 reset_buttons(),也就是把 button_count 清零。随后释放鼠标时,release 和 press 的状态链断了,VBox 就像收到了一次菜单项选择/关闭,于是菜单刚出现就关闭。
另外前一个几何/父子关系修复的根因是:XWayland transient 可能先有 X11 parent 关系,但对应 Wayland surface() 还没 associate;mapped 后的 ConfigureRequest 又只是 X11 client 的请求,实际 set_geometry/ConfigureNotify 会晚到。以前 treeland 太早 reparent,或者没有及时把 mapped configure size 应用到 wrapper 几何,导致 transient/dialog 初始位置或大小不对。

然后关于 requestConfigure:质疑方向是对的,代码确实显得绕。但按当前代码,不能简单删掉 SurfaceWrapper 里对 WXWaylandSurface::requestConfigure 的处理,因为 SurfaceWrapper 把 m_surfaceItem 设成了 ManualResize,WXWaylandSurfaceItem 的 requestConfigure 连接目前只在 position mask 时发 implicitPositionChanged,并不会自动把 wrapper 的 actual size / normalGeometry 改掉。这个 handler 的作用是处理 mapped XWayland 的 size configure request,并回 configure() 给 XWayland。

然后GPT-5.5确实承认了多改了代码, 我等下force-push上来 (

@LFRon LFRon force-pushed the fix/xwayland-dialog-popup branch from 97f8be9 to bbf6ae1 Compare June 26, 2026 14:12
XWayland override-redirect transients and mapped X11 configure flows can arrive before treeland has a wrapper/container ready. Focus or pointer transitions during the opening click also let wlroots reset pointer button state, so dialogs and menus from apps such as WeChat and VirtualBox could close immediately after appearing.

Forward wlroots focus_in/grab_focus through qwlroots and waylib, defer override-redirect focus until the surface is mapped, and apply it only when wlroots reports the surface wants keyboard focus. Defer pointer enter/clear while buttons are held so the click that opens a popup is not converted into an unintended release/activation.

Wait for parent association before reparenting XWayland children, accept mapped ConfigureRequest sizes for managed XWayland windows, guard recursive resize feedback, and sync the accepted content size after X11 configure to avoid transient main-window artifacts. Keep the remaining debug output focused on the core deferred/applied/dropped decisions.
@LFRon LFRon force-pushed the fix/xwayland-dialog-popup branch from bbf6ae1 to 8920e96 Compare June 29, 2026 09:23
@LFRon

LFRon commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

修不好, 微信搜索框的光标一直失焦, 不失焦就在截图后直接无法聚焦搜索框本体, 先关了这个PR

@LFRon LFRon closed this Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants