Skip to content

fix: migrate treeland output protocol v1 to v2 - #1729

Open
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:agent/bot/9cda2caa2af3
Open

deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:agent/bot/9cda2caa2af3

Conversation

@deepin-wm

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

Copy link
Copy Markdown

Treeland output 协议 v2 适配

将 dde-shell 中两处 treeland output v1 协议消费者迁移到 v2(纯协议消费者迁移,无逻辑变更)。

改动文件(6 个)

文件 改动
shell/CMakeLists.txt find_package(TreelandProtocols 0.6 REQUIRED);XML 引用 → treeland-output-manager-unstable-v2.xml
shell/treelandoutputwatcher.h include → qwayland-treeland-output-manager-unstable-v2.h;基类 → treeland_output_manager_v2;override 签名 QString → struct ::wl_output*;新增 struct wl_output; 前置声明
shell/treelandoutputwatcher.cpp include → …-unstable-v2-client-protocol.h;接口版本 → treeland_output_manager_v2_interface.version;primary_output 改为 null 早返回 + 遍历 qApp->screens() 通过 QNativeInterface::QWaylandScreen::output() 反查 QScreen
panels/notification/osd/brightness/CMakeLists.txt 同上版本约束 + XML 引用(保留 NO_INCLUDE_CORE_ONLY)
panels/notification/osd/brightness/treelandbrightness.h 全部符号 color_control_v1 → picture_control_v2;treeland_output_manager_v1 → v2;本地类名 TreelandColorControl 保留不变
panels/notification/osd/brightness/treelandbrightness.cpp 全部符号更名;get_color_control → get_picture_control;接口版本更新

关键说明

  • 构建依赖:treeland-protocols ≥ 0.6(v2 XML 由 master 提供,尚未发 tag)
  • 无 #include <QNativeInterface>:Qt6 不为该命名空间生成转发头文件,QWaylandScreen 通过 <QScreen> 传递性引入
  • null 处理:v2 primary_output 事件 allow-null="true",实现中 null 早返回
  • 顺带修复:v1 代码 qApp->primaryScreen()->name() 在 primaryScreen() 返回 null 时会崩溃;v2 版本增加了 null 防护

Ref: DDE-232
Multica Issue: DDE-541

Summary by Sourcery

Migrate Treeland output consumers to protocol v2 with UUID-based output identification and robust screen lifecycle handling.

Bug Fixes:

  • Prevent primary-screen handling from failing when no primary screen is available and handle failed or invalid output mappings without crashing.

Enhancements:

  • Migrate output watching and brightness reporting to the Treeland output manager v2 protocol, using output UUIDs to map Wayland outputs to Qt screens.
  • Add shared output UUID protocol support for resolving compositor output identifiers and tracking screen additions and removals.

Build:

  • Require TreelandProtocols 0.9 and generate client bindings for the output manager v2 and output UUID protocols.

@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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 Sep 9, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Updates both Treeland output consumers from v1 to the v2 output manager, introducing asynchronous UUID-based QScreen mapping for primary-output selection and brightness control, with lifecycle/error handling for null, failed, and stale protocol objects. Build configuration now requires TreelandProtocols 0.9 and generates the v2 output-manager plus output-UUID clients.

Sequence diagram for UUID-based primary output selection

sequenceDiagram
    participant Compositor
    participant Watcher as TreelandOutputWatcher
    participant UUIDManager as TreelandOutputUuidManager
    participant Screen as QScreen
    participant Qt as QtScreenSystem

    Compositor->>Watcher: treeland_output_manager_v2_primary_output(uuid)
    Watcher->>Watcher: applyPrimary(uuid)
    alt UUID mapping available
        Watcher->>Qt: handlePrimaryScreenChanged(screen.handle())
    else UUID not mapped yet
        Watcher->>Watcher: requestUuid(screen)
        Watcher->>UUIDManager: get_uuid(wl_output)
        UUIDManager-->>Watcher: uuidReceived(uuid)
        Watcher->>Watcher: applyPrimary(uuid)
    end
    alt compositor reports failure
        Compositor->>Watcher: treeland_output_manager_v2_primary_output_failed(reason)
        Watcher->>Watcher: clear pending UUID
    end
