Skip to content

fix: prevent mouse drag from blocking icon clicks#721

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
18202781743:master
Mar 6, 2026
Merged

fix: prevent mouse drag from blocking icon clicks#721
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Mar 6, 2026

Fixed an issue where dragging on application icons could block
subsequent click events. Added explicit onClicked handler to MouseArea
that only triggers root.itemClicked() when not actively dragging. This
ensures that drag operations don't interfere with normal click behavior
for launching applications.

Log: Fixed application launch failure when clicking icons after drag
operations

Influence:

  1. Test clicking application icons to ensure they launch correctly
  2. Test dragging icons and verify drag functionality still works
  3. Test quick click-drag-release scenarios to ensure no interference
  4. Verify both mouse and touch interactions work properly
  5. Test edge cases like partial drags and cancellations

fix: 修复鼠标拖动导致图标点击失效的问题

修复了在应用程序图标上拖动操作会阻止后续点击事件的问题。为MouseArea添加
了显式的onClicked处理程序,仅在非拖动状态下触发root.itemClicked()。这确
保拖动操作不会干扰正常的点击启动应用程序行为。

Log: 修复拖动操作后点击图标无法启动应用的问题

Influence:

  1. 测试点击应用程序图标,确保能正确启动应用
  2. 测试拖动图标功能,验证拖动操作仍然有效
  3. 测试快速点击-拖动-释放场景,确保没有相互干扰
  4. 验证鼠标和触摸交互都能正常工作
  5. 测试边缘情况,如部分拖动和取消操作

Summary by Sourcery

Bug Fixes:

  • Ensure icon click handlers only fire when not actively dragging to avoid blocked application launches after drag operations.

Fixed an issue where dragging on application icons could block
subsequent click events. Added explicit onClicked handler to MouseArea
that only triggers root.itemClicked() when not actively dragging. This
ensures that drag operations don't interfere with normal click behavior
for launching applications.

Log: Fixed application launch failure when clicking icons after drag
operations

Influence:
1. Test clicking application icons to ensure they launch correctly
2. Test dragging icons and verify drag functionality still works
3. Test quick click-drag-release scenarios to ensure no interference
4. Verify both mouse and touch interactions work properly
5. Test edge cases like partial drags and cancellations

fix: 修复鼠标拖动导致图标点击失效的问题

修复了在应用程序图标上拖动操作会阻止后续点击事件的问题。为MouseArea添加
了显式的onClicked处理程序,仅在非拖动状态下触发root.itemClicked()。这确
保拖动操作不会干扰正常的点击启动应用程序行为。

Log: 修复拖动操作后点击图标无法启动应用的问题

Influence:
1. 测试点击应用程序图标,确保能正确启动应用
2. 测试拖动图标功能,验证拖动操作仍然有效
3. 测试快速点击-拖动-释放场景,确保没有相互干扰
4. 验证鼠标和触摸交互都能正常工作
5. 测试边缘情况,如部分拖动和取消操作
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 6, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts click handling for icon items so that clicks are only processed when no drag is active, fixing a bug where drag operations blocked subsequent click-triggered launches, and removes the previous workaround click handler on the outer control.

Sequence diagram for icon click vs drag handling

sequenceDiagram
    actor User
    participant MouseArea
    participant DragHandler as DragHandler_drag
    participant Root as IconItemDelegate_root

    rect rgb(230,255,230)
        Note over User,Root: Simple click (no drag)
        User->>MouseArea: press
        MouseArea->>DragHandler: startInteraction
        DragHandler-->>DragHandler: drag.active = false
        User->>MouseArea: release
        MouseArea-->>MouseArea: onClicked (drag.active == false)
        MouseArea->>Root: itemClicked()
    end

    rect rgb(255,230,230)
        Note over User,Root: Drag operation
        User->>MouseArea: press
        MouseArea->>DragHandler: startInteraction
        DragHandler-->>DragHandler: drag.active = true (movement exceeds threshold)
        User->>MouseArea: move (drag)
        DragHandler-->>DragHandler: update position
        User->>MouseArea: release
        MouseArea-->>MouseArea: onClicked (drag.active == true)
        MouseArea--xRoot: itemClicked() (blocked by condition)
    end
Loading

File-Level Changes

Change Details Files
Gate icon click handling on drag state within the MouseArea to prevent drags from consuming clicks, and remove the obsolete outer onClicked workaround.
  • Add onClicked handler on the inner MouseArea that calls root.itemClicked() only when drag.active is false
  • Remove the onClicked handler from the outer Control that unconditionally called root.itemClicked()
  • Clean up the outdated FIXME comment about DragHandler blocking the Control's onClicked
