Skip to content

[Fix] input handling, scrolling, and gesture state#366

Merged
imxade merged 3 commits into
AOSSIE-Org:mainfrom
PinJinx:InputInjectionBugFixes
Jul 15, 2026
Merged

[Fix] input handling, scrolling, and gesture state#366
imxade merged 3 commits into
AOSSIE-Org:mainfrom
PinJinx:InputInjectionBugFixes

Conversation

@PinJinx

@PinJinx PinJinx commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Addressed Issues:

N/A

Description

This PR improves the input system by fixing several gesture and keyboard-related issues across all supported platforms.

Changes

  • Added proper onTouchCancel handling to prevent gestures from getting stuck when touch events are interrupted.
  • Added support for HOLD and RELEASE key injection across Linux, macOS, and Windows.
  • Fixed Ctrl + Mouse Wheel zoom by correctly holding and releasing the Ctrl key.
  • Fixed invert scrolling behavior for both vertical and horizontal scrolling on all platforms.
  • Applied pending sensitivity and invert scroll settings immediately during WebRTC input session initialization.
  • Added media key support (Play/Pause, Next, Previous, Volume Up/Down, Mute) across all supported platforms.
  • Added native macOS media transport key support using NX_SYSDEFINED events.
  • Improved gesture state cleanup and drag timeout cleanup.
  • Updated platform injectors to support held modifier keys.

Screenshots/Recordings:

N/A

Functional Verification

Screen Mirror

  • Screen Mirror works.

Authentication

  • Connection doesn't work without a valid token.

Basic Gestures

  • One-finger tap: Verified as Left Click.

  • Two-finger tap: Verified as Right Click.

  • Click and drag: Verified selection behavior.

  • Pinch to zoom: Verified zoom functionality.

Modes & Settings

  • Cursor mode: Cursor moves smoothly and accurately.

  • Scroll mode: Page scrolls as expected.

  • Sensitivity: Verified changes in cursor speed/sensitivity settings.

  • Copy and Paste: Verified both Copy and Paste functionality.

  • Invert Scrolling: Verified scroll direction toggles correctly.

Advanced Input

  • Key combinations: Verified HOLD/RELEASE behavior for modifiers (e.g. Ctrl+C, Ctrl+Scroll Zoom).

  • Keyboard input: Verified Space, Backspace, and Enter keys work correctly.

  • Glide typing: Verified path drawing and text output.

  • Voice input: Verified speech-to-text functionality.

  • Backspace doesn't send the previous input.

Any other gesture or input behavior introduced:

  • New Gestures: Verified touch cancellation cleanup, media keys, and proper modifier key state handling.

Additional Notes:

This PR mainly focuses on improving input reliability and platform consistency by fixing gesture cleanup, modifier key handling, scrolling behavior, and media key support across Linux, macOS, and Windows.

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.

  • My code follows the project's code style and conventions.

  • I have performed a self-review of my own code.

  • I have commented my code, particularly in hard-to-understand areas.

  • If applicable, I have made corresponding changes or additions to the documentation.

  • If applicable, I have made corresponding changes or additions to tests.

  • My changes generate no new warnings or errors.

  • I have joined the Discord server and I will share a link to this PR with the project maintainers there.

  • I have read the contribution guidelines.

  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.

  • In case of UI change I've added a demo video.

Summary by CodeRabbit

  • New Features
    • Added support for media controls, including volume, mute, play/pause, next, previous, and stop across platforms.
    • Improved keyboard input handling for held and released keys.
  • Bug Fixes
    • Fixed gesture cancellation so interrupted touch gestures reset cleanly.
    • Corrected horizontal and vertical scroll inversion behavior.
    • Updated zoom input handling for more reliable control-key behavior.
    • Applied unsaved sensitivity and scroll settings immediately to new connections.

@PinJinx
PinJinx requested a review from imxade July 14, 2026 15:07
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds touch-cancel gesture cleanup, pending input configuration application, positional keyboard injection, media-key mappings, consistent scroll inversion, macOS media events, and GStreamer development-shell configuration.

Changes

Input handling

Layer / File(s) Summary
Trackpad cancellation cleanup
src/components/Trackpad/TouchArea.tsx, src/hooks/useTrackpadGesture.ts
Propagates touch-cancel events and clears gesture, pinch, drag, and timeout state when touches are cancelled.
Input configuration and injection contracts
src/server/api/apiHandlers.ts, src/server/types.ts, src/server/InputHandler.ts
Applies pending configuration to new input sessions and uses explicit control-key hold/release events for zoom.
Platform injection
src/server/drivers/*
Adds positional keyboard events, media-key support, macOS media events, and consistent scroll inversion across platforms.

Development shell multimedia setup

Layer / File(s) Summary
GStreamer development-shell wiring
shell.nix
Adds multimedia libraries and exports the GStreamer plugin search path.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant InputHandler
  participant PlatformInjector
  participant KeyboardBackend
  InputHandler->>PlatformInjector: Hold control key
  PlatformInjector->>KeyboardBackend: injectKey("control", "HOLD")
  InputHandler->>PlatformInjector: Inject zoom wheel
  InputHandler->>PlatformInjector: Release control key
  PlatformInjector->>KeyboardBackend: injectKey("control", "RELEASE")
Loading

Possibly related PRs

Suggested labels: Typescript Lang

Suggested reviewers: imxade

Poem

I’m a rabbit with paws on the trackpad tonight,
Cancelling touches and making states right.
Keys hold, keys release, media tunes play,
Scrolls turn smoothly along their way.
GStreamer plugins hop into the shell—
Input magic works quite well! 🐇

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change set around input handling, scrolling, and gesture state.
Description check ✅ Passed The description follows the template and covers issues, summary, verification, notes, and checklist, with only the issue reference left as N/A.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/Trackpad/TouchArea.tsx`:
- Line 10: Add the Next.js "use client" directive at the top of the TouchArea
component file so its touch and mouse event handlers run as a client component.

In `@src/server/InputHandler.ts`:
- Around line 202-205: Update the control-key and mouse-wheel injection flow
around this.injector.injectMouseWheel so the wheel call executes inside a
try...finally block, with this.injector.injectKey("control", "RELEASE") in the
finally clause to guarantee release when injection fails.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0be28747-297e-499c-a0b9-ba34e1af81da

📥 Commits

Reviewing files that changed from the base of the PR and between 0a1455f and d5d9e8d.

📒 Files selected for processing (14)
  • shell.nix
  • src/components/Trackpad/TouchArea.tsx
  • src/hooks/useTrackpadGesture.ts
  • src/server/InputHandler.ts
  • src/server/api/apiHandlers.ts
  • src/server/drivers/keyMap.ts
  • src/server/drivers/linux/index.ts
  • src/server/drivers/linux/keyboard.ts
  • src/server/drivers/mac/index.ts
  • src/server/drivers/mac/keyboard.ts
  • src/server/drivers/mac/structs.ts
  • src/server/drivers/windows/index.ts
  • src/server/drivers/windows/keyboard.ts
  • src/server/types.ts

onTouchStart: (e: React.TouchEvent) => void
onTouchMove: (e: React.TouchEvent) => void
onTouchEnd: (e: React.TouchEvent) => void
onTouchCancel: (e: React.TouchEvent) => void

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify if "use client" is present at the top of the file.
head -n 5 src/components/Trackpad/TouchArea.tsx | grep -q 'use client' || echo "Missing 'use client' directive in src/components/Trackpad/TouchArea.tsx."

Repository: AOSSIE-Org/Rein

Length of output: 226


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '1,40p' src/components/Trackpad/TouchArea.tsx

Repository: AOSSIE-Org/Rein

Length of output: 1265


Add "use client" to src/components/Trackpad/TouchArea.tsx. This component uses touch and mouse event handlers, so it must be a client component in Next.js.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/Trackpad/TouchArea.tsx` at line 10, Add the Next.js "use
client" directive at the top of the TouchArea component file so its touch and
mouse event handlers run as a client component.

Source: Path instructions

Comment on lines +202 to 205
this.injector.injectKey("control", "HOLD")
this.injector.injectMouseWheel(0, amount)
this.injector.injectKey("control")
this.injector.injectKey("control", "RELEASE")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Ensure the modifier key is released if an error occurs.

If this.injector.injectMouseWheel throws an error, the execution will abort, leaving the "control" key logically stuck in the down position. Wrap the wheel injection in a try...finally block to guarantee the release event is dispatched.

🔒️ Proposed fix to prevent stuck keys
-					this.injector.injectKey("control", "HOLD")
-					this.injector.injectMouseWheel(0, amount)
-					this.injector.injectKey("control", "RELEASE")
+					this.injector.injectKey("control", "HOLD")
+					try {
+						this.injector.injectMouseWheel(0, amount)
+					} finally {
+						this.injector.injectKey("control", "RELEASE")
+					}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.injector.injectKey("control", "HOLD")
this.injector.injectMouseWheel(0, amount)
this.injector.injectKey("control")
this.injector.injectKey("control", "RELEASE")
}
this.injector.injectKey("control", "HOLD")
try {
this.injector.injectMouseWheel(0, amount)
} finally {
this.injector.injectKey("control", "RELEASE")
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/server/InputHandler.ts` around lines 202 - 205, Update the control-key
and mouse-wheel injection flow around this.injector.injectMouseWheel so the
wheel call executes inside a try...finally block, with
this.injector.injectKey("control", "RELEASE") in the finally clause to guarantee
release when injection fails.

@imxade
imxade merged commit 7337789 into AOSSIE-Org:main Jul 15, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants