Skip to content

fix: fix touchscreen long press and drag issues#741

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
18202781743:master
Mar 19, 2026
Merged

fix: fix touchscreen long press and drag issues#741
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Mar 18, 2026

  1. Changed visibility handling to opacity for dragged items to maintain
    layout stability
  2. Replaced DragHandler with MouseArea for better touchscreen
    compatibility
  3. Fixed drag state condition to use mouseArea.drag.active instead of
    dragHandler.active
  4. Added proper touchscreen long press support via onPressAndHold
    handler
  5. Implemented deferred drag start to prevent crashes during page/folder
    transitions
  6. Restored click and right-click functionality within the MouseArea

Log: Fixed touchscreen long press not triggering context menu and
improved drag-and-drop reliability

Influence:

  1. Test long press on touchscreen to verify context menu appears
  2. Test drag-and-drop operations on both mouse and touchscreen
  3. Verify items disappear properly during drag (opacity becomes 0)
  4. Test folder opening/closing during drag operations
  5. Test right-click functionality still works correctly
  6. Verify no crashes occur when switching pages during drag
  7. Test drag threshold and hot spot positioning

fix: 修复触摸屏长按和拖拽问题

  1. 将拖拽项的可见性处理改为透明度控制,以保持布局稳定性
  2. 用 MouseArea 替换 DragHandler 以获得更好的触摸屏兼容性
  3. 修复拖拽状态条件,使用 mouseArea.drag.active 替代 dragHandler.active
  4. 通过 onPressAndHold 处理器添加正确的触摸屏长按支持
  5. 实现延迟拖拽启动,防止在页面/文件夹切换期间崩溃
  6. 恢复 MouseArea 内的点击和右键点击功能

Log: 修复触摸屏长按无法触发上下文菜单的问题,并提高拖拽操作的可靠性

Influence:

  1. 测试触摸屏长按,验证上下文菜单是否正常显示
  2. 测试鼠标和触摸屏上的拖拽操作
  3. 验证拖拽期间项目是否正确消失(透明度变为0)
  4. 测试拖拽操作期间的文件夹打开/关闭
  5. 测试右键点击功能是否仍然正常工作
  6. 验证在拖拽期间切换页面不会导致崩溃
  7. 测试拖拽阈值和热点定位

Summary by Sourcery

Improve touch and mouse drag-and-drop handling for icon items to stabilize layout and prevent crashes during drag operations.

Bug Fixes:

  • Fix drag state tracking for icon delegates by basing it on the MouseArea drag state.
  • Prevent crashes when icons are destroyed during drag operations by deferring drag start from the delegate.
  • Ensure icons visually disappear during drag without affecting layout by controlling opacity instead of visibility.

Enhancements:

  • Replace DragHandler with a MouseArea-based implementation to improve touchscreen compatibility for dragging icons.
  • Add proper touchscreen long-press handling to trigger the context menu on icon items.
  • Restore left-click and right-click activation on icon items while preserving drag behavior.

1. Changed visibility handling to opacity for dragged items to maintain
layout stability
2. Replaced DragHandler with MouseArea for better touchscreen
compatibility
3. Fixed drag state condition to use mouseArea.drag.active instead of
dragHandler.active
4. Added proper touchscreen long press support via onPressAndHold
handler
5. Implemented deferred drag start to prevent crashes during page/folder
transitions
6. Restored click and right-click functionality within the MouseArea

Log: Fixed touchscreen long press not triggering context menu and
improved drag-and-drop reliability

Influence:
1. Test long press on touchscreen to verify context menu appears
2. Test drag-and-drop operations on both mouse and touchscreen
3. Verify items disappear properly during drag (opacity becomes 0)
4. Test folder opening/closing during drag operations
5. Test right-click functionality still works correctly
6. Verify no crashes occur when switching pages during drag
7. Test drag threshold and hot spot positioning

fix: 修复触摸屏长按和拖拽问题

1. 将拖拽项的可见性处理改为透明度控制,以保持布局稳定性
2. 用 MouseArea 替换 DragHandler 以获得更好的触摸屏兼容性
3. 修复拖拽状态条件,使用 mouseArea.drag.active 替代 dragHandler.active
4. 通过 onPressAndHold 处理器添加正确的触摸屏长按支持
5. 实现延迟拖拽启动,防止在页面/文件夹切换期间崩溃
6. 恢复 MouseArea 内的点击和右键点击功能

