Skip to content

fix(launcher): fix search result items not responding to mouse clicks…#727

Merged
robertkill merged 1 commit intolinuxdeepin:masterfrom
robertkill:master
Mar 10, 2026
Merged

fix(launcher): fix search result items not responding to mouse clicks…#727
robertkill merged 1 commit intolinuxdeepin:masterfrom
robertkill:master

Conversation

@robertkill
Copy link
Contributor

@robertkill robertkill commented Mar 10, 2026

… in windowed mode

The MouseArea was bound to enabled: root.dndEnabled, which defaults to false in SearchResultView delegates. This caused the MouseArea to be completely disabled, preventing onClicked from firing. Meanwhile, the Button consumed mouse events, blocking the outer TapHandler from receiving them — resulting in all three click mechanisms failing.

Changed MouseArea to always be enabled and conditionally set drag.target instead, so click handling works regardless of dndEnabled while drag behavior remains controlled.

Log: Fix search result items not responding to mouse clicks in windowed mode

Influence:

  1. Open the launcher in windowed mode
  2. Type a keyword in the search box to trigger the search result list
  3. Click on an app icon in the search results and verify it launches correctly
  4. Right-click on an app icon in the search results and verify the context menu appears
  5. Verify click and drag operations still work correctly in the frequently used and recently installed views

fix: 修复小窗口模式搜索列表中应用无法鼠标点击的问题

MouseArea 的 enabled 绑定到了 root.dndEnabled,而搜索结果的 delegate 未设置该属性,默认值为 false,导致 MouseArea 被完全禁用,onClicked
无法触发。同时 Button 消费了鼠标事件,阻止了外层 TapHandler 接收
事件,导致三层点击机制全部失效。

将 MouseArea 改为始终启用,仅通过 drag.target 条件控制拖拽行为,
使点击处理不再依赖 dndEnabled 的值。

Log: 修复小窗口模式搜索列表中应用无法鼠标点击的问题

Influence:

  1. 打开小窗口模式的启动器
  2. 在搜索框中输入关键字,触发搜索结果列表
  3. 点击搜索结果中的应用图标,验证应用能正常启动
  4. 右键点击搜索结果中的应用图标,验证右键菜单正常弹出
  5. 验证常用应用和最近安装区域的点击和拖拽操作仍然正常

PMS: BUG-352527

Summary by Sourcery

Ensure launcher icon delegates in windowed mode respond correctly to mouse clicks while preserving drag-and-drop behavior.

Bug Fixes:

  • Fix search result items in windowed launcher mode not responding to mouse clicks due to a disabled MouseArea.

Enhancements:

  • Decouple click handling from drag-and-drop enablement by always enabling the MouseArea and conditioning only the drag target.

… in windowed mode

The MouseArea was bound to `enabled: root.dndEnabled`, which defaults
to false in SearchResultView delegates. This caused the MouseArea to
be completely disabled, preventing onClicked from firing. Meanwhile,
the Button consumed mouse events, blocking the outer TapHandler from
receiving them — resulting in all three click mechanisms failing.

Changed MouseArea to always be enabled and conditionally set
drag.target instead, so click handling works regardless of dndEnabled
while drag behavior remains controlled.

Log: Fix search result items not responding to mouse clicks in windowed mode

Influence:
1. Open the launcher in windowed mode
2. Type a keyword in the search box to trigger the search result list
3. Click on an app icon in the search results and verify it launches correctly
4. Right-click on an app icon in the search results and verify the context menu appears
5. Verify click and drag operations still work correctly in the frequently used and recently installed views

fix: 修复小窗口模式搜索列表中应用无法鼠标点击的问题

MouseArea 的 enabled 绑定到了 root.dndEnabled,而搜索结果的 delegate
未设置该属性,默认值为 false,导致 MouseArea 被完全禁用,onClicked
无法触发。同时 Button 消费了鼠标事件,阻止了外层 TapHandler 接收
事件,导致三层点击机制全部失效。

将 MouseArea 改为始终启用,仅通过 drag.target 条件控制拖拽行为,
使点击处理不再依赖 dndEnabled 的值。

Log: 修复小窗口模式搜索列表中应用无法鼠标点击的问题

Influence:
1. 打开小窗口模式的启动器
2. 在搜索框中输入关键字,触发搜索结果列表
3. 点击搜索结果中的应用图标,验证应用能正常启动
4. 右键点击搜索结果中的应用图标,验证右键菜单正常弹出
5. 验证常用应用和最近安装区域的点击和拖拽操作仍然正常

PMS: BUG-352527
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the MouseArea behavior in the windowed launcher icon delegate so that clicks always work while drag behavior is still gated by the drag-and-drop flag, fixing search results not responding to mouse clicks in windowed mode.

Sequence diagram for updated click handling in windowed search result items

sequenceDiagram
    actor User
    participant MouseArea
    participant Button
    participant TapHandler
    participant AppLauncher

    rect rgb(230,230,255)
        Note over User,AppLauncher: Left-click on search result item (windowed mode)
        User->>MouseArea: mousePress(Qt.LeftButton)
        alt dndEnabled is true
            MouseArea->>MouseArea: drag.target = root
            MouseArea-->>User: Begin drag if movement
        else dndEnabled is false
            MouseArea->>MouseArea: drag.target = null
            MouseArea-->>User: Treat as normal click
        end
        User->>MouseArea: mouseRelease(Qt.LeftButton)
        MouseArea->>AppLauncher: onClicked -> launch app
    end

    rect rgb(230,255,230)
        Note over User,AppLauncher: Right-click on search result item
        User->>TapHandler: rightClick
        TapHandler->>AppLauncher: show context menu
    end
