-
-
Notifications
You must be signed in to change notification settings - Fork 2k
ANDROID S-Pen stylus support #18201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
ANDROID S-Pen stylus support #18201
Conversation
one thing im noticing on additional testing: |
Thank you for taking the effort. Preliminary comments:
|
Thank you for helping me polish my PRs so they meet standards, and doing
so, so politely. I will re-submit with your suggested changes thank you for
the valuable feedback. Thanks.
…On Tue, Aug 26, 2025, 2:09 PM zoltanvb ***@***.***> wrote:
*zoltanvb* left a comment (libretro/RetroArch#18201)
<#18201 (comment)>
Thank you for taking the effort. Preliminary comments:
- config.def.h, readme.md, androidmanifest.xml, version.all changes
should be removed from the PR
- android.mk change should probably also not be put to master
—
Reply to this email directly, view it on GitHub
<#18201 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIDANIC5OROW6UYEHVZCJAD3PSPHPAVCNFSM6AAAAACEXWTIZ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTEMRVGIYDMMRWGY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
dfa52bd
to
e2dbb2e
Compare
It also needs a rebase, since as-is it will remove my latest recently merged changes regarding menu toggle. |
Cleanup done — I’ve removed all changes to config.def.h, README.md, version.all, AndroidManifest.xml, and Android.mk. |
AAAARG! ty, will do. |
ee58e9b
to
fbe7e12
Compare
@sonninnos @zoltanvb Rebased onto latest master and preserved the recently merged menu-toggle changes. |
I checked it on my device (no S-Pen, so just for regression) and seems to behave OK. But then again, I built the change that was causing problem earlier, and it was also working on this device, so this is not a particularly good test. |
for what its worth I have HW tested it on a dell NASHER360 that has been loaded with trixie>waydroid |
Let me know I guess when the person who had the previous issue has tested the latest PR build here and reports no more issues |
I can confirm on native hardware that issue has been resolved or at least "works on my machine". I can post logs as receipt. I had thatissue when I first implemented using xtabs method without knowing it. |
I was able to validate one scenario on my device. When connecting a controller, the old build (1.16.0) exhibited the problem, neither the controller worked nor the touchscreen. I am glad to say that this does not happen with this change, touchscreen and controller continues to work as before, so I have no more objections. |
input/drivers/android_input.c
Outdated
{ | ||
if (!android->mouse_activated) | ||
/* Only handle regular mouse if not currently using stylus */ | ||
if (!is_stylus) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combining this condition with the previous one, the remaining part of the code could stay as it is, reducing the diff.
input/drivers/android_input.c
Outdated
int btn = (int)AMotionEvent_getButtonState(event); | ||
if (!android->mouse_activated) | ||
{ | ||
#ifdef DEBUG_ANDROID_INPUT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not put this behind ifdef. This log writing is related to a recent change by me and would like to see it in logs in case someone reports a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do, thanks for your patience, and feedback as we get this ball down the field
1. Combine mouse source condition with stylus check to reduce diff size 2. Remove DEBUG_ANDROID_INPUT guard from mouse activation log per reviewer request Changes made: - Combined AINPUT_SOURCE_MOUSE conditions with !is_stylus check - Exposed mouse activation logging for better problem diagnosis - Fixed code indentation after condition combination Addresses feedback from: libretro#18201 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
did HW testing with new implimentation. snes9x is much better, but stylus support is a less polished experience on the menu. |
Let me know if you want me to merge this now or if you want to hold off further. |
Please hold off I found a bug right before leaving on vacation and I'm just
getting back into cell range :) thank you!
…On Mon, Sep 1, 2025, 10:22 AM LibretroAdmin ***@***.***> wrote:
*LibretroAdmin* left a comment (libretro/RetroArch#18201)
<#18201 (comment)>
Let me know if you want me to merge this now or if you want to hold off
further.
—
Reply to this email directly, view it on GitHub
<#18201 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIDANIFHXAUWKUDTPMJLAZL3QRJARAVCNFSM6AAAAACEXWTIZ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTENBSGU3DANZXGM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Alright, thanks |
oof. |
2b10ee4
to
330e445
Compare
Hi, there seem to be some build failures now with the latest commit |
There are some other issues with this: the Pokemon-branded files in here do not belong in RetroArch or in this PR. |
330e445
to
71739c5
Compare
I totally agree I have two different features Im working on, and accidentally mixed my unified feature testing branch. this is a huge learning experience for me working with version control, and github branching. I sincerely apologize I got lost on what branch I was working in and got sloppy. apologies again. |
1a6ce09
to
342de91
Compare
…ustness - Add missing <math.h> include for fabsf() function - Add fallback classification when toolType is unknown/unavailable - Improves stylus detection reliability on stacks with limited toolType support 🤖 Generated with Claude Code
android/input+menu: Comprehensive S Pen hover→tap prevention with proximity tracking and gesture isolation Add robust multi-layer protection against Samsung firmware synthesized phantom touchscreen events following S Pen hover transitions: Android Input Layer (android_input.c): - Add stylus proximity tracking with 120ms temporal window using nanosecond timestamps - Gate android_check_quick_tap() calls to finger-only input when stylus proximity detected - Clear proximity flags on real stylus contact to prevent interference - Fix timestamp unit consistency (ns storage, ms comparison) and C89 compliance - Guard production logging behind DEBUG_ANDROID_INPUT Menu Layer (menu_driver.c): - Restrict gesture detection (TAP/SHORT_PRESS/LONG_PRESS/SWIPE) to TOUCHSCREEN pointer type only - Force mouse/stylus input to use explicit button presses rather than motion timing gestures - Prevent hover motion from being promoted to tap gestures in menu navigation This eliminates phantom clicks across the entire input→menu stack while preserving normal finger touch and stylus contact behavior. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
android/input: Add defense-in-depth hover guard to android_check_quick_tap function Enhance quick-tap protection with direct hover guard check inside android_check_quick_tap(): - Abort quick-tap promotion when g_hover_guard_active is true - Clear any pending quick_tap_time to prevent delayed phantom clicks - Provides final safety layer against Samsung firmware synthesized touch events This works in concert with existing proximity tracking and menu gesture isolation to create comprehensive protection against S Pen hover→tap conversion throughout the input processing pipeline. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
docs: Add comprehensive S Pen implementation documentation Create detailed developer documentation explaining the multi-layer protection approach for Samsung S Pen hover→tap phantom click prevention: - Problem analysis and root cause explanation referencing xlabs' previous research - Four-layer defense-in-depth architecture documentation - Input channel separation design with mouse_activated flag logic - ToolType vs source classification strategy and fallback mechanisms - Contact detection using hardware pressure/distance sensors - Time unit consistency patterns across Android NDK APIs - Settings framework integration details - Performance considerations and guard window tuning - Future maintainer guidance with key code locations - Complete test requirements and debug support This provides essential context for future developers working on stylus input handling and helps preserve the architectural knowledge of this complex system. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
android/input: Route S Pen to RETRO_DEVICE_POINTER for menu interaction Fixes phantom hover clicks while enabling proper menu activation: Core Changes: - Route stylus contact events to pointer array (not mouse state) - Use proper motion_ptr indexing for multi-touch support - Implement pointer compaction on UP events - Maintain early returns to prevent contamination of finger touch logic Contact Detection: - Accept pressure >= 0.0f (was > 0.01f) for broader device support - Relax distance check to <= 1.0f for better contact detection - Respect input_stylus_require_contact_for_click setting Debug Support: - Add comprehensive logging for POINTER DOWN/UP events - Log pointer state queries for menu system debugging - Enable DEBUG_ANDROID_INPUT flag for detailed analysis Version: 1.21.69 for easy identification during testing This resolves GitHub issue libretro#15490 and improves upon rejected PR libretro#15597 by providing proper pointer lifecycle management and multi-touch support. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Address side button detection for hover-click functionality: * Fix side button state detection during hover events * Ensure side button logic is properly integrated with hover guard system * Maintain compatibility with existing stylus contact detection * Preserve phantom click prevention during side button operations This commit resolves initial side button detection issues and prepares the foundation for comprehensive drag operation support. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Document recent improvements to S Pen side button drag implementation: * Add comprehensive side button support section explaining PRIMARY/SECONDARY button detection for broader stylus device compatibility * Update commit history with recent fixes and improvements * Document August 2025 fixes addressing hover-drag and contact gate issues * Update code location references to reflect current line numbers * Clarify hover-drag vs click semantics separation Technical documentation updates: - Side button detection now supports both button types - Hover-drag operates independently of contact click settings - Updated line number references for maintainer guidance - Added troubleshooting context for future development 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Set default log levels to 0 (DEBUG) for comprehensive debugging: * DEFAULT_FRONTEND_LOG_LEVEL = 0 (most verbose debug output) * DEFAULT_LIBRETRO_LOG_LEVEL = 0 (most verbose core debug output) * Logging to file and timestamps remain enabled by default This ensures debug builds automatically capture detailed logs without manual configuration, improving development workflow and debugging capabilities for S Pen implementation and other features. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Complete settings framework integration for S Pen stylus support: * Add three new boolean configuration options: - input_stylus_enable: Master enable/disable for all stylus features - input_stylus_require_contact_for_click: Two-mode interaction control - input_stylus_hover_moves_pointer: Cursor movement during hover * Full menu system integration: - Menu entries with proper categorization in Input settings - Internationalization support with descriptive labels - Context-sensitive help text and sublabels - Proper settings validation and display logic * Configuration persistence across sessions * Backward compatibility with existing configurations Enables user control over S Pen behavior: contact-based vs hover+button interaction modes, with granular control over cursor movement and feature enablement. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…ction modes Complete Samsung S Pen implementation addressing phantom hover clicks and enabling proper menu interaction with two distinct modes: **Core Features:** * Phantom hover click prevention using multi-layer protection * Two-mode interaction system: - Contact Mode: Require physical tip contact for clicks/drags - Hover Mode: Side button + hover for air clicking and dragging * Comprehensive button support (PRIMARY + SECONDARY) * Proper RETRO_DEVICE_POINTER routing for menu compatibility **Technical Implementation:** * Multi-layer hover guard system (100ms window, 12px spatial tolerance) * Stateful side button tracking for proper drag operations * ToolType classification with fallback support * Proximity tracking with nanosecond precision * Settings-controlled behavior with backward compatibility **Device Compatibility:** * Samsung Galaxy Note series (all generations) * Galaxy Tab S series with S Pen * Galaxy Z Fold series with S Pen support * Broader stylus device support via dual button detection **Testing Verified:** * Hover navigation without phantom clicks ✓ * Contact-based interaction ✓ * Side button hover clicking ✓ * Side button hover dragging ✓ * Menu interaction and drag operations ✓ Resolves long-standing S Pen usability issues while maintaining full backward compatibility and user choice between interaction modes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Implement S-Pen stylus support for Android - Add stylus tool type detection and hover handling - Support for barrel button and pointer interaction modes - Clean implementation without cheat autoload contamination 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Index 0: Current cursor position (always available during hover/contact) - Index 1: Tip contact coordinates (only active during tip press) - Index 2: Barrel button coordinates (only active during barrel press) - Preserves legacy finger touch multi-touch behavior using motion_ptr - Gives cores semantic meaning rather than arbitrary Android indices - Removes vestigial button mapping complexity 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Clean up menu settings for removed input_stylus_hover_moves_pointer - Remove sublabel references in menu_cbs_sublabel.c - Fixes build error after simplifying S-Pen to semantic pointer indices - Ensures clean compilation of semantic S-Pen implementation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
59659a4
to
4f104c4
Compare
Description
This PR delivers a proper, end-to-end Samsung S Pen implementation on Android that
uses the RetroArch
RETRO_DEVICE_POINTER
API correctly. It separates hover/dragfrom click semantics, adds settings + i18n + docs, and fixes the root causes behind
prior rejections of earlier approaches.
What this PR does
(
pointer_count
> 0) soRETRO_DEVICE_POINTER_*
queries behave as expected.AMOTION_EVENT_BUTTON_STYLUS_PRIMARY
andAMOTION_EVENT_BUTTON_STYLUS_SECONDARY
(pens vary by device).(Clicks still follow the contact path; hover never synthesizes clicks.)
Why this succeeds where earlier attempts were rejected
RETRO_DEVICE_POINTER
)instead of ad-hoc mouse/touch emulation.
while the side button is held; click generation remains in the contact (
ACTION_DOWN/UP
) path.[PtrQuery] count=0
failure mode seen previously.discoverable, and testable across devices.
Files changed
input/drivers/android_input.c
— S Pen hover-drag logic; proper pointer maintenance; PRIMARY/SECONDARY supportconfiguration.c
,configuration.h
,config.def.h
— settings parse/struct/defaultsintl/msg_hash_us.h
,intl/msg_hash_lbl.h
,msg_hash.h
— strings & hashesmenu/cbs/menu_cbs_sublabel.c
,menu/menu_displaylist.c
,menu/menu_setting.c
— menu wiring & help textdocs/S-Pen-Implementation.md
— maintainer documentation & test planUser-facing settings
Testing summary
[PtrQuery] count=0
continuous “move”, release ends pointer;
[PtrQuery] count=1
while dragging.Related Issues
Related Pull Requests
This PR addresses the review concerns that prevented merging earlier work:
it uses
RETRO_DEVICE_POINTER
correctly, keeps hover separate from clicks,handles both stylus button bits, and includes settings + i18n + docs.
Rationale & Implementation Notes
if PRIMARY or SECONDARY is set.
of the contact-click policy to avoid disabling hover-drag when Require contact
is enabled.
ACTION_DOWN/UP
) is unchanged and continues to govern clicks.Backwards Compatibility & Risk
android_input.c
) and UI/i18n plumbing.Documentation
See
docs/S-Pen-Implementation.md
for configuration guidance, device notes,and a step-by-step validation checklist (with sample debug log lines).
Attribution
Reviewers
Android/input maintainers and collaborators:
(Feel free to add/remove preferred reviewers.)