Skip to content

feat(dock): support compositor-driven dock resize - #1732

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
gugullll:master
Oct 16, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
gugullll:master

Conversation

@gugullll

@gugullll gugullll commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Add a client wrapper for the treeland layer-shell-extension protocol and wire it into the dock so the compositor owns the interactive resize (referenced protocol PR linuxdeepin/treeland-protocols#104).

加入 layer-shell-extension 协议客户端封装,合成器接管 dock 交互缩放,
替代客户端自身拖拽逻辑。

Log: dock 支持合成器接管缩放
PMS: BUG-294673
Influence: 合成器接管 dock 缩放交互,状态机改为 compositorOwnsResize 驱动,
拖拽期间屏蔽客户端手动计算,flow 与可执行尺寸更稳定。

Summary by Sourcery

Enable the compositor to own dock resize interactions while retaining client-side resizing as a fallback on unsupported platforms.

New Features:

  • Add compositor-driven interactive resizing for the dock through the Treeland layer-shell extension protocol.

Enhancements:

  • Update dock resizing state handling so compositor-controlled size changes drive the UI while client-side drag calculations are bypassed.

Build:

  • Generate and include the Treeland layer-shell extension Wayland client protocol sources.

@sourcery-ai

sourcery-ai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

The dock now negotiates compositor-owned interactive resizing through the Treeland layer-shell extension, passing Wayland input and size constraints to the compositor and adapting the QML drag state machine to consume compositor-driven size and lifecycle updates, with legacy client-side resizing retained as a fallback.

Sequence diagram for compositor-driven dock resize

sequenceDiagram
    actor User
    participant DragArea
    participant DockPanel
    participant LayerShell as LayerShellExtension
    participant Compositor

    User->>DragArea: onPressed
    DragArea->>DockPanel: beginDockResize(edges)
    DockPanel->>LayerShell: getLayerShellExtensionObject(surface)
    DockPanel->>LayerShell: beginResize(seat, serial, edges, constraints)
    LayerShell->>Compositor: begin_resize(...)
    Compositor-->>LayerShell: resizing(1)
    LayerShell-->>DockPanel: resizingChanged(true)
    DockPanel-->>DragArea: onIsResizingChanged(true)
    Compositor-->>DragArea: configure size
    DragArea->>DragArea: update dockSize from width or height
    User-->>Compositor: release pointer
    Compositor-->>LayerShell: resizing(0)
    LayerShell-->>DockPanel: resizingChanged(false)
    DockPanel-->>DragArea: onIsResizingChanged(false)
    DragArea->>DragArea: finishResize()
Loading

Flow diagram for dock resize fallback

flowchart TD
    Press["Dock drag begins"] --> Begin["Panel.beginDockResize(edges)"]
    Begin --> Available{"Layer-shell extension active and Wayland handles available?"}
    Available -->|Yes| Compositor["Compositor owns resize"]
    Compositor --> Ignore["Ignore client-side position calculations"]
    Ignore --> Configure["Apply compositor-driven width or height"]
    Configure --> End["resizingChanged(false) and finishResize()"]
    Available -->|No| Legacy["Use legacy client-side drag logic"]
    Legacy --> End
Loading

File-Level Changes

Change Details Files
Add a Qt Wayland client wrapper for Treeland’s layer-shell extension resize protocol.
  • Generate the new protocol client sources during the dock build.
  • Wrap the manager and per-surface object, including resize requests and compositor resizing notifications.
  • Track the native wl_surface and expose resize-state changes to the dock panel.
panels/dock/CMakeLists.txt
panels/dock/layershellextension.h
panels/dock/layershellextension.cpp
Route dock resize initiation through the compositor when the extension is available, while preserving the legacy fallback.
  • Create the protocol manager on Wayland and lazily bind an extension object to the current dock surface.
  • Pass the current seat, pointer serial, resize edge, and orientation-specific size limits to begin_resize.
  • Forward compositor resize notifications into the panel resize state and return failure when the protocol path cannot be used.
panels/dock/dockpanel.h
panels/dock/dockpanel.cpp
panels/dock/constants.h
Update the QML drag state machine to defer interactive resizing and completion to the compositor.
  • Add compositor ownership and notification state flags around drag initiation.
  • Skip client-side mouse-delta resizing while compositor ownership is active and synchronize dockSize from compositor-driven width or height changes.
  • Ignore stray pointer releases during compositor resizing and finalize state when the compositor reports resizing ended.
panels/dock/package/main.qml

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 2 issues

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

## Individual Comments

### Comment 1
<location path="panels/dock/package/main.qml" line_range="656-671" />
<code_context>
             recentDeltas = []
             Panel.requestClosePopup()
+
+            var edges = 0
+            if (Panel.position === Dock.Bottom) {
+                edges = Dock.ResizeEdgeTop
+            } else if (Panel.position === Dock.Top) {
+                edges = Dock.ResizeEdgeBottom
+            } else if (Panel.position === Dock.Right) {
+                edges = Dock.ResizeEdgeLeft
+            } else if (Panel.position === Dock.Left) {
+                edges = Dock.ResizeEdgeRight
+            }
+            dock.resizingReceived = false
+            var accepted = Panel.beginDockResize(edges)
</code_context>
<issue_to_address>
**issue (bug_risk):** The mouse release can arrive before the compositor's asynchronous `resizing(1)` event. In that order `resizingReceived` is still false, so `finishResize()` clears `compositorOwnsResize` and releases the grab even though the compositor resize has already been requested; the later compositor resize events then run against a completed client drag and the resize state is lost.

**Triggers:** When the user presses and releases quickly before the compositor's `resizing(1)` event reaches the client.

**Suggested fix:** Track that a compositor resize was requested independently of receipt of `resizing(1)`, and defer finishing the drag until the compositor explicitly reports the resize has ended.
</issue_to_address>

### Comment 2
<location path="panels/dock/layershellextension.h" line_range="47-48" />
<code_context>
+
+    void beginResize(struct ::wl_seat *seat, uint32_t serial, uint32_t edges, int32_t minWidth, int32_t minHeight, int32_t maxWidth, int32_t maxHeight);
+
+    // Rejects begin_resize once that surface is destroyed; callers compare it
+    // against the window's current wl_surface and re-bind when it changed.
+    struct ::wl_surface *nativeSurface() const;
+
+Q_SIGNALS:
</code_context>
<issue_to_address>
**nitpick:** The comment says the wrapper rejects `begin_resize` after the surface is destroyed, but `nativeSurface()` only returns a stored pointer and performs no validity check or rejection. The actual safety behavior depends entirely on the caller comparing the pointer, so the wrapper's documented contract is false and future callers can invoke the protocol operation with a stale surface association.

**Suggested fix:** Change the comment to describe the caller-side comparison, or make `beginResize()` validate the native surface/object lifetime before issuing the request.

```suggestion
    // Returns the surface associated with this object; callers compare it
    // against the window's current wl_surface and re-bind when it changed.
```
</issue_to_address>

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

Comment thread panels/dock/package/main.qml Outdated
Comment thread panels/dock/layershellextension.h Outdated
@deepin-bot

deepin-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 2.0.54
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1733

Comment thread panels/dock/package/main.qml Outdated
Comment thread panels/dock/CMakeLists.txt
Comment thread panels/dock/dockpanel.cpp
Comment thread panels/dock/dockpanel.cpp Outdated
Comment thread panels/dock/dockpanel.cpp Outdated
Comment thread panels/dock/dockpanel.h Outdated
@gugullll
gugullll force-pushed the master branch 2 times, most recently from 11e2004 to cf178d8 Compare September 16, 2026 10:00
Comment thread panels/dock/dockpanel.cpp Outdated
Comment thread panels/dock/dockpanel.cpp Outdated
@gugullll
gugullll force-pushed the master branch 3 times, most recently from bc5a552 to 3eafd46 Compare September 17, 2026 06:31
18202781743
18202781743 previously approved these changes Sep 17, 2026
18202781743
18202781743 previously approved these changes Sep 17, 2026
@deepin-bot

deepin-bot Bot commented Sep 22, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 2.0.55
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1752

@deepin-bot

deepin-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 2.0.56
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1753

@deepin-bot

deepin-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 2.0.57
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1758

@deepin-bot

deepin-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 2.0.58
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1765

Add a client wrapper for the treeland layer-shell-extension protocol and wire
it into the dock so the compositor owns the interactive resize (referenced
protocol PR linuxdeepin/treeland-protocols#104).

加入 layer-shell-extension 协议客户端封装,合成器接管 dock 交互缩放,
替代客户端自身拖拽逻辑。

Log: dock 支持合成器接管缩放
PMS: BUG-294673
Influence: 合成器接管 dock 缩放交互,状态机改为 compositorOwnsResize 驱动,
          拖拽期间屏蔽客户端手动计算,flow 与可执行尺寸更稳定。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 79 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 79 分,大于 70 分通过阈值。代码实现了 compositor 驱动的 dock 缩放功能,整体架构清晰,但存在 1 处资源泄漏边界问题和 1 处低危安全风险,建议修复后合并。

🔍 详细分析

1. 语法逻辑 ❌

评价: 一般 ❌ 不通过

潜在问题:

  1. panels/dock/dockpanel.cpp:665 - 资源泄漏:getLayerShellExtensionObject() 创建的协议对象在 m_dockShellExtensionObject 已存在时未被释放
  2. panels/dock/dockpanel.cpp:624 - Q_UNREACHABLE() 在 Q_INVOKABLE 方法中使用,存在未定义行为风险
  3. panels/dock/package/main.qml:748 - beginResize() 返回值未检查,合成器驱动缩放失败时无回退机制

建议: 1.将 m_dockShellExtensionObject 非空检查移至 getLayerShellExtensionObject() 调用之前,避免创建未使用的协议对象
2.将 Q_UNREACHABLE() 替换为 return false 并添加日志,增强 Q_INVOKABLE 方法的健壮性
3.在 QML 中检查 beginResize() 返回值,失败时回退到客户端拖拽逻辑


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. panels/dock/dockpanel.cpp:599 - beginResize() 函数缺少函数级注释说明
  2. panels/dock/dockpanel.cpp:29 - 使用 QtWaylandClient 私有头文件,跨 Qt 版本兼容性风险
  3. panels/dock/layershellextension.h:36 - TreeLandLayerShellExtensionObject 继承 QWaylandClientExtensionTemplate 不恰当

建议: 1.为私有 API 使用添加版本守卫和文档说明
2.考虑 TreeLandLayerShellExtensionObject 仅继承 QtWayland::treeland_layer_shell_extension_object_v1
3.为 beginResize() 添加函数级注释
4.考虑使用结构体封装尺寸约束参数


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无优化建议


4. 代码安全 🔒

评价: 良好 ✅ 通过

🔐 发现 1 个安全漏洞

安全漏洞详情:

  1. 🟢 Use-After-Free 风险 (panels/dock/layershellextension.h - TreeLandLayerShellExtensionObject::m_nativeSurface): m_nativeSurface 为原始 wl_surface 指针,无生命周期跟踪。若 wl_surface 在扩展对象存活期间被销毁(如 QWaylandWindow 重建),使用过期指针可能导致 use-after-free。虽然 nativeSurface() 访问器有注释警告,但类本身未提供任何保护机制 ——非常重要

建议: 1.为 m_nativeSurface 添加生命周期管理或销毁监听器
2.添加参数校验确保 min <= max 且值为非负数


💡 改进建议代码示例

// 修复1: 将 m_dockShellExtensionObject 检查移至 getLayerShellExtensionObject() 之前
bool DockPanel::beginResize()
{
    // ... switch position ...

    if (!m_dockShellExtensionManager) {
        qCWarning(dockLog) << "beginResize: layer shell extension manager is null";
        return false;
    }
    if (!m_dockShellExtensionManager->isActive()) {
        qCWarning(dockLog) << "beginResize: layer shell extension manager inactive";
        return false;
    }
    // 先检查是否已在缩放中,避免创建未使用的协议对象
    if (m_dockShellExtensionObject) {
        qCWarning(dockLog) << "beginResize: resize already in progress";
        return false;
    }

    // 然后再创建协议对象
    auto *dockSurface = m_dockShellExtensionManager->getLayerShellExtensionObject(surface);
    if (!dockSurface) {
        qCWarning(dockLog) << "beginResize: failed to get layer shell extension object";
        return false;
    }
    // ... continue with resize ...
}

// 修复2: 替换 Q_UNREACHABLE() 为安全返回
default:
    qCWarning(dockLog) << "beginResize: unknown position" << position();
    return false;

// 修复3: QML 中检查返回值
if (dock.compositorDrivenResize) {
    if (!Panel.beginResize()) {
        // 回退到客户端拖拽逻辑
        dock.compositorDrivenResize = false
    }
}

本报告由 AI 代码审查工具自动生成

@mhduiy

mhduiy commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

/forcemerge

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gugullll, mhduiy

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-bot

deepin-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit c602f63 into linuxdeepin:master Oct 16, 2026
7 of 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