Loading

File-Level Changes

Change Details Files
Ensure MouseArea in windowed icon delegate is always clickable while drag behavior remains conditional on drag-and-drop being enabled.
  • Set the MouseArea enabled property to always be true so it no longer depends on the dndEnabled flag, allowing onClicked/onPressed to fire consistently.
  • Update the MouseArea drag.target binding to use the root item only when dndEnabled is true and null otherwise, preserving conditional drag behavior without disabling clicks.
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:

  • Since MouseArea is enabled by default, enabled: true can be dropped and you can rely solely on the conditional drag.target binding to keep the change minimal and consistent with other delegates.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since MouseArea is enabled by default, `enabled: true` can be dropped and you can rely solely on the conditional `drag.target` binding to keep the change minimal and consistent with other delegates.

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

这段代码修改了 QML 中的拖拽逻辑,主要涉及 MouseArea 的属性配置。以下是对该 git diff 的详细审查意见,包括语法逻辑、代码质量、性能和安全方面的分析:

1. 语法逻辑

  • 修改前:
    enabled: root.dndEnabled
    drag.target: root
    逻辑是:当 dndEnabledfalse 时,禁用整个 MouseArea。这意味着鼠标事件(如点击、悬停)都会被拦截或忽略,且 drag.target 始终指向 root,依赖 MouseArea 的禁用状态来阻止拖拽。
  • 修改后:
    enabled: true
    drag.target: root.dndEnabled ? root : null
    逻辑是:MouseArea 始终处于启用状态,但在 drag.target 属性上使用三元运算符进行判断。只有当 dndEnabledtrue 时,拖拽目标才指向 root;否则为 null
  • 审查意见:
    • 逻辑正确性:修改后的逻辑是正确的。在 QML 中,将 drag.target 设置为 null 是禁用拖拽的标准做法。
    • 交互影响:修改前,当 dndEnabledfalse 时,MouseArea 被禁用,这可能导致其下方的组件接收到鼠标事件(穿透)。修改后,MouseArea 始终启用,这意味着即使不能拖拽,它也会消耗鼠标事件(如点击),阻止事件穿透到父组件或兄弟组件。请确认这是预期的交互行为。如果希望在不可拖拽时依然允许点击穿透,修改后的代码可能会导致问题(例如无法点击背景或其他元素)。

2. 代码质量

  • 可读性:修改后的代码 root.dndEnabled ? root : null 非常直观,明确表达了"条件满足时拖拽,否则不拖拽"的意图。
  • 维护性:将状态控制集中在 drag.target 属性上,比分散在 enableddrag.target 两个属性上更易于维护。开发者只需要关注拖拽相关的属性配置。
  • 一致性:代码中 onPressed 回调里依然保留了 if (root.dndEnabled) 的判断。虽然 drag.targetnull 时通常不会触发拖拽,但保留这个判断可以作为一种"双重保险"(Defense in depth),防止意外的逻辑分支,或者在 drag.target 之外有其他副作用逻辑。这是好的实践。

3. 代码性能

  • 绑定开销:修改后的代码引入了一个属性绑定 root.dndEnabled ? root : null。每次 root.dndEnabled 改变时,这个表达式都会重新求值。
  • 审查意见
    • dndEnabled 通常是一个布尔标志,不会高频变化,因此这个性能开销可以忽略不计。
    • 相比之下,修改前的 enabled: root.dndEnabled 也是一个绑定,两者在性能层面几乎没有差异。

4. 代码安全

  • 空指针安全:表达式 root.dndEnabled ? root : null 是安全的。当条件不满足时返回 null,这是 QML 拖拽系统明确定义的有效值,不会导致崩溃或未定义行为。
  • 状态一致性:修改后的代码确保了只要 dndEnabled 为 false,拖拽行为在物理上就不可能发生(因为没有 target),比单纯禁用 MouseArea 更能从底层机制上防止拖拽触发。

总结与改进建议

总体评价
这是一个合理的重构,旨在解耦"鼠标交互的启用"与"拖拽功能的启用"。它允许 MouseArea 处理其他鼠标事件(如点击),同时根据条件禁用拖拽。

改进建议

  1. 确认事件穿透需求
    如前所述,请确认当 dndEnabledfalse 时,是否需要保留 MouseArea 对点击事件的拦截。

    • 如果希望不可拖拽时,点击该区域不发生任何事(也不穿透),则当前修改是完美的。
    • 如果希望不可拖拽时,点击该区域穿透到下层,则应该恢复 enabled: root.dndEnabled,或者修改逻辑如下:
      // 方案 A: 恢复旧逻辑(如果不需要点击事件)
      enabled: root.dndEnabled
      drag.target: root
      
      // 方案 B: 允许点击但禁用拖拽(如果需要点击事件)
      enabled: true
      // 阻止拖拽,但允许鼠标通过 propagateComposedEvents 或其他机制传递(需具体场景分析)
      drag.target: root.dndEnabled ? root : null
  2. 代码注释
    由于 enabled 被硬编码为 true,未来维护者可能会疑惑为什么这里不控制开关。建议添加简短注释:

    // MouseArea must remain enabled to handle clicks, even if dragging is disabled
    enabled: true
    drag.target: root.dndEnabled ? root : null
  3. 性能微优化(非必须)
    如果 root 对象非常复杂,且 dndEnabled 变化极其频繁(虽然不太可能),可以考虑将 root 缓存为局部变量,但在 QML 属性绑定的上下文中,直接引用通常也是高效的,此处无需过度优化。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@robertkill robertkill merged commit 04d3aaf into linuxdeepin:master Mar 10, 2026
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.

4 participants