Skip to content

fix: show dock context menu on long press release#1571

Merged
fly602 merged 1 commit into
linuxdeepin:masterfrom
fly602:master
May 20, 2026
Merged

fix: show dock context menu on long press release#1571
fly602 merged 1 commit into
linuxdeepin:masterfrom
fly602:master

Conversation

@fly602
Copy link
Copy Markdown
Contributor

@fly602 fly602 commented Apr 28, 2026

  1. Add isLongPressing property to track long press state
  2. Defer dock context menu display until long press is released for mouse input
  3. Refactor touch long press to use same deferred release pattern
  4. Add debug logging for both mouse and touch long press events

Previously the dock context menu opened immediately on the longPressed signal, which could cause unexpected behavior while the user was still pressing. Now the menu only appears after the long press is released, providing a more natural and predictable interaction.

Log: Changed dock long press behavior to show context menu on release instead of immediately

Influence:

  1. Test mouse long press on dock - verify context menu appears on release not during press
  2. Test touch long press on dock - verify context menu appears on release not during press
  3. Test short click/tap on dock - verify context menu does NOT appear
  4. Test right-click on dock - verify normal context menu behavior is unaffected
  5. Test long press and drag - verify no unexpected menu activation
  6. Test rapid long press/release cycles - verify isLongPressing flag resets correctly

fix: 修复任务栏长按上下文菜单在松开时才显示

  1. 添加 isLongPressing 属性用于跟踪长按状态
  2. 鼠标输入的长按上下文菜单延迟到松开时显示
  3. 重构触摸长按逻辑,使用相同的延迟松开模式
  4. 为鼠标和触摸长按事件添加调试日志

此前任务栏上下文菜单在 longPressed 信号触发时立即打开,可能导致用户仍在
按压时出现意外行为。现在菜单仅在长按松开后显示,提供更自然和可预测的交互
体验。

Log: 修改任务栏长按行为,上下文菜单在松开时显示而非立即显示

Influence:

  1. 测试鼠标长按任务栏 - 验证上下文菜单在松开时而非按压时显示
  2. 测试触摸长按任务栏 - 验证上下文菜单在松开时而非按压时显示
  3. 测试短按/轻点任务栏 - 验证上下文菜单不会出现
  4. 测试右键点击任务栏 - 验证正常的上下文菜单行为不受影响
  5. 测试长按并拖动 - 验证不会意外激活菜单
  6. 测试快速长按/松开循环 - 验证 isLongPressing 标志正确重置

PMS: BUG-358827
Change-Id: I23597cf45ae2c4cea634eb525a6ad09bde5fc89a

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.

Sorry @fly602, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

18202781743
18202781743 previously approved these changes Apr 28, 2026
@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

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented May 9, 2026

TAG Bot

New tag: 2.0.40
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1592

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented May 14, 2026

TAG Bot

New tag: 2.0.41
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1596

@fly602 fly602 force-pushed the master branch 2 times, most recently from 2fa95bd to 2dedacb Compare May 19, 2026 08:45
1. Replace the previous MouseArea click handling with TapHandler-based
input processing in the multitask view dock item
2. Handle mouse input explicitly by accepting left and right buttons,
but only execute Applet.openWorkspace() on left-button taps
3. Add a dedicated touch-screen TapHandler that accepts touch input and
opens the workspace on tap
4. Keep gesture handling within bounds to avoid unintended activation
outside the item area
5. This change prevents right-click mouse actions and long-press
touch interactions from triggering behavior that could lead to an
unnecessary context menu, while preserving normal left-click and touch-
tap activation

Log: Adjusted multitask view interaction so right-click and touch long-
press no longer bring up the context menu

Influence:
1. Verify left-click on the multitask view item still opens the
workspace and closes the tooltip
2. Verify right-click on the multitask view item does not open the
workspace and does not show an unwanted context menu
3. Verify single tap on a touch screen still opens the workspace
correctly
4. Verify long-press on a touch screen does not trigger a context menu
or other unintended action
5. Verify hover behavior and tooltip display remain unchanged
6. Verify taps or clicks outside the item bounds do not trigger
workspace activation

fix: 禁止多任务视图触发右键菜单

1. 将多任务视图停靠项中原有的 MouseArea 点击处理替换为基于 TapHandler 的
输入处理
2. 显式处理鼠标输入,接受左键和右键事件,但仅在左键点击时执行
Applet.openWorkspace()
3. 新增一个专用于触摸屏的 TapHandler,用于接收触控输入并在点击时打开工
作区
4. 将手势处理限制在组件边界内,避免在项目区域外发生误触发
5. 此修改可避免鼠标右键操作和触摸屏长按交互触发可能导致不必要右键菜单的
行为,同时保留正常的左键点击和触控点击激活能力

Log: 调整多任务视图交互,右键和触摸长按不再弹出右键菜单

