Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Nov 24, 2025

DQuickDrag 目前不支持 wayland 会话,直接使用会导致一些问题.暂时在
wayland 会话下规避使用.

Summary by Sourcery

Fix dock tray drag behavior under non-X11 sessions and adjust dock position notification to accept explicit dimensions.

Bug Fixes:

  • Disable DQuickDrag activation when running under non-X11 (Wayland) platforms to avoid drag-related issues.
  • Capture and reuse tray item visuals as drag images on non-X11 platforms to maintain drag feedback.
  • Provide explicit width/height parameters when notifying dock position changes to ensure correct layout updates in different orientations.

DQuickDrag 目前不支持 wayland 会话,直接使用会导致一些问题.暂时在
wayland 会话下规避使用.

PMS: BUG-339309
Log:
@BLumia BLumia requested a review from yixinshark November 24, 2025 09:40
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行审查分析:

  1. 语法逻辑分析:
    代码在语法上是正确的,符合 QML 的语法规范。主要修改了两个部分:
  • dock 位置变化通知函数增加了参数
  • 托盘拖拽功能的平台判断优化
  1. 代码质量改进建议:

第一处修改(dock/package/main.qml):

function onWidthChanged() {
    if (dock.useColumnLayout) {
        Panel.notifyDockPositionChanged(dock.width, 0)
    }
}

function onHeightChanged() {
    if (!dock.useColumnLayout) {
        Panel.notifyDockPositionChanged(0, dock.height)
    }
}

建议改进:

  • 可以考虑合并这两个函数为一个更通用的函数,减少代码重复
  • 添加参数验证,确保传入的宽高值有效

第二处修改(ActionLegacyTrayPluginDelegate.qml):

DQuickDrag.active: Drag.active && Qt.platform.pluginName === "xcb"

这个修改很好,增加了平台判断,避免了在非 X11 平台上的潜在问题。

if (Qt.platform.pluginName !== "xcb") {
    root.grabToImage(function(result) {
        root.Drag.imageSource = result.url;
    })
}

建议改进:

  • grabToImage 是异步操作,应该添加错误处理
  • 考虑添加加载状态提示
  • 可以缓存生成的图片,避免重复生成
  1. 性能优化建议:
  • grabToImage 操作可能会频繁触发(在 onWidthChanged 中),建议:
    • 添加防抖动(debounce)机制
    • 考虑限制图片更新的频率
    • 可以添加一个标志位,避免在拖拽过程中重复生成图片
  1. 安全性建议:
  • grabToImage 生成的图片 URL 应该进行适当的清理和验证
  • 考虑添加内存管理,确保及时释放生成的图片资源
  • 对于平台判断(Qt.platform.pluginName),建议使用常量定义,避免硬编码
  1. 其他建议:
  • 添加适当的注释说明平台差异的原因
  • 考虑将平台相关的逻辑抽取为单独的函数或组件
  • 建议添加单元测试来验证不同平台下的行为

这些修改总体上是合理的,主要解决了跨平台的兼容性问题,但在性能和错误处理方面还有改进空间。

@BLumia BLumia requested a review from wjyrich November 24, 2025 09:40
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 24, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR gates DQuickDrag usage to X11 (xcb) sessions and provides fallback drag imagery for Wayland, while also updating dock position notifications to include explicit dimensions depending on orientation.

File-Level Changes

Change Details Files
Restrict DQuickDrag usage to X11 and add Wayland-safe drag image handling for legacy tray items.
  • Gate DQuickDrag.active behind a Qt.platform.pluginName === "xcb" check to avoid using DQuickDrag on Wayland sessions.
  • On non-xcb platforms, capture the root item to an image and assign it to Drag.imageSource when drag state changes so drag visuals still work without DQuickDrag.
  • Ensure Drag.imageSource is refreshed on width changes for non-xcb platforms to keep the drag image in sync with the item size.
panels/dock/tray/package/ActionLegacyTrayPluginDelegate.qml
Pass explicit width/height to dock position change notifications based on orientation.
  • When the dock uses a column layout, call Panel.notifyDockPositionChanged with the dock width and 0 height to indicate horizontal sizing.
  • When the dock does not use a column layout, call Panel.notifyDockPositionChanged with 0 width and the dock height to indicate vertical sizing.
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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The grabToImage logic for non-xcb platforms is duplicated in multiple places; consider extracting it into a small helper function (e.g., updateDragImageIfNeeded()) to keep behavior consistent and easier to maintain.
  • Calling grabToImage on every onWidthChanged for non-xcb platforms may be expensive during continuous resize; consider guarding it with additional conditions (e.g., only when dragging or visible) or throttling to reduce potential performance impact.
  • The platform check Qt.platform.pluginName === "xcb" is used in several places; consider centralizing this into a reusable property or helper (e.g., isXcbPlatform) to avoid scattering string literals and to simplify future platform handling changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `grabToImage` logic for non-`xcb` platforms is duplicated in multiple places; consider extracting it into a small helper function (e.g., `updateDragImageIfNeeded()`) to keep behavior consistent and easier to maintain.
