Skip to content

Fix touchpad right-click#1071

Open
Nightwalker743 wants to merge 2 commits intoutkarshdalal:masterfrom
Nightwalker743:fix/touchpad-right-click
Open

Fix touchpad right-click#1071
Nightwalker743 wants to merge 2 commits intoutkarshdalal:masterfrom
Nightwalker743:fix/touchpad-right-click

Conversation

@Nightwalker743
Copy link
Copy Markdown
Contributor

@Nightwalker743 Nightwalker743 commented Apr 2, 2026

Description

This is a fix for the issue reported in the Discord here: https://discord.com/channels/1378308569287622737/1488785598658510909

Right now, using the default trackpad, right clicks often don't trigger from two-finger taps. This fixes that and also makes two finger taps work as right click unless if a right click button is created from the control editor (just like how left click works right now).

Recording

Screen_Recording_20260402_000551_GameNative.mp4

Checklist

  • If I have access to #code-changes, I have discussed this change there and it has been green-lighted. If I do not have access, I have still provided clear context in this PR. If I skip both, I accept that this change may face delays in review, may not be reviewed at all, or may be closed.
  • I have attached a recording of the change.
  • I have read and agree to the contribution guidelines in CONTRIBUTING.md.

Summary by cubic

Fixes unreliable touchpad right-clicks. Two-finger taps now register as right-click without stray left-clicks, and repeated clicks always register. Two-finger right-click stays enabled unless a profile defines a right-click button.

  • Bug Fixes
    • com.winlator.widget.TouchpadView: Added suppress flags to block a left-tap after a two-finger right-click in both pointer and touchscreen paths; reset on ACTION_DOWN.
    • com.winlator.widget.TouchpadView: Force-release before pressing left/right buttons to clear stale state; safer delayed releases with early guards and finger-capture checks.
    • app.gamenative.ui/screen/xserver/XServerScreen: Removed blanket disable of right-click.
    • com.winlator.widget.InputControlsView: Enable both pointer buttons on touch down; disable left/right only when a control binds MOUSE_LEFT_BUTTON or MOUSE_RIGHT_BUTTON.

Written for commit bd27d50. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Improved touchpad responsiveness to reduce accidental left/right pointer presses.
    • Suppressed unintended consecutive clicks after multi-finger gestures to avoid duplicate inputs.
    • tightened touch-down handling so pointer buttons enable/disable more reliably during complex touch sequences.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6831bae5-6d98-43b9-8c67-d1db0fbdd5fe

📥 Commits

Reviewing files that changed from the base of the PR and between d3688aa and bd27d50.

📒 Files selected for processing (1)
  • app/src/main/java/com/winlator/widget/TouchpadView.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/src/main/java/com/winlator/widget/TouchpadView.java

📝 Walkthrough

Walkthrough

Removed explicit right-button disable from XServerScreen; InputControlsView now enables both pointer buttons on touch-down and conditionally disables them per binding. TouchpadView adds suppression for a left-click after a two-finger right-click, prevents duplicate two-finger tap handling, and tightens press/release guards tied to finger identity and enabled state.

Changes

Cohort / File(s) Summary
Pointer button routing
app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt, app/src/main/java/com/winlator/widget/InputControlsView.java
Removed the explicit right-button-disable call from XServerScreen; InputControlsView now enables both pointer buttons on touch-down (setPointerButtonLeftEnabled(true), setPointerButtonRightEnabled(true)) and disables the corresponding button when a control element binding maps to MOUSE_LEFT_BUTTON or MOUSE_RIGHT_BUTTON.
Touchpad tap & button state
app/src/main/java/com/winlator/widget/TouchpadView.java
Added suppressNextLeftTap and twoFingerTapFired to prevent immediate/duplicate left-clicks after two-finger right-clicks; on press, release-before-repress if already pressed; release paths now check view/feature enabled and matching finger identity and avoid spurious releases in non-relative mode.

Sequence Diagram(s)