Influence:
1. 验证左键点击多任务视图项后,仍可正常打开工作区并关闭提示框
2. 验证右键点击多任务视图项时,不会打开工作区,也不会弹出不需要的右键
菜单
3. 验证在触摸屏上单击后,仍可正常打开工作区
4. 验证在触摸屏上长按时,不会触发右键菜单或其他非预期行为
5. 验证悬停行为和提示框显示逻辑保持不变
6. 验证在组件边界外的点击或触控不会触发工作区打开

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

deepin pr auto review

你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff代码。本次修改主要是将QML中的 MouseArea 替换为了更现代的 TapHandler,并分离了鼠标点击和触摸屏点击的逻辑。

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

1. 语法与逻辑

  • 信号参数不匹配(重要)TapHandleronTapped 信号的参数签名是 onTapped(eventPoint, button),其中 button单数,表示触发事件的那个按键(如 Qt.LeftButton)。你代码中写的是 buttons(复数),这在QML中虽然不会直接报错(JS的弱类型特性),但语义不准确,且如果后续有人误以为它是位掩码组合(如 Qt.LeftButton | Qt.RightButton)就会产生逻辑Bug。
  • 触摸屏TapHandler的冗余逻辑:你为触摸屏单独写了一个 TapHandler,并设置了 acceptedButtons: Qt.NoButton。实际上,TapHandler 默认就会接受触摸屏的 Tap 事件。如果你只是为了区分鼠标和触摸,或者防止触摸屏长按触发右键菜单,这种写法可以接受,但 Qt.NoButton 的语义有些模糊。
  • 右键点击逻辑丢失:原 MouseArea 虽然没有显式处理 Qt.RightButton,但它会拦截右键事件。新的鼠标 TapHandler 声明了 acceptedButtons: Qt.LeftButton | Qt.RightButton,但在 onTapped 中只处理了左键。如果右键点击,事件被该 Handler 拦截但未做任何处理,可能会导致原本期望的右键菜单(如Dock栏图标的上下文菜单)失效。

2. 代码质量

  • 对象冗余:目前使用了两个 TapHandler 来分别处理鼠标和触摸。虽然Qt Quick允许挂载多个Input Handler,但在这个场景下,完全可以合并为一个 TapHandler,通过判断设备类型来执行逻辑,这样代码更简洁,也更符合Qt官方推荐的做法。
  • 属性冗余gesturePolicy: TapHandler.WithinBoundsTapHandler 的默认值,显式写出虽然增加了可读性,但略显冗余。如果团队规范要求显式声明默认值则保留,否则可以移除。

3. 代码性能

  • 事件处理开销:使用两个 TapHandler 意味着每次点击事件到达时,QML引擎都需要遍历并计算两个Handler的 acceptedDevicesacceptedButtons,这比单个Handler带来了微小的额外开销。在嵌入式或低端设备上,合并为一个Handler性能表现更好。

4. 代码安全

  • 事件拦截安全(逻辑漏洞):如前文所述,鼠标 TapHandler 设置了接受右键但未处理右键,这属于“事件吞没”,会破坏UI的交互完整性,导致用户右键无响应。
  • 输入校验:QML的Handler底层由C++驱动,传入的 eventPointbutton 都是安全的,不存在注入风险,这方面没有问题。

💡 改进建议与重构代码

建议将两个 TapHandler 合并为一个,利用 eventPoint.device 来区分输入设备,并修复参数命名和右键拦截的问题。

改进后的代码:

    TapHandler {
        id: tapHandler
        // 只接受鼠标左键和右键(触摸屏的Tap不依赖button,会被自动识别)
        acceptedButtons: Qt.LeftButton | Qt.RightButton 
        
        onTapped: function (eventPoint, button) {
            // 1. 处理鼠标左键 或 触摸屏点击
            if (button === Qt.LeftButton || eventPoint.device === PointerDevice.TouchScreen) {
                Applet.openWorkspace()
                toolTip.close()
            } 
            // 2. 如果需要保留右键菜单功能,不应该在这里拦截右键
            // 如果确定不需要右键菜单,当前逻辑是安全的;否则需要移除 Qt.RightButton
        }
    }

如果你坚决需要隔离鼠标和触摸屏的逻辑(例如触摸屏需要特殊防抖处理),改进后的双Handler代码应为:

    TapHandler {
        id: mouseTapHandler
        acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad // 明确只接受鼠标/触控板
        acceptedButtons: Qt.LeftButton // 只接受左键,右键事件放行给其他组件(如菜单)
        
        onTapped: function (eventPoint, button) {
            if (button === Qt.LeftButton) {
                Applet.openWorkspace()
                toolTip.close()
            }
        }
    }

    TapHandler {
        id: touchTapHandler
        acceptedDevices: PointerDevice.TouchScreen // 明确只接受触摸屏
        // 触摸屏Tap不需要判断button
        
        onTapped: function (eventPoint, button) {
            Applet.openWorkspace()
            toolTip.close()
        }
    }

总结: 最推荐第一种(单Handler)方案,它更简洁、性能更好,且避免了事件吞没的问题。请根据你的实际业务需求(特别是右键菜单是否需要存在)调整 acceptedButtons

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@fly602 fly602 merged commit c92e0d4 into linuxdeepin:master May 20, 2026
11 of 12 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