Skip to content

fix: fix destroyed callback issues in GestureRecognizer#1013

Draft
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/gesture-destroyed-callback
Draft

fix: fix destroyed callback issues in GestureRecognizer#1013
deepin-wm wants to merge 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 with gesture objects by simplifying destroyed-signal handling and aligning unregister behavior for swipe and hold gestures.

Bug Fixes:

  • Ensure swipe and hold gestures are removed from active and registered lists when their QObject is destroyed without emitting spurious cancelled signals.
  • Make hold gesture unregistration emit the cancelled signal only when the gesture was actually active, matching swipe behavior.
  • Avoid double-deletion patterns by removing explicit deleteLater calls for child timers managed by Qt's parent–child ownership.

Enhancements:

  • Remove redundant bookkeeping of destroyed-signal connections in GestureRecognizer, relying on Qt's automatic disconnection instead.

@sourcery-ai

sourcery-ai Bot commented Jun 18, 2026

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

Reviewer's Guide

Adjusts GestureRecognizer’s lifecycle handling by replacing destroyed-signal-based unregister calls with direct list cleanup lambdas, simplifying connection management, aligning hold-gesture cancellation semantics with swipe, and relying on Qt’s parent/child destruction instead of manual deleteLater.

Sequence diagram for gesture destruction cleanup in GestureRecognizer

sequenceDiagram
    participant SwipeGesture
    participant GestureRecognizer

    SwipeGesture ->> GestureRecognizer: destroyed
    GestureRecognizer ->> GestureRecognizer: m_swipeGestures.removeOne(gesture)
    GestureRecognizer ->> GestureRecognizer: m_activeSwipeGestures.removeOne(gesture)
Loading

Sequence diagram for unregisterHoldGesture behavior in GestureRecognizer

sequenceDiagram
    participant Client
    participant GestureRecognizer
    participant HoldGesture

    Client ->> GestureRecognizer: unregisterHoldGesture(gesture)
    GestureRecognizer ->> GestureRecognizer: m_holdGestures.removeOne(gesture)
    GestureRecognizer ->> GestureRecognizer: m_activeHoldGestures.removeOne(gesture)
    alt gesture_was_active
        GestureRecognizer ->> HoldGesture: cancelled
    end
    GestureRecognizer ->> HoldGesture: deleteLater()
Loading

File-Level Changes

Change Details Files
Replace destroyed-signal unregister callbacks with direct in-place list cleanup for swipe and hold gestures.
  • Connect gesture destroyed signal to lambdas that remove the gesture from registered and active lists instead of calling unregister methods.
  • Use removeOne for list cleanup to avoid unnecessary multi-removals and side effects during object destruction.
  • Ensure that destruction no longer triggers gesture cancellation or deleteLater via unregister during QObject teardown.
src/input/gestures.cpp
Simplify GestureRecognizer resource management by removing explicit destroyed-signal connection tracking.
  • Remove the m_destroyConnections map from GestureRecognizer.
  • Eliminate connection bookkeeping and disconnect logic in unregisterSwipeGesture and unregisterHoldGesture, relying on Qt’s auto-disconnect on object destruction.
src/input/gestures.cpp
src/input/gestures.h
Align HoldGesture lifecycle and cancellation behavior with SwipeGesture and Qt’s parent-child ownership model.
  • Change unregisterHoldGesture to cancel only when the gesture was active by checking and removing it from m_activeHoldGestures instead of m_holdGestures.
  • Maintain m_holdGestures via simple removal without affecting cancellation semantics.
  • Remove deleteLater on m_holdTimer in HoldGesture destructor, relying on Qt parent-based cleanup instead.
src/input/gestures.cpp

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-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

1 similar comment
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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.

2 participants