- Calling `grabToImage` on every `onWidthChanged` for non-`xcb` platforms may be expensive during continuous resize; consider guarding it with additional conditions (e.g., only when dragging or visible) or throttling to reduce potential performance impact.
- The platform check `Qt.platform.pluginName === "xcb"` is used in several places; consider centralizing this into a reusable property or helper (e.g., `isXcbPlatform`) to avoid scattering string literals and to simplify future platform handling changes.

## Individual Comments

### Comment 1
<location> `panels/dock/tray/package/ActionLegacyTrayPluginDelegate.qml:175-179` </location>
<code_context>
         }

+        if (Qt.platform.pluginName !== "xcb") {
+            root.grabToImage(function(result) {
+                root.Drag.imageSource = result.url;
+            })
+        }
</code_context>

<issue_to_address>
**suggestion:** Consider guarding against grabToImage failures before using result.url.

grabToImage can fail or return an empty/invalid result. Using result.url unconditionally risks subtle issues (e.g., broken or stale drag thumbnail, platform-specific quirks). Please validate result and result.url (or result.image) before assigning to root.Drag.imageSource, and consider keeping the previous image or using a fallback when the grab fails.

```suggestion
        if (Qt.platform.pluginName !== "xcb") {
            root.grabToImage(function(result) {
                // Guard against grabToImage failures or empty results before updating the drag image.
                var hasValidImage = result && result.image && result.image.width > 0 && result.image.height > 0
                var hasValidUrl = result && result.url && result.url !== ""

                if (hasValidImage) {
                    root.Drag.imageSource = result.image
                } else if (hasValidUrl) {
                    root.Drag.imageSource = result.url
                }
                // If neither image nor URL is valid, keep the existing imageSource as a fallback.
            })
        }
```
</issue_to_address>

### Comment 2
<location> `panels/dock/tray/package/ActionLegacyTrayPluginDelegate.qml:190-196` </location>
<code_context>
         Panel.contextDragging = true
     }

+    onWidthChanged: {
+        if (Qt.platform.pluginName !== "xcb") {
+            root.grabToImage(function(result) {
+                root.Drag.imageSource = result.url;
+            })
</code_context>

<issue_to_address>
**suggestion (performance):** Re-evaluate triggering grabToImage on every width change for non-xcb platforms.

This handler will invoke `grabToImage` on every width change for non-xcb platforms, which can be expensive (e.g., during animations, layout changes, or DPI/scale updates) and may cause jank if multiple items update. Consider only doing this while a drag is active, or debounce/coalesce width changes to avoid repeated grabs during rapid size updates.

```suggestion
    onWidthChanged: {
        // Avoid expensive grabToImage calls on every width change:
        // only update the drag image while a drag is actually active.
        if (Qt.platform.pluginName !== "xcb" && Drag.active) {
            root.grabToImage(function(result) {
                root.Drag.imageSource = result.url;
            })
        }
    }
```
</issue_to_address>

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.

Comment on lines +190 to +196
onWidthChanged: {
if (Qt.platform.pluginName !== "xcb") {
root.grabToImage(function(result) {
root.Drag.imageSource = result.url;
})
}
}
Copy link

Choose a reason for hiding this comment

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

suggestion (performance): Re-evaluate triggering grabToImage on every width change for non-xcb platforms.

This handler will invoke grabToImage on every width change for non-xcb platforms, which can be expensive (e.g., during animations, layout changes, or DPI/scale updates) and may cause jank if multiple items update. Consider only doing this while a drag is active, or debounce/coalesce width changes to avoid repeated grabs during rapid size updates.

Suggested change
onWidthChanged: {
if (Qt.platform.pluginName !== "xcb") {
root.grabToImage(function(result) {
root.Drag.imageSource = result.url;
})
}
}
onWidthChanged: {
// Avoid expensive grabToImage calls on every width change:
// only update the drag image while a drag is actually active.
if (Qt.platform.pluginName !== "xcb" && Drag.active) {
root.grabToImage(function(result) {
root.Drag.imageSource = result.url;
})
}
}

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, wjyrich

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

@BLumia BLumia merged commit a662e47 into linuxdeepin:master Nov 25, 2025
8 of 11 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.

3 participants