Skip to content

fix: prevent touchscreen right-click context menu#1539

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

fix: prevent touchscreen right-click context menu#1539
qxp930712 wants to merge 1 commit intolinuxdeepin:masterfrom
qxp930712:master

Conversation

@qxp930712
Copy link
Copy Markdown

@qxp930712 qxp930712 commented Mar 30, 2026

Modified notification view delegate to check for touchscreen device type before showing context menu on right-click. Added PointerDevice.TouchScreen type check to both TapHandler instances in the DelegateChooser.

The previous implementation would trigger context menu on right-click gestures from touchscreen devices, which was unintended behavior. Touchscreen right-clicks are typically long-press gestures that should not open the same context menu as mouse right-clicks. This change ensures context menus only appear when using mouse input devices.

Influence:

  1. Test right-click with mouse on notification items - context menu should appear
  2. Test long-press/touch gestures on touchscreen devices - context menu should not appear
  3. Verify regular left-click functionality remains unchanged
  4. Test touchscreen interactions with other gestures to ensure no regression

PMS: BUG-355017

Summary by Sourcery

Bug Fixes:

  • Stop touchscreen long-press gestures from incorrectly triggering the notification item context menu.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: qxp930712

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

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 30, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR restricts notification context menu activation to mouse right-clicks by updating TapHandler conditions to ignore right-click-style presses originating from touchscreen devices, preventing unintended context menus on touch long-press gestures.

Sequence diagram for notification context menu activation with pointer device filtering

sequenceDiagram
    actor User
    participant MouseDevice
    participant TouchDevice
    participant NotifyViewDelegate
    participant TapHandlerRightClick
    participant ContextMenu

    rect rgb(230,230,250)
        User->>MouseDevice: right_click
        MouseDevice->>TapHandlerRightClick: press event
        TapHandlerRightClick->>TapHandlerRightClick: onPressedChanged
        Note over TapHandlerRightClick: pressed && point.device.type != PointerDevice.TouchScreen
        TapHandlerRightClick->>NotifyViewDelegate: setting(point.position)
        NotifyViewDelegate->>ContextMenu: open at position
    end

    rect rgb(250,230,230)
        User->>TouchDevice: long_press
        TouchDevice->>TapHandlerRightClick: press event
        TapHandlerRightClick->>TapHandlerRightClick: onPressedChanged
        Note over TapHandlerRightClick: pressed && point.device.type == PointerDevice.TouchScreen
        TapHandlerRightClick--xContextMenu: do not open
    end
Loading

Flow diagram for TapHandler onPressedChanged context menu condition

flowchart TD
    A[onPressedChanged triggered] --> B{pressed}
    B -->|false| Z[Exit without action]
    B -->|true| C{point.device.type != PointerDevice.TouchScreen}
    C -->|false| Z
    C -->|true| D[Read pos = point.position]
    D --> E[Call setting with pos]
    E --> F[Context menu opens at pos]
Loading

File-Level Changes

Change Details Files
Gate context menu activation so it only runs for right-clicks from non-touchscreen pointing devices.
  • Updated both TapHandler instances handling Qt.RightButton to additionally check point.device.type is not PointerDevice.TouchScreen before invoking the context menu logic
  • Ensured long-press/right-click gestures from touchscreens no longer trigger the notification context menu while preserving behavior for mouse right-clicks
panels/notification/center/NotifyViewDelegate.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
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.

Hey - I've found 1 issue, and left some high level feedback:

  • The onPressedChanged guards assume point.device is always defined; consider defensively checking point.device && point.device.type !== PointerDevice.TouchScreen (or equivalent) to avoid runtime errors in edge cases where no device is associated.
  • The two TapHandler blocks now contain identical logic for filtering out touchscreen right-clicks; consider extracting the shared behavior into a helper or common component to avoid duplication and keep future behavior changes in one place.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `onPressedChanged` guards assume `point.device` is always defined; consider defensively checking `point.device && point.device.type !== PointerDevice.TouchScreen` (or equivalent) to avoid runtime errors in edge cases where no device is associated.
- The two `TapHandler` blocks now contain identical logic for filtering out touchscreen right-clicks; consider extracting the shared behavior into a helper or common component to avoid duplication and keep future behavior changes in one place.

## Individual Comments

### Comment 1
<location path="panels/notification/center/NotifyViewDelegate.qml" line_range="118" />
<code_context>
                 acceptedButtons: Qt.RightButton
                 onPressedChanged: function () {
-                    if (pressed) {
+                    if (pressed && point.device.type !== PointerDevice.TouchScreen) {
                         let pos = point.position
                         setting(pos)
</code_context>
<issue_to_address>
**suggestion:** Use TapHandler's acceptedDevices instead of checking device type inside the handler.

Rather than checking `point.device.type !== PointerDevice.TouchScreen` in `onPressedChanged`, configure the appropriate `acceptedDevices` (e.g. `PointerDevice.Mouse`) on `TapHandler`. This keeps the handler focused on the press logic and centralizes device filtering in the declarative properties, avoiding duplicated conditions.

Suggested implementation:

```
            TapHandler {
                acceptedButtons: Qt.RightButton
                acceptedDevices: PointerDevice.Mouse
                onPressedChanged: function () {
                    if (pressed) {
                        let pos = point.position
                        setting(pos)
                    }

```

```
            TapHandler {
                acceptedButtons: Qt.RightButton
                acceptedDevices: PointerDevice.Mouse
                onPressedChanged: function () {
                    if (pressed) {
                        let pos = point.position
                        setting(pos)
                    }

```
</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.

acceptedButtons: Qt.RightButton
onPressedChanged: function () {
if (pressed) {
if (pressed && point.device.type !== PointerDevice.TouchScreen) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use TapHandler's acceptedDevices instead of checking device type inside the handler.

Rather than checking point.device.type !== PointerDevice.TouchScreen in onPressedChanged, configure the appropriate acceptedDevices (e.g. PointerDevice.Mouse) on TapHandler. This keeps the handler focused on the press logic and centralizes device filtering in the declarative properties, avoiding duplicated conditions.

Suggested implementation:

            TapHandler {
                acceptedButtons: Qt.RightButton
                acceptedDevices: PointerDevice.Mouse
                onPressedChanged: function () {
                    if (pressed) {
                        let pos = point.position
                        setting(pos)
                    }

            TapHandler {
                acceptedButtons: Qt.RightButton
                acceptedDevices: PointerDevice.Mouse
                onPressedChanged: function () {
                    if (pressed) {
                        let pos = point.position
                        setting(pos)
                    }

Modified notification view delegate to check for touchscreen
device type before showing context menu on right-click. Added
PointerDevice.TouchScreen type check to both TapHandler instances in
the DelegateChooser.

The previous implementation would trigger context menu on right-click
gestures from touchscreen devices, which was unintended behavior.
Touchscreen right-clicks are typically long-press gestures that should
not open the same context menu as mouse right-clicks. This change
ensures context menus only appear when using mouse input devices.

Influence:
1. Test right-click with mouse on notification items - context menu
should appear
2. Test long-press/touch gestures on touchscreen devices - context menu
should not appear
3. Verify regular left-click functionality remains unchanged
4. Test touchscreen interactions with other gestures to ensure no
regression

PMS: BUG-355017
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