Loading

Sequence diagram for UUID-based brightness control

sequenceDiagram
    participant Brightness as TreelandBrightness
    participant UUIDManager as TreelandOutputUuidManager
    participant UUIDRequest as TreelandOutputUuid
    participant OutputManager as OutputManagerV2
    participant Control as TreelandPictureControl
    participant Compositor

    Brightness->>UUIDManager: get_uuid(wl_output)
    UUIDManager-->>UUIDRequest: uuidReceived(uuid)
    UUIDRequest-->>Brightness: uuidReceived(uuid)
    Brightness->>OutputManager: get_picture_control(uuid)
    OutputManager-->>Control: picture control object
    Compositor-->>Control: treeland_output_picture_control_v2_brightness(brightness)
    Control-->>Brightness: brightnessChanged(brightness)
    Compositor-->>Control: treeland_output_picture_control_v2_result(result)
    alt invalid output result
        Brightness->>Brightness: delete m_control
    end
Loading

File-Level Changes

Change Details Files
Migrates shell output selection from the v1 name-based protocol to v2 UUID-based output mapping.
  • Adds shared UUID manager/request wrappers and generates the output UUID protocol client.
  • Resolves each QScreen to a Wayland output UUID, tracks screen lifecycle, and applies pending primary-output events after asynchronous mapping.
  • Handles null UUIDs, failed primary-output requests, missing screens, and removed screens without crashing or retaining stale mappings.
shell/CMakeLists.txt
shell/treelandoutputuuid.h
shell/treelandoutputuuid.cpp
shell/treelandoutputwatcher.h
shell/treelandoutputwatcher.cpp
Migrates brightness monitoring to v2 picture-control objects identified through output UUIDs.
  • Replaces color-control v1 bindings and get_color_control with picture-control v2 bindings and get_picture_control.
  • Resolves the primary QScreen to a UUID before creating the control and refreshes on protocol, UUID-manager, and primary-screen state changes.
  • Processes v2 result events, invalidates stale controls on invalid-output responses, and guards inactive or null output states.
panels/notification/osd/brightness/CMakeLists.txt
panels/notification/osd/brightness/treelandbrightness.h
panels/notification/osd/brightness/treelandbrightness.cpp
Updates build-time protocol generation and dependency requirements for the new protocol clients.
  • Requires TreelandProtocols 0.9.
  • Generates clients for the unstable v2 output manager and unstable v1 output UUID XML protocols.
  • Shares the UUID implementation with the brightness target while preserving its private include setup.
shell/CMakeLists.txt
panels/notification/osd/brightness/CMakeLists.txt

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

@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

@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

@deepin-bot

deepin-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 2.0.59
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1766

@deepin-bot

deepin-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 2.0.60
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1773

@deepin-bot

deepin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 2.0.61
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1786

@deepin-wm
deepin-wm force-pushed the agent/bot/9cda2caa2af3 branch 2 times, most recently from 4009139 to 6c5c101 Compare November 3, 2026 06:08
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@deepin-wm
deepin-wm force-pushed the agent/bot/9cda2caa2af3 branch 4 times, most recently from 5fdbc6e to 86f4a5f Compare November 3, 2026 08:05
1. 更新 CMakeLists 的 find_package 要求 TreelandProtocols 0.9
2. 迁移 treelandoutputwatcher 至 treeland_output_manager_v2
3. 迁移 treelandbrightness 从 color_control_v1 到 picture_control_v2
4. primary_output 事件回调从 wl_output* 改为 const QString &uuid
5. get_picture_control 请求从 wl_output* 改为 const QString &uuid
6. 新增 TreelandOutputUuidManager 和 TreelandOutputUuid 建立 wl_output→uuid 映射
7. 主屏匹配方式从指针比较改为 UUID 映射表查找
8. 补充 result 事件处理,含 commit_result 枚举(invalid_output=3)
9. 补充 primary_output_failed 事件处理
10. 缓存 pending primary uuid 处理时序问题
11. 处理屏幕移除并修复 TreelandOutputUuid 生命周期
12. 修复重复的 SPDX-FileCopyrightText 行
13. 更新 debian/control 构建依赖为 treeland-protocols (>= 0.9.0)
14. 提取 TreelandOutputUuidManager/TreelandOutputUuid 到共享头文件 shell/treelandoutputuuid.h,消除 shell 与 osd/brightness 模块间的重复定义

