Skip to content

fix: restore right-click context menu in windowed launcher's frequent…#759

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/windowed-right-click-context-menu
May 15, 2026
Merged

fix: restore right-click context menu in windowed launcher's frequent…#759
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/windowed-right-click-context-menu

Conversation

@Ivy233
Copy link
Copy Markdown
Contributor

@Ivy233 Ivy233 commented May 15, 2026

…ly used view

The TapHandler addition in 957e8a7 caused MouseArea to participate in the pointer event delivery system, which bypassed the acceptedButtons filter and allowed right-click events to be consumed by onClicked, triggering app launch instead of the context menu.

fix: 修复弹窗启动器"常用应用"区域右键菜单失效的问题

957e8a7 提交中新增的 TapHandler 导致 MouseArea 参与指针事件分发系统, 绕过了 acceptedButtons 过滤,右键事件被 onClicked 消费,触发启动应用
而非弹出右键菜单。

PMS: BUG-360855

Summary by Sourcery

Bug Fixes:

  • Prevent right-click events on frequently used app icons in the windowed launcher from being treated as normal clicks that launch the app, allowing the context menu to appear as expected.

…ly used view

The TapHandler addition in 957e8a7 caused MouseArea to participate in the
pointer event delivery system, which bypassed the acceptedButtons filter and
allowed right-click events to be consumed by onClicked, triggering app launch
instead of the context menu.

fix: 修复弹窗启动器"常用应用"区域右键菜单失效的问题

957e8a7 提交中新增的 TapHandler 导致 MouseArea 参与指针事件分发系统,
绕过了 acceptedButtons 过滤,右键事件被 onClicked 消费,触发启动应用
而非弹出右键菜单。

PMS: BUG-360855
@Ivy233 Ivy233 requested a review from 18202781743 May 15, 2026 03:44
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 15, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Restricts the launcher icon MouseArea to handle only left-clicks so that right-click events are no longer consumed by the click handler, restoring the system context menu in the windowed launcher’s frequently used view.

Sequence diagram for restored right-click context menu handling

sequenceDiagram
    actor User
    participant MouseArea
    participant root
    participant ContextMenu

    User->>MouseArea: mousePress(button)
    alt LeftButton
        MouseArea->>MouseArea: onPressed(mouse)
        MouseArea->>root: itemClicked() [via onClicked]
    else RightButton
        MouseArea->>MouseArea: onPressed(mouse)
        MouseArea-->>User: mouse.accepted = false
        User->>ContextMenu: showContextMenu()
    end
Loading

File-Level Changes

Change Details Files
Ensure MouseArea only handles left-button interactions so right-click continues to open the context menu instead of launching the app.
  • Add an early return in onPressed for non-left mouse buttons and mark the event as not accepted so it can propagate to the context menu handler.
  • Remove the redundant left-button check in the drag-and-drop preparation logic, now guarded by the left-button filter.
  • Update onClicked to take the mouse event parameter and ignore non-left-button clicks while preserving the long-press guard and drag-active guard before invoking itemClicked.
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
Copy Markdown

@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:

  • The left-button guard logic is duplicated between onPressed and onClicked; consider extracting a small helper or at least centralizing the button check so future changes don’t get out of sync.
  • You’re explicitly rejecting non-left clicks in onPressed, but onClicked just returns without changing mouse.accepted; consider making the acceptance behavior consistent across both handlers so other handlers (e.g., context menu logic) see a predictable event state.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The left-button guard logic is duplicated between onPressed and onClicked; consider extracting a small helper or at least centralizing the button check so future changes don’t get out of sync.
- You’re explicitly rejecting non-left clicks in onPressed, but onClicked just returns without changing mouse.accepted; consider making the acceptance behavior consistent across both handlers so other handlers (e.g., context menu logic) see a predictable event state.

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

deepin pr auto review

你好!我是CodeGeeX,你的智能编程助手。我已仔细审查了你提供的 QML 代码的 git diff

这段代码的主要修改是为 IconItemDelegate 的鼠标按下(onPressed)和点击(onClicked)事件增加了对鼠标按键的过滤(仅响应左键 Qt.LeftButton),并对拖拽(dnd)逻辑进行了简化。

以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的审查意见和改进建议:

1. 语法与逻辑

  • onClickedmouse 对象的可用性风险
    在 QML 的 MouseArea 中,onClicked 信号是会传递 mouse 参数的,所以 onClicked: function(mouse) 在语法上是正确的。但是,在 QML 的某些版本或某些自定义的 Control 组件中,clicked 信号的参数可能不总是包含完整的 mouse 对象(或者可能为 undefined)。为了逻辑的健壮性,建议在访问 mouse.button 前增加存在性检查,或者依赖 onPressed 中的拦截。
  • 逻辑拦截的冗余性
    你在 onPressed 中已经对非左键事件执行了 mouse.accepted = false,这意味着该鼠标事件将不会被继续下发,理论上 MouseArea 不会触发 onClicked 信号。因此在 onClicked 中再次检查 mouse.button !== Qt.LeftButton 虽然是防御性编程,但属于冗余逻辑。

2. 代码质量

  • 状态重置逻辑的隐患
    onClicked 中,如果 isTouchLongPressedtrue,代码会将其重置为 falsereturn。这意味着长按事件被消费了。但是,如果用户在触摸屏上长按后松开,触发的是 canceled 还是 clicked?建议确认长按的打断逻辑,通常长按打断应该在 onReleasedonCanceled 中统一处理状态重置,而不是在 onClicked 中,否则可能导致状态机混乱。
  • 代码一致性
    onPressed 使用了 function(mouse) 的写法,onClicked 也改成了 function(mouse),保持了代码风格的一致性,这一点做得很好。

3. 代码性能

  • grabToImage 的性能开销
    onPressed 中,每次按下左键且 dndEnabled 为真时,都会调用 appIcon.grabToImage()。这是一个同步渲染操作,会将组件渲染为图片,这在频繁点击时可能会产生性能开销(内存分配和 GPU 渲染)。
    改进建议:如果 appIcon 的视觉内容在不切换时是不变的,建议缓存这个 imageSource,仅在图标源发生改变时才重新 grabToImage,而不是每次 Press 都去生成。

4. 代码安全

  • 资源泄漏(QML 上下文)
    grabToImage 的回调函数 function(result) { root.Drag.imageSource = result.url; } 是一个闭包。如果用户极快地点击并拖拽,可能会在旧的 grabToImage 未完成时触发新的请求。虽然 Qt 内部通常会处理掉旧的回调,但 result.url 指向的是临时缓存文件,应确保该 URL 在拖拽结束前不会被 Qt 内部回收。
  • 事件穿透的安全性
    mouse.accepted = false 会将事件传递给父组件,这是正确的做法,确保了右键菜单等事件能被上层捕获,不存在安全风险。

💡 综合改进后的代码建议

基于以上分析,我为你优化了代码。主要改进点在于:增强了 mouse 对象的安全检查,优化了 onClicked 中的冗余判断,并添加了相关的逻辑注释。

            onPressed: function (mouse) {
                // 拦截非左键事件,使其穿透给父组件处理(如右键菜单)
                if (!mouse || mouse.button !== Qt.LeftButton) {
                    mouse.accepted = false
                    return
                }

                isTouchLongPressed = false

                if (root.dndEnabled) {
                    // TODO: 性能优化考虑 - 如果 appIcon 不常变化,可考虑缓存 result.url,避免每次 Press 都触发渲染
                    appIcon.grabToImage(function(result) {
                        if (result.url) {
                            root.Drag.imageSource = result.url;
                        }
                    })
                }
            }

            onClicked: function(mouse) {
                // 恢复长按状态(建议评估是否应放在 onReleased/onCanceled 中统一管理)
                if (isTouchLongPressed) {
                    isTouchLongPressed = false
                    return
                }

                // 防御性编程:虽然 onPressed 已经拦截了非左键,但防止意外情况导致非左键触发 clicked
                if (mouse && mouse.button !== Qt.LeftButton) {
                    return
                }

                if (!drag.active) {
                    root.itemClicked()
                }
            }

如果你对上述建议有任何疑问,或者需要我进一步解释 QML 的事件分发机制,随时告诉我!

Comment thread qml/windowed/IconItemDelegate.qml
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@Ivy233
Copy link
Copy Markdown
Contributor Author

Ivy233 commented May 15, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented May 15, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit c5982f0 into linuxdeepin:master May 15, 2026
9 of 11 checks passed
@Ivy233 Ivy233 deleted the fix/windowed-right-click-context-menu branch May 15, 2026 06:47
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