Log: 修复触摸屏长按无法触发上下文菜单的问题,并提高拖拽操作的可靠性

Influence:
1. 测试触摸屏长按,验证上下文菜单是否正常显示
2. 测试鼠标和触摸屏上的拖拽操作
3. 验证拖拽期间项目是否正确消失(透明度变为0)
4. 测试拖拽操作期间的文件夹打开/关闭
5. 测试右键点击功能是否仍然正常工作
6. 验证在拖拽期间切换页面不会导致崩溃
7. 测试拖拽阈值和热点定位
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 18, 2026

Reviewer's Guide

Refactors drag-and-drop handling from DragHandler to MouseArea to improve touchscreen long-press support and drag reliability, switches dragged-item hiding from visibility to opacity, and defers drag start to avoid crashes when delegates are destroyed during page or folder transitions.

Sequence diagram for deferred drag start with MouseArea

sequenceDiagram
    actor User
    participant MouseArea
    participant IconDelegateRoot as IconDelegateRoot
    participant IconLoader as IconLoader
    participant DndItem as DndItem
    participant Qt as Qt

    User->>MouseArea: press(left button)
    MouseArea->>IconDelegateRoot: set Drag.hotSpot
    MouseArea->>IconLoader: grabToImage(callback)
    IconLoader-->>MouseArea: callback(result)
    MouseArea->>IconDelegateRoot: set Drag.imageSource

    User->>MouseArea: start_drag_move
    MouseArea->>MouseArea: drag.active = true
    MouseArea->>DndItem: set currentlyDraggedId
    MouseArea->>DndItem: set currentlyDraggedIconName
    MouseArea->>DndItem: copy Drag.hotSpot
    MouseArea->>DndItem: copy Drag.mimeData
    MouseArea->>DndItem: set mergeSize
    MouseArea->>DndItem: copy Drag.imageSource
    MouseArea->>DndItem: set Drag.dragType
    MouseArea->>Qt: callLater(startDnd)
    Qt-->>DndItem: startDnd()
    DndItem->>DndItem: Drag.active = true
    DndItem->>DndItem: Drag.startDrag()

    note over IconDelegateRoot,DndItem: IconDelegateRoot may be destroyed during drag without crashing
Loading

Sequence diagram for touchscreen long press context menu

sequenceDiagram
    actor TouchUser as TouchUser
    participant MouseArea
    participant IconDelegateRoot as IconDelegateRoot

    TouchUser->>MouseArea: touch_and_hold
    MouseArea->>MouseArea: onPressAndHold(mouse)
    MouseArea->>IconDelegateRoot: menuTriggered()
Loading

Class diagram for updated icon drag and interaction handling

classDiagram
    class IconItemDelegate {
        +bool dndEnabled
        +string iconSource
        +DragAttached Drag
        +void folderClicked()
        +void itemClicked()
        +void menuTriggered()
    }

    class MouseAreaDelegate {
        +bool hoverEnabled
        +DragHandler drag
        +void onPressed(mouse)
        +void onClicked(mouse)
        +void onPressAndHold(mouse)
    }

    class DndItem {
        +string currentlyDraggedId
        +string currentlyDraggedIconName
        +int mergeSize
        +DragAttached Drag
    }

    class FolderGridViewPopupDelegate {
        +string desktopId
        +string iconSource
        +int opacity
        +DragAttached Drag
    }

    class FullscreenFrameDelegate {
        +string desktopId
        +string iconSource
        +int opacity
        +DragAttached Drag
        +bool dndEnabled
    }

    IconItemDelegate o-- MouseAreaDelegate : contains
    IconItemDelegate ..> DndItem : configures_drag_state
    FolderGridViewPopupDelegate ..> DndItem : hides_via_opacity
    FullscreenFrameDelegate ..> DndItem : hides_via_opacity
    DndItem <.. MouseAreaDelegate : receives_drag_parameters

    class DragAttached {
        +bool active
        +int dragType
        +point hotSpot
        +map mimeData
        +string imageSource
        +void startDrag()
    }
Loading

File-Level Changes

