Skip to content

fix: delay drag activation to fix first drag icon not showing in treeland#1670

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
Jul 23, 2026
Merged

fix: delay drag activation to fix first drag icon not showing in treeland#1670
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743

@18202781743 18202781743 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The issue was that on treeland, the first drag attempt did not display
the icon because Drag.active was set to true immediately without
waiting for the drag image to be fully captured. By moving Drag.active = true into a Qt.callLater() callback after the image grab
completes, we ensure the drag image is ready before activating the drag.
Additionally, setting Drag.active = false when drag is not active
prevents premature drag activation.

Log: Fixed first drag icon not showing issue on treeland

Influence:

  1. Test drag behavior on treeland to verify icon appears on first drag
  2. Test drag behavior on other platforms (X11, Wayland) to ensure no
    regression
  3. Verify that drag activation timing is correct under various
    conditions

fix: 修复 treeland 下首次拖拽图标不显示的问题

问题在于 treeland 环境下,首次拖拽时未等待拖拽图像完全捕获就
立即设置了 Drag.active = true。通过在图像抓取完成后的回调中使用
Qt.callLater() 延迟设置 Drag.active = true,确保拖拽图像就绪后再激活
拖拽。同时,在非拖拽状态下设置 Drag.active = false,避免提前激活拖拽。

Log: 修复 treeland 下首次拖拽图标不显示的问题

Influence:

  1. 在 treeland 上测试拖拽功能,验证首次拖拽显示图标
  2. 在其他平台(X11、Wayland)上测试拖拽,确保无回归
  3. 验证各种条件下拖拽激活时机的正确性

Summary by Sourcery

Bug Fixes:

  • Fix missing drag icon on the first drag attempt in treeland by aligning Drag.active timing with image capture completion.

@sourcery-ai

sourcery-ai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Delays activation of the drag state until after the drag image is captured, and explicitly deactivates drag when no active drag is in progress to fix the first-drag icon issue on treeland without regressing other platforms.

Sequence diagram for delayed drag activation after image capture

sequenceDiagram
    actor User
    participant DragItem
    participant Qt
    participant Drag

    User->>DragItem: startDrag
    DragItem->>DragItem: [grab image]
    DragItem->>Qt: Qt.callLater(callback)
    Qt->>Drag: Drag.active = true

    alt drag not active
        DragItem->>Drag: Drag.active = false
    end
Loading

File-Level Changes

Change Details Files
Adjust drag activation timing so Drag.active is set true only after the drag image grab completes and is set false when there is no active drag.
  • Move Drag.active = true into a Qt.callLater() callback that runs after the image grab succeeds, ensuring the drag image URL is assigned before activation.
  • Add an else branch for the drag activation condition that explicitly sets Drag.active = false when the drag is not active.
  • Remove the previous unconditional assignment of Drag.active = active to avoid premature activation tied directly to the active property.
panels/dock/tray/quickpanel/DragItem.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 left some high level feedback:

  • Consider handling the case where the drag is cancelled or active becomes false while the image grab is still in progress, so that the Qt.callLater callback does not mistakenly set Drag.active = true after the fact.
  • The previous code set Drag.active = active, whereas the new logic always sets it to true after a successful grab; double-check whether you still need to respect the active flag in some scenarios (e.g., reuse of this function for non-drag cases).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider handling the case where the drag is cancelled or `active` becomes false while the image grab is still in progress, so that the `Qt.callLater` callback does not mistakenly set `Drag.active = true` after the fact.
- The previous code set `Drag.active = active`, whereas the new logic always sets it to `true` after a successful grab; double-check whether you still need to respect the `active` flag in some scenarios (e.g., reuse of this function for non-drag cases).

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-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

The issue occurred because under the treeland environment, the drag
icon was not displayed during the first drag attempt. This was due
to incorrectly setting `Drag.active` before the image grab operation
completed. The fix moves the drag activation logic to occur only after
the image is successfully grabbed via the callback, and explicitly
deactivates drag when the grab fails or is not ready.

Log: Fixed first drag icon not showing under treeland

Influence:
1. Test dragging quick panel items in treeland and verify icon appears
on first drag
2. Verify drag behavior remains correct in other desktop environments
(e.g., X11)
3. Test drag with various item types and positions
4. Verify no regressions in drag cancellation or re-drag scenarios

fix: 修复treeland下首次拖拽不显示图标问题

在treeland环境下,首次拖拽时拖拽图标未能显示。原因是在图像截取操作完成前
就错误地设置了 `Drag.active` 状态。修复方案是仅在图像截取成功后的回调函
数中激活拖拽,并在截取失败或未就绪时显式取消拖拽。

Log: 修复treeland下首次拖拽图标不显示的问题

Influence:
1. 在treeland环境下测试拖拽快速面板项目,验证首次拖拽时图标正常显示
2. 验证其他桌面环境(如X11)下拖拽行为仍然正确
3. 测试不同项目类型和位置的拖拽功能
4. 验证拖拽取消或重新拖拽场景无回归问题

PMS: BUG-339333
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码通过将拖拽激活逻辑移入异步回调并使用Qt.callLater延迟执行,有效修复了拖拽图像缺失的竞态问题
逻辑正确且无性能与安全风险,代码质量良好,故给予满分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

DragItem.qmlonActiveChanged 逻辑中,原代码在 grabToImage 异步回调外部直接执行 dragItem.Drag.active = active,导致图像未生成时即激活拖拽。修复后将其移入回调函数内部,并使用 Qt.callLater 确保 QML 属性绑定更新后再激活拖拽,同时补充了 else 分支显式关闭拖拽状态,逻辑严谨。
潜在问题:无
建议:无

  • 2.代码质量(良好)✓

修复代码结构清晰,正确处理了异步操作的时序问题,else 分支的加入保证了状态的一致性,符合规范。
潜在问题:无
建议:无

  • 3.代码性能(无性能问题)✓

grabToImage 为异步操作,不阻塞主线程。Qt.callLater 将操作推迟到事件循环空闲时执行,避免不必要的重绘或布局抖动,性能表现良好。
潜在问题:无
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码修改仅涉及 QML 拖拽状态和异步图像生成的时序控制,不存在外部输入处理、命令执行或内存越界等安全风险。

  • 建议:无

■ 【改进建议代码示例】

// 当前代码已为最佳实践,无需进一步修改

@18202781743

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 7e0796d into linuxdeepin:master Jul 23, 2026
10 of 13 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