Log: 迁移 treeland output 协议消费者从 v1 到 v2 并适配 UUID 标识,提取共享 UUID 类消除重复代码
Influence: 多屏环境下主屏切换、OSD 亮度显示、屏幕热插拔
Ref: DDE-541
@deepin-wm
deepin-wm force-pushed the agent/bot/9cda2caa2af3 branch from 86f4a5f to 6422835 Compare November 3, 2026 08:16
@wineee
wineee marked this pull request as ready for review November 3, 2026 08:52

@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/notification/osd/brightness/treelandbrightness.cpp" line_range="90-91" />
<code_context>
+    m_currentUuid.clear();

-    if (!output) {
+    if (!screen) {
         return;
     }

</code_context>
<issue_to_address>
**Brightness stays bound to old output**

When the primary screen changes or disappears while a UUID request is outstanding and the new screen has no usable Wayland output, `refresh()` and `requestPrimaryUuid()` return without cancelling the old request, so its callback passes the sender check and installs a picture control for the previous output; the OSD then reports stale brightness.

Cancel or invalidate the outstanding UUID request before returning when the primary screen has no usable Wayland output.

Also at `panels/notification/osd/brightness/treelandbrightness.cpp:102-118`, `panels/notification/osd/brightness/treelandbrightness.cpp:120-122`.
</issue_to_address>

### Comment 2
<location path="panels/notification/osd/brightness/treelandbrightness.cpp" line_range="124-125" />
<code_context>
+        if (sender() != m_uuidRequest)
+            return;
+
+        if (uuid.isEmpty())
+            return;
+
+        m_currentUuid = uuid;
</code_context>
<issue_to_address>
**Brightness monitoring stops after lookup failures**

When the UUID is empty, `get_picture_control()` returns null, or the picture control reports `commit_result_invalid_output`, `TreelandBrightness` returns or clears its control without retrying UUID/control resolution or notifying brightness consumers, so `brightness()` returns zero or the OSD retains stale brightness until an unrelated refresh.

Retry UUID/control resolution and notify brightness consumers on each failed resolution path.

Also at `panels/notification/osd/brightness/treelandbrightness.cpp:132-133`, `panels/notification/osd/brightness/treelandbrightness.cpp:139-144`.
</issue_to_address>

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

Comment on lines +90 to 91
if (!screen) {
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Brightness stays bound to old output

When the primary screen changes or disappears while a UUID request is outstanding and the new screen has no usable Wayland output, refresh() and requestPrimaryUuid() return without cancelling the old request, so its callback passes the sender check and installs a picture control for the previous output; the OSD then reports stale brightness.

Cancel or invalidate the outstanding UUID request before returning when the primary screen has no usable Wayland output.

Also at panels/notification/osd/brightness/treelandbrightness.cpp:102-118, panels/notification/osd/brightness/treelandbrightness.cpp:120-122.

Prompt for AI agents
In `panels/notification/osd/brightness/treelandbrightness.cpp` at lines 90-91:

**Brightness stays bound to old output**

When the primary screen changes or disappears while a UUID request is outstanding and the new screen has no usable Wayland output, `refresh()` and `requestPrimaryUuid()` return without cancelling the old request, so its callback passes the sender check and installs a picture control for the previous output; the OSD then reports stale brightness.

Cancel or invalidate the outstanding UUID request before returning when the primary screen has no usable Wayland output.

Also at `panels/notification/osd/brightness/treelandbrightness.cpp:102-118`, `panels/notification/osd/brightness/treelandbrightness.cpp:120-122`.

Comment on lines +124 to +125
if (uuid.isEmpty())
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Brightness monitoring stops after lookup failures

When the UUID is empty, get_picture_control() returns null, or the picture control reports commit_result_invalid_output, TreelandBrightness returns or clears its control without retrying UUID/control resolution or notifying brightness consumers, so brightness() returns zero or the OSD retains stale brightness until an unrelated refresh.

Retry UUID/control resolution and notify brightness consumers on each failed resolution path.

Also at panels/notification/osd/brightness/treelandbrightness.cpp:132-133, panels/notification/osd/brightness/treelandbrightness.cpp:139-144.

Prompt for AI agents
In `panels/notification/osd/brightness/treelandbrightness.cpp` at lines 124-125:

**Brightness monitoring stops after lookup failures**

When the UUID is empty, `get_picture_control()` returns null, or the picture control reports `commit_result_invalid_output`, `TreelandBrightness` returns or clears its control without retrying UUID/control resolution or notifying brightness consumers, so `brightness()` returns zero or the OSD retains stale brightness until an unrelated refresh.

Retry UUID/control resolution and notify brightness consumers on each failed resolution path.

Also at `panels/notification/osd/brightness/treelandbrightness.cpp:132-133`, `panels/notification/osd/brightness/treelandbrightness.cpp:139-144`.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交将 treeland output 协议从 v1 迁移至 v2,引入基于 UUID 的输出标识机制替代直接 wl_output 引用。 整体实现逻辑清晰,内存管理规范(全面使用 QPointer 防止悬垂指针),无安全漏洞。 仅存在少量代码质量方面的轻微改进空间(变量遮蔽、新类缺少文档注释、删除方式不一致),不影响功能正确性。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: ['requestPrimaryUuid() 中 lambda 内部变量 raw(第187行)与外部作用域 raw(第169行)同名构成变量遮蔽,建议将内部变量重命名为 picRaw 以提高可读性。']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: ['为 TreelandOutputUuidManager 和 TreelandOutputUuid 添加简短的类级别注释说明其用途', '将 requestPrimaryUuid() lambda 内的 raw 重命名为 picRaw 或 controlRaw 以消除变量遮蔽', '统一对象删除方式,建议 onScreenRemoved() 中也使用 deleteLater()']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

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

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 建议:消除变量遮蔽并统一删除方式
void TreelandBrightness::requestPrimaryUuid()
{
    // ... 前置检查不变 ...
    auto *raw = m_uuidManager->get_uuid(output);
    if (!raw)
        return;

    m_uuidRequest = new ::TreelandOutputUuid(raw, this);

    connect(m_uuidRequest, &::TreelandOutputUuid::uuidReceived, this, [this](const QString &uuid) {
        if (sender() != m_uuidRequest)
            return;

        if (uuid.isEmpty())
            return;

        m_currentUuid = uuid;

        delete m_uuidRequest;
        m_uuidRequest = nullptr;

        // 重命名 raw -> picRaw,消除与外部 raw 的变量遮蔽
        auto *picRaw = get_picture_control(uuid);
        if (!picRaw)
            return;

        m_control = new TreelandPictureControl(picRaw, this);
        connect(m_control, &TreelandPictureControl::brightnessChanged,
                this, &TreelandBrightness::brightnessChanged);
        connect(m_control, &TreelandPictureControl::resultReceived, this, [this](uint32_t result) {
            if (result == TreelandPictureControl::commit_result_invalid_output) {
                delete m_control;
                m_control = nullptr;
                m_currentUuid.clear();
            }
        });
    });
}

// 建议:onScreenRemoved 中统一使用 deleteLater()
void TreelandOutputWatcher::onScreenRemoved(QScreen *screen)
{
    for (auto it = m_uuidToScreen.begin(); it != m_uuidToScreen.end();) {
        if (it.value() == screen)
            it = m_uuidToScreen.erase(it);
        else
            ++it;
    }
    if (auto obj = m_uuidRequests.take(screen))
        obj->deleteLater();  // 统一使用 deleteLater()
}

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

Comment thread shell/CMakeLists.txt
shell.cpp
treelandoutputwatcher.h
treelandoutputwatcher.cpp
treelandoutputuuid.h

@18202781743 18202781743 Nov 3, 2026 •

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.

先放osd插件或者搞个库吧,不放在shell里,

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