Skip to content

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

Open
fly602 wants to merge 1 commit intolinuxdeepin:masterfrom
fly602:master
Open

fix: show dock context menu on long press release#1571
fly602 wants to merge 1 commit intolinuxdeepin: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

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

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码主要实现了在 Dock 面板中通过长按(鼠标或触摸屏)触发菜单显示的功能。以下是对这段代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面的建议:

1. 语法逻辑

优点:

  • 代码逻辑基本正确,通过 isLongPressing 标志位来区分普通点击和长按操作。
  • 鼠标和触摸屏事件处理逻辑保持一致,符合预期。

问题与改进:

  • 状态管理不够清晰isLongPressingdockContainer 的属性,但只在 TapHandlerTapHandler 的作用域内使用。建议将其移至更合适的作用域,或者明确其生命周期。
  • 事件处理顺序onLongPressedonPressedChanged 的触发顺序可能导致竞态条件。建议在 onPressedChanged 中增加对 isLongPressing 的初始化检查。

2. 代码质量

优点:

  • 使用了 console.debug 输出调试信息,便于开发阶段调试。
  • 代码结构清晰,易于理解。

问题与改进:

  • 重复代码onPressedChanged 中的逻辑在 TapHandlerTapHandler 中完全重复。建议提取为共享函数或组件。
  • 调试信息冗余console.debug 语句在正式发布时可能影响性能或暴露内部逻辑。建议使用条件编译或日志级别控制。

3. 代码性能

问题与改进:

  • 频繁的属性访问dockContainer.isLongPressing 在多个地方被访问,可以考虑缓存该值以减少属性访问开销。
  • 不必要的计算onPressedChanged 中每次都会计算 lastActive,即使不需要。建议将计算移至实际需要时。

4. 代码安全

问题与改进:

  • 调试信息泄露console.debug 输出的调试信息可能被恶意用户利用。建议在生产环境中禁用或过滤敏感信息。
  • 状态不一致风险isLongPressing 的状态可能在异常情况下(如快速点击或触摸)不一致。建议增加状态重置逻辑或超时机制。

5. 具体改进建议

以下是优化后的代码示例:

Window {
    // ... 其他代码 ...

    // 将 isLongPressing 移至更合适的作用域
    property bool isLongPressing: false

    // 提取共享逻辑
    function handleLongPressRelease() {
        if (!isLongPressing) return;
        
        isLongPressing = false;
        let lastActive = MenuHelper.activeMenu;
        MenuHelper.closeCurrent();
        dockMenuLoader.active = true;
        
        if (lastActive !== dockMenuLoader.item) {
            requestShowDockMenu();
        }
    }

    TapHandler {
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        gesturePolicy: TapHandler.WithinBounds

        onTapped: {
            if (tapCount === 2) {
                viewDeactivated()
            }
        }
        
        onLongPressed: {
            console.debug("[Mouse Long Press] longPressed")
            isLongPressing = true
        }
        
        onPressedChanged: {
            console.debug("[Mouse Long Press] pressedChanged, pressed:", pressed, "isLongPressing:", isLongPressing)
            if (!pressed) {
                handleLongPressRelease();
            }
        }
    }

    // 触摸屏点击处理
    TapHandler {
        onTapped: {
            if (tapCount === 2) {
                viewDeactivated()
            }
        }
        
        onLongPressed: {
            console.debug("[Touch Long Press] longPressed")
            isLongPressing = true
        }
        
        onPressedChanged: {
            console.debug("[Touch Long Press] pressedChanged, pressed:", pressed, "isLongPressing:", isLongPressing)
            if (!pressed) {
                handleLongPressRelease();
            }
        }
    }
}

6. 其他建议

  1. 增加超时机制:如果用户长按后没有释放,可以设置一个超时时间自动重置 isLongPressing 状态。
  2. 事件防抖:在快速连续点击或触摸时,可以增加防抖逻辑避免误触发。
  3. 日志管理:使用统一的日志管理工具替代 console.debug,便于在生产环境中控制日志输出。

总结

这段代码实现了基本功能,但在状态管理、代码复用和性能优化方面还有改进空间。通过提取共享逻辑、优化属性访问和增加状态保护机制,可以提升代码的健壮性和可维护性。

@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

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