Skip to content

fix: fix destroyed callback issues in GestureRecognizer#1013

Merged
zccrs merged 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/gesture-destroyed-callback
Jun 30, 2026
Merged

fix: fix destroyed callback issues in GestureRecognizer#1013
zccrs merged 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/gesture-destroyed-callback

Conversation

@deepin-wm

@deepin-wm deepin-wm commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix multiple issues related to the destroyed signal callback in GestureRecognizer:

  1. Replace destroyed callback with direct list cleanup lambda — Avoid calling unregister on a being-destroyed object which would emit cancelled signal and call deleteLater on it
  2. Remove m_destroyConnections — Qt auto-disconnects destroyed signal connections, so manual management is unnecessary
  3. Fix unregisterHoldGesture to clean m_activeHoldGestures — Now matches swipe behavior: emit cancelled only when gesture was active
  4. Remove deleteLater in HoldGesture destructor — Child objects are auto-destroyed by Qt parent mechanism

Test Plan

  • Test gesture unregister during active gesture recognition
  • Test HoldGesture lifecycle and timer behavior
  • Test SwipeGesture unregister with active gestures

Summary by Sourcery

Resolve lifecycle issues in gesture recognition by simplifying destroyed-signal handling and aligning swipe/hold gesture cleanup and cancellation behavior.

Bug Fixes:

  • Prevent unwanted cancellation and deleteLater calls when gestures are destroyed by directly cleaning internal gesture lists.
  • Ensure hold gestures only emit cancelled when they were active, matching swipe gesture behavior.

Enhancements:

  • Remove obsolete destroyed-connection tracking in GestureRecognizer in favor of relying on Qt's automatic signal disconnection.
  • Stop manually deleting the hold timer in HoldGesture destructor and rely on Qt parent-child object cleanup.

Chores:

  • Update gestures header copyright years to 2024-2026.

@sourcery-ai

sourcery-ai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors GestureRecognizer’s gesture destruction handling to rely on Qt’s automatic signal disconnection, directly clean up gesture lists on QObject destruction, and align swipe/hold unregister behavior while removing an unsafe deleteLater call in HoldGesture.

Sequence diagram for gesture QObject destruction cleanup

sequenceDiagram
    actor QObject
    participant SwipeGesture
    participant HoldGesture
    participant GestureRecognizer

    QObject->>SwipeGesture: destroyed
    SwipeGesture->>GestureRecognizer: destroyed
    GestureRecognizer->>GestureRecognizer: m_swipeGestures.removeOne
    GestureRecognizer->>GestureRecognizer: m_activeSwipeGestures.removeOne

    QObject->>HoldGesture: destroyed
    HoldGesture->>GestureRecognizer: destroyed
    GestureRecognizer->>GestureRecognizer: m_holdGestures.removeOne
    GestureRecognizer->>GestureRecognizer: m_activeHoldGestures.removeOne
Loading

Sequence diagram for explicit HoldGesture unregistration

sequenceDiagram
    participant GestureRecognizer
    participant HoldGesture

    GestureRecognizer->>HoldGesture: unregisterHoldGesture
    GestureRecognizer->>GestureRecognizer: m_holdGestures.removeOne
    alt gesture is active
        GestureRecognizer->>GestureRecognizer: m_activeHoldGestures.removeOne
        GestureRecognizer->>HoldGesture: cancelled
    else gesture is not active
        GestureRecognizer->>GestureRecognizer: m_activeHoldGestures.removeOne
    end
    GestureRecognizer->>HoldGesture: deleteLater
Loading

File-Level Changes

Change Details Files
Simplify swipe gesture destruction handling and avoid emitting cancelled for already-destroyed gestures.
  • Replace destroyed-signal callback for swipe gestures with an inline lambda that directly removes gestures from registered and active lists.
  • Stop tracking destroyed-signal connections in a map when registering swipe gestures.
  • Change unregisterSwipeGesture to only remove a single instance from the registered list and emit cancelled only if the gesture was active.
src/input/gestures.cpp
Align hold gesture destruction and unregistration behavior with swipe gestures and fix lifecycle management.
  • Replace destroyed-signal callback for hold gestures with an inline lambda that directly removes gestures from registered and active lists.
  • Update unregisterHoldGesture to only emit cancelled if the gesture was active, and continue deleting the gesture object via deleteLater.
  • Make HoldGesture destructor stop the timer without calling deleteLater, relying on QObject parent-child ownership for timer cleanup.
src/input/gestures.cpp
Remove obsolete bookkeeping for destroyed-signal connections and update header metadata.
  • Delete the QMap of gesture destroy connections from GestureRecognizer, relying on Qt’s automatic disconnection of destroyed signals.
  • Update the copyright year range in the gestures header.
src/input/gestures.h

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

1. Replace destroyed callback with direct list cleanup lambda to avoid calling unregister on a being-destroyed object which emits cancelled signal and calls deleteLater
2. Remove m_destroyConnections as Qt auto-disconnects destroyed signal
3. Fix unregisterHoldGesture to clean m_activeHoldGestures and emit cancelled only when gesture was active, matching swipe behavior
4. Remove deleteLater in HoldGesture destructor as child objects are auto-destroyed by Qt parent mechanism

Log: Fixed unsafe destroyed callback behavior in gesture recognition

Influence:
1. Test gesture unregister during active gesture recognition
2. Test HoldGesture lifecycle and timer behavior
3. Test SwipeGesture unregister with active gestures

fix: 修复GestureRecognizer中destroyed回调相关问题

1. 将destroyed回调改为直接列表清理lambda,避免在对象销毁过程中调用unregister导致发射cancelled信号和deleteLater
2. 移除m_destroyConnections,Qt会自动断开destroyed信号连接
3. 修复unregisterHoldGesture补充m_activeHoldGestures清理,仅在手势活跃时发射cancelled,与swipe版本对称
4. 移除HoldGesture析构函数中的deleteLater,子对象由Qt父对象机制自动销毁

Log: 修复手势识别中destroyed回调的不安全行为

Influence:
1. 测试手势识别期间的手势注销
2. 测试HoldGesture生命周期和定时器行为
3. 测试活跃状态下SwipeGesture的注销

Fixes: #WM-32
@deepin-wm deepin-wm force-pushed the fix/gesture-destroyed-callback branch from cacfbc3 to 463cc80 Compare June 18, 2026 11:04
@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-bot

deepin-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.8.12
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1036

@deepin-bot

deepin-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.8.13
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1063

@wineee wineee marked this pull request as ready for review June 29, 2026 09:53

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

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.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm, wineee

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

2 similar comments
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm, wineee

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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm, wineee

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

@zccrs zccrs merged commit 0590643 into linuxdeepin:master Jun 30, 2026
9 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.

4 participants