Change Details Files
Refactor drag handling from DragHandler to MouseArea with proper drag/image setup and deferred drag start to avoid crashes.
  • Replace DragHandler with MouseArea that drives root as drag.target when drag-and-drop is enabled
  • Initialize Drag.hotSpot and imageSource on mouse press by mapping the press position and grabbing the icon image
  • On drag activation, transfer Drag-related properties from the delegate (root) to the global dndItem and set dragType to Automatic
  • Use Qt.callLater to activate dndItem.Drag to avoid nested event loop issues if the delegate is destroyed during drag
qml/IconItemDelegate.qml
Fix drag state tracking to use MouseArea drag state instead of removed DragHandler.
  • Update dragged state condition to depend on mouseArea.drag.active
  • Update state PropertyChanges target to mouseArea.drag.target to match new drag handler
qml/IconItemDelegate.qml
Restore and clarify pointer interactions, including click, right-click, and touchscreen long press for context menu.
  • Add MouseArea.onClicked handler to route left-clicks to folder or item activation and right-clicks to context menu trigger
  • Add MouseArea.onPressAndHold handler to trigger the context menu for touchscreen long press when no button is reported
qml/IconItemDelegate.qml
Hide dragged items using opacity instead of visibility to avoid layout changes during drag.
  • Change FolderGridViewPopup item hiding condition from visible to opacity based on whether the item is currently being dragged
  • Apply the same opacity-based hiding logic in FullscreenFrame for desktop items
qml/FolderGridViewPopup.qml
qml/FullscreenFrame.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 found 2 issues, and left some high level feedback:

  • Switching from visible to opacity keeps the delegate in the hit-test area; if the dragged icon should not accept input while currentlyDraggedId === model.desktopId, consider also gating enabled (or acceptedButtons) on that condition to avoid clicks/presses on an invisible item.
  • The MouseArea now combines drag.threshold with onClicked; if very small drags should not result in a click action, you may want to track whether a drag was initiated/moved and suppress the click handler in that case.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Switching from `visible` to `opacity` keeps the delegate in the hit-test area; if the dragged icon should not accept input while `currentlyDraggedId === model.desktopId`, consider also gating `enabled` (or `acceptedButtons`) on that condition to avoid clicks/presses on an invisible item.
- The MouseArea now combines `drag.threshold` with `onClicked`; if very small drags should not result in a click action, you may want to track whether a drag was initiated/moved and suppress the click handler in that case.

## Individual Comments

### Comment 1
<location path="qml/IconItemDelegate.qml" line_range="123" />
<code_context>
+                        drag.threshold: 1
+                        onPressed: function (mouse) {
+                            if (mouse.button === Qt.LeftButton && root.dndEnabled) {
+                                root.Drag.hotSpot = mapToItem(iconLoader, Qt.point(mouse.x, mouse.y))
                                 iconLoader.grabToImage(function(result) {
-                                    dndItem.Drag.imageSource = result.url;
</code_context>
<issue_to_address>
**issue (bug_risk):** Hotspot mapping may use the wrong coordinate space

`Drag.hotSpot` is in `root`'s coordinate space, but `mapToItem(iconLoader, ...)` returns coordinates in `iconLoader` space. Unless these items overlap exactly, the hotspot will be offset from the cursor. Map directly to `root` (e.g., `mapToItem(root, ...)`) to keep the hotspot aligned.
</issue_to_address>

### Comment 2
<location path="qml/FullscreenFrame.qml" line_range="642" />
<code_context>
                                             displayFont: isWindowedMode ? DTK.fontManager.t9 : DTK.fontManager.t6
                                             Drag.mimeData: Helper.generateDragMimeData(model.desktopId)
-                                            visible: dndItem.currentlyDraggedId !== model.desktopId
+                                            opacity: dndItem.currentlyDraggedId !== model.desktopId ? 1 : 0
                                             iconSource: iconName

</code_context>
<issue_to_address>
**suggestion (bug_risk):** Transparent dragged item may still accept input

Using `opacity` instead of `visible` keeps the dragged item interactive even when fully transparent. With a drag proxy above it, pointer events can still reach this delegate, changing behavior from the previous `visible`-based approach. If you want to preserve the old semantics, consider also toggling `visible` or `enabled` so the item ignores input while hidden.
</issue_to_address>

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

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@18202781743
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 19, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 4d671a2 into linuxdeepin:master Mar 19, 2026
10 of 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.

3 participants