qml/windowed/IconItemDelegate.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 - I've left some high level feedback:

  • By moving itemClicked() from the Control’s onClicked to the inner MouseArea, keyboard activation (e.g., Enter/Space on a focused item) may no longer trigger clicks; consider keeping a path for non-pointer activation if the delegate is intended to be keyboard-accessible.
  • Relying solely on drag.active to gate itemClicked() may treat very small drags as non-clicks or vice versa depending on how DragHandler behaves; consider enforcing a small movement threshold or using the handler’s drag distance to more precisely distinguish drags from clicks.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- By moving `itemClicked()` from the `Control`’s `onClicked` to the inner `MouseArea`, keyboard activation (e.g., Enter/Space on a focused item) may no longer trigger clicks; consider keeping a path for non-pointer activation if the delegate is intended to be keyboard-accessible.
- Relying solely on `drag.active` to gate `itemClicked()` may treat very small drags as non-clicks or vice versa depending on how `DragHandler` behaves; consider enforcing a small movement threshold or using the handler’s drag distance to more precisely distinguish drags from clicks.

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

deepin pr auto review

这段代码对 IconItemDelegate.qml 进行了重构,主要目的是解决 DragHandler 启用时导致点击事件无法触发的问题。

以下是对这段 Diff 的审查意见,分为语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑

  • 逻辑修正正确
    • 问题背景:原代码中,onClicked 事件处理位于 DragHandler 的父级(推测是一个 MouseArea 或类似的输入处理组件)。根据代码注释 FIXME,当 DragHandler 启用并处于活动状态时,它会“窃取”或屏蔽掉父组件的点击事件,导致 root.itemClicked() 无法被调用。
    • 修改方案:新代码将 onClicked 逻辑移到了 TapHandler 内部。
    • 逻辑分析TapHandler 是 Qt Quick 中用于处理点击/轻触的高级手势处理器。它与 DragHandler 是平级关系。当 drag.active 为 false(即没有发生拖拽)时,TapHandler 能够正常捕获点击事件。这修复了之前的逻辑漏洞,使得点击和拖拽能够共存且互不干扰。
  • 条件判断if (!drag.active) 是必要的。如果不加这个判断,用户在拖拽结束释放鼠标时,可能会意外触发点击事件(取决于具体的交互逻辑),导致拖拽操作被误判为点击操作。

2. 代码质量

  • 消除了技术债务:原代码中的 FIXME 注释表明这是一个已知但未修复的问题。新代码移除了这个注释,并提供了更合理的实现方案,提高了代码的可维护性。
  • 组件职责分离:将点击事件的处理从可能包含拖拽逻辑的父组件移至专门负责点击的 TapHandler 中,使得组件的职责更加清晰。
  • 可读性:代码逻辑非常直观,符合 QML 的惯用写法。

3. 代码性能

  • 性能影响极小:将 onClicked 从父组件移至 TapHandler 内部,并不会引入显著的性能开销。TapHandler 本身就是 Qt Quick 推荐的处理点击的方式,其内部实现经过了优化。
  • 避免冗余调用:通过 !drag.active 判断,避免了在拖拽操作结束后冗余地触发点击逻辑,这在逻辑上也保证了性能的合理性。

4. 代码安全

  • 无安全风险:这段代码主要涉及 UI 交互逻辑,不涉及内存管理、权限控制或数据验证,因此不存在典型的安全漏洞(如缓冲区溢出、SQL注入等)。
  • 状态一致性:通过 drag.active 检查,确保了只有在非拖拽状态下才触发点击回调,保证了 UI 状态的一致性,防止了状态混乱(例如同时触发拖拽和点击可能导致的副作用)。

改进建议

虽然这段代码已经解决了核心问题,但可以考虑以下微小的优化建议,取决于具体的项目上下文:

  1. 变量作用域:确保 drag 对象在 TapHandler 的作用域内是可访问的。从 Diff 看,drag 应该是同级的 DragHandler 的 id。如果 drag 的 id 定义在外部,请确保引用正确(例如使用 root.drag.active 或具体路径)。
  2. 手势阈值:如果系统对“点击”和“拖拽”的区分非常严格,可以考虑调整 TapHandlerlongPressThreshold 或相关属性,但这通常不是必须的,除非有特殊的 UX 需求。

总结:这是一次高质量的代码修复。它正确地利用了 Qt Quick 的手势处理机制(TapHandler)解决了 DragHandler 带来的事件冲突问题,逻辑清晰,消除了技术债务,且没有引入副作用或性能问题。建议采纳。

@deepin-ci-robot
Copy link

[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

@18202781743
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 6, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 094fd43 into linuxdeepin:master Mar 6, 2026
8 of 9 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