sequenceDiagram
    participant User as User (touch)
    participant Input as InputControlsView
    participant Touch as TouchpadView
    participant XSrv as XServerScreen

    User->>Input: touch down / pointer events
    Note over Input: enables both pointer buttons\nthen inspects ControlElement bindings
    Input-->>Touch: forward touch stream (with button-enable state)
    alt binding includes MOUSE_RIGHT_BUTTON
        Input->>Touch: disable right button for this element
    end
    Touch->>Touch: handle taps\n(two-finger detection sets twoFingerTapFired,\nsuppressNextLeftTap flagged)
    Touch->>XSrv: inject pointer press/release events (respecting guards)
    XSrv-->>Touch: acknowledge/input consumed
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Poem

🐰 Two-paw tap for a right-click cheer,
I hush the left so it won't appear.
A gentle flag, a careful cue,
presses match fingers — tidy and true.
Hooray — hops and clicks now steer.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing touchpad right-click functionality, which is the central objective of this PR.
Description check ✅ Passed The description is comprehensive, addressing the problem, providing a Discord reference, explaining the fix behavior, attaching a recording, completing the checklist, and including an auto-generated summary.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-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.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="app/src/main/java/com/winlator/widget/TouchpadView.java">

<violation number="1" location="app/src/main/java/com/winlator/widget/TouchpadView.java:1074">
P2: Forced release-before-press can break legitimate existing held-button state and interrupt ongoing drag/selection interactions.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/src/main/java/com/winlator/widget/TouchpadView.java`:
- Around line 1099-1115: The delayed release Runnables in
releasePointerButtonLeft (and similarly releasePointerButtonRight) currently
close over mutable field fingerPointerButtonLeft/fingerPointerButtonRight so a
later reassignment can be cancelled by an earlier runnable; fix by capturing a
local stable token (e.g., final Finger capturedFinger =
this.fingerPointerButtonLeft or an incrementing pressId capturedPressId) inside
the method and then inside the postDelayed Runnable check that the current field
still equals capturedFinger (or that currentPressId == capturedPressId) before
performing the release and clearing the field; bail out from the Runnable if the
token does not match.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c73821ae-f178-449f-ba42-2a0d5d2506c2

📥 Commits

Reviewing files that changed from the base of the PR and between aa412fc and 976c66f.

📒 Files selected for processing (3)
  • app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt
  • app/src/main/java/com/winlator/widget/InputControlsView.java
  • app/src/main/java/com/winlator/widget/TouchpadView.java
💤 Files with no reviewable changes (1)
  • app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt

…ns, enable dynamic right-click control

Three related issues fixed:

1. Two-finger right-click tap fires a spurious left-click when the second
   finger lifts (numFingers drops to 1, case 1 fires). Added
   suppressNextLeftTap flag: set on right-click (case 2), checked and
   cleared on left-tap (case 1). Reset on ACTION_DOWN to prevent stale
   state after ACTION_CANCEL.

2. Repeated right-clicks silently fail. pressPointerButtonLeft/Right
   guarded with !isButtonPressed() which drops the press if the button
   state is stale (Pointer.buttonMask is a plain int read from UI thread
   without XLock). Changed to force-release any stuck button before
   pressing, so clicks always go through.
   Release functions simplified with early-return guard; isButtonPressed
   check moved inside the delayed runnable as a safety net.

3. showInputControls() unconditionally called
   setPointerButtonRightEnabled(false), killing two-finger right-click
   even on gamepad presets with no MOUSE_RIGHT_BUTTON binding. Removed
   the blanket disable. InputControlsView now dynamically checks for
   MOUSE_RIGHT_BUTTON bindings on ACTION_DOWN (mirroring the existing
   MOUSE_LEFT_BUTTON pattern) and only disables right-click when a
   dedicated button element exists in the profile.
@Nightwalker743 Nightwalker743 force-pushed the fix/touchpad-right-click branch from 976c66f to d3688aa Compare April 2, 2026 05:32
Two-finger tap fired right-click in handleTsPointerUp(), then
handleTsUp() also fired a left-click because the finger hadn't
moved beyond tap threshold. Added twoFingerTapFired flag to
suppress the spurious left-click, matching the existing
doubleTapDetected pattern.
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.

1 participant