Skip to content

fix: enable right-click menu via long-press on touchscreen#1579

Open
wjyrich wants to merge 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-bug-358827
Open

fix: enable right-click menu via long-press on touchscreen#1579
wjyrich wants to merge 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-bug-358827

Conversation

@wjyrich
Copy link
Copy Markdown
Contributor

@wjyrich wjyrich commented Apr 29, 2026

Previously, only touch long-press events (mouse.button === Qt.NoButton) triggered the app item's context menu. This change also recognizes right-button long-press events, allowing touchscreen users with right- click hardware buttons to access the menu.

Log: Fixed right-click menu not working on touchscreen devices

Influence:

  1. Test long-press on a taskbar app item using a touchscreen (simulate touch input)
  2. Test long-press using a right-click hardware button on a touchscreen device
  3. Verify that the correct context menu appears for both scenarios
  4. Ensure normal left-click behavior remains unchanged
  5. Verify that the change does not affect desktop mouse right-click behavior

fix: 在触摸屏上支持通过长按右键弹出菜单

之前只有触摸长按事件(mouse.button === Qt.NoButton)能触发应用项的右键
菜单。此次变更同时识别右键长按事件,允许带有右键硬件按钮的触摸屏用户访问
菜单。

Log: 修复触摸屏设备右键菜单无法使用的问题

Influence:

  1. 在任务栏应用项上使用触摸屏进行长按测试(模拟触摸输入)
  2. 在触摸屏设备上使用右键硬件按钮进行长按测试
  3. 验证两种场景下均能弹出正确的上下文菜单
  4. 确保普通的左键操作行为不受影响
  5. 验证该改动不会影响桌面鼠标右键行为

PMS: BUG-358827

Summary by Sourcery

Bug Fixes:

  • Fix touchscreen devices failing to open the app item context menu when long-pressing with a hardware right-click button.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 29, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Extends the AppItem long-press handler so that both pure touch long-presses and right-button long-presses on touchscreens open the taskbar app item's context menu, without changing normal left-click or desktop right-click behavior.

Sequence diagram for AppItem long-press handling on touchscreen

sequenceDiagram
    actor TouchUser
    participant AppItem
    participant ContextMenu

    TouchUser->>AppItem: pressAndHold (touch, Qt.NoButton)
    AppItem->>AppItem: onPressAndHold(mouse)
    AppItem->>AppItem: if mouse.button == Qt.NoButton or Qt.RightButton
    AppItem->>ContextMenu: requestAppItemMenu()

    TouchUser->>AppItem: pressAndHold (right-click hardware, Qt.RightButton)
    AppItem->>AppItem: onPressAndHold(mouse)
    AppItem->>AppItem: if mouse.button == Qt.NoButton or Qt.RightButton
    AppItem->>ContextMenu: requestAppItemMenu()

    TouchUser->>AppItem: short tap (Qt.LeftButton)
    AppItem->>AppItem: onClicked(mouse)
    AppItem-->>ContextMenu: no request (normal left-click behavior)
Loading

File-Level Changes

Change Details Files
Recognize right-button long-press events in addition to touch-only long-presses to trigger the app item context menu.
  • Update press-and-hold handler condition to accept both no-button (touch) and right-button inputs
  • Keep existing requestAppItemMenu() invocation and behavior unchanged for qualifying events
panels/dock/taskmanager/package/AppItem.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 reviewed your changes and they look great!


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.

@wjyrich wjyrich requested a review from 18202781743 April 29, 2026 07:41
@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented Apr 29, 2026

TAG Bot

New tag: 2.0.39
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1580

Changed touchscreen long press handling from `MouseArea.onPressAndHold`
to `TapHandler.onLongPressed` to avoid conflicting behavior and
duplicate menu triggers when the user releases the touch. The
`isTouchLongPressed` flag is now used to skip `onClicked` processing
after a long press, ensuring the menu appears only once.

Log: Fixed touchscreen long press menu activation for dock app items

Influence:
1. Test touchscreen long press on various dock app items; verify the
context menu appears only once
2. Test touchscreen tap; ensure the app launches without unintended menu
3. Test left-click and right-click with a mouse; verify no regression in
menu or drag behavior
4. Test touchscreen drag; verify drag initiation still works correctly
5. Test combined mouse and touch interactions; verify no false menu
triggers

fix: 修复触摸屏长按导致菜单重复弹出问题

将触摸屏长按处理从 `MouseArea.onPressAndHold` 迁移到
`TapHandler.onLongPressed`,避免了释放触摸时触发的冲突行为和菜单重复弹
出。通过 `isTouchLongPressed` 标志在 `onClicked` 中跳过处理,确保菜单只
弹出一次。

Log: 修复任务栏应用项触摸长按菜单激活问题

Influence:
1. 在多个任务栏应用项上测试触摸屏长按,验证上下文菜单仅弹出一次
2. 测试触摸屏点击,验证应用正常启动,不出现意外菜单
3. 测试鼠标左键和右键点击,验证菜单和拖拽行为无回归
4. 测试触摸屏拖拽,验证拖拽操作正常启动
5. 测试鼠标和触摸混合操作,验证无错误菜单触发

PMS: BUG-358827
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码修改主要涉及触摸屏长按和鼠标点击事件的交互逻辑处理。以下是对该 git diff 的详细审查意见:

1. 语法逻辑审查

  • 逻辑正确性:代码通过引入 isTouchLongPressed 标志位,成功解决了 TapHandler(处理触摸长按)和 MouseAreaonClicked(处理点击)之间的冲突。
    • 当用户在触摸屏上长按时,TapHandler 触发 onLongPressed,设置标志位为 true 并弹出菜单。
    • 随后长按结束通常会触发 MouseAreaonClicked 信号。由于此时 isTouchLongPressedtrueonClicked 会直接 return,避免了重复弹出菜单或执行点击逻辑。
    • onPressed 中重置该标志位,确保每次新的按下操作都从初始状态开始,逻辑闭环完整。
  • 事件顺序:Qt/QML 的事件处理顺序通常是先 onPressed,再处理 TapHandler,最后是 onClicked。代码利用了这一顺序:
    1. onPressed: 重置标志位 false
    2. TapHandler: 如果是长按,设置标志位 true
    3. onClicked: 检查标志位,决定是否执行。
      这个顺序是正确的。

2. 代码质量审查

  • 可读性:注释 // 记录是否是触摸长按导致的,防止在 onClicked 中重复处理 清晰地解释了引入该变量的目的,有助于后续维护。
  • 代码整洁度:移除了旧的 onPressAndHold 逻辑,使代码结构更清晰,避免了在 MouseArea 中混用鼠标和触摸事件的处理,职责划分更明确(TapHandler 专门处理触摸,MouseArea 专门处理鼠标/通用点击)。

3. 代码性能审查

  • 性能影响:引入一个布尔属性 isTouchLongPressed 对性能影响极小,几乎可以忽略不计。
  • 事件处理TapHandler 是 QML 中处理触摸手势的高效方式,比手动在 MouseArea 中通过计时器判断长按性能更好且更符合 Qt 的设计规范。

4. 代码安全审查

  • 状态一致性:在 onPressed 中重置 isTouchLongPressed = false 是非常关键的一步。这确保了如果用户快速连续点击,或者上一次操作异常终止,状态不会被错误地保留到下一次操作中,防止了“一次长按导致后续所有点击失效”的潜在 Bug。
  • 设备区分acceptedDevices: PointerDevice.TouchScreen 明确限制了 TapHandler 仅响应触摸屏事件,防止了鼠标长按意外触发触摸逻辑,增强了交互的确定性。

改进建议

虽然代码逻辑已经比较完善,但仍有以下两点可以优化:

  1. 变量作用域与命名

    • isTouchLongPressed 属性目前定义在 Item 的根层级(推测,因为它在 onPressedTapHandler 之间共享)。如果这个逻辑仅在这个局部范围内有效,建议将其作用域限制得更小,或者添加前缀(如 privateIsTouchLongPressed)以表明它是内部状态,防止外部意外修改。
  2. 逻辑合并(可选)

    • onClicked 中,isTouchLongPressed 被检查后立即被重置为 false
    • 实际上,onPressed 中已经重置了它。虽然在 onClicked 中再次重置是“防御性编程”的好习惯,但在 onPressed 必然先于 onClicked 执行的前提下,onClicked 里的重置略显冗余。不过保留它可以增加代码的健壮性,不是严重问题。

总结
这段代码是一个高质量的修复,有效地解决了触摸长按与点击事件的冲突问题。逻辑清晰,注释得当,且考虑了状态重置,是一个可靠的提交。

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.

2 participants