Add native touch support on Windows with multi-touch and pen input - #3218
Open
Ahmed Ali (thisAAY) wants to merge 2 commits into
Open
Ahmed Ali (thisAAY) wants to merge 2 commits into
Ahmed Ali (thisAAY) wants to merge 2 commits into
Conversation
Windows synthesizes mouse events for touch input, so touch screens are handled as a mouse with a single pointer. Handle WM_POINTER messages before the mouse event synthesis happens and send the received touch and pen pointers to ComposeScene, enabling multi-touch gestures and pen pressure. The feature is opt-in via the compose.windows.nativeTouch system property.
Visualizes the active pointers to test multi-touch input on touch screen devices.
Vladimir Mazunin (mazunin-v-jb)
requested review from
Ivan Matkov (MatkovIvan),
Igor Demin (igordmn) and
Alexander Maryanovsky (m-sasha)
and removed request for
Ivan Matkov (MatkovIvan)
July 13, 2026 12:12
Author
|
Any updates on this? |
|
Ahmed Ali (@thisAAY), thank you for your PR. We are currently investigating how we can provide long-term support for this. When we know the answer, we'll return to your PR. |
|
Also hoping for better touch screen support on desktop Windows and Linux. Hopefully this gets resolved soon. Igor Demin (@igordmn) Any time frame? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Compose for Desktop has no native touch support on Windows. AWT doesn't handle touch, and Windows synthesizes mouse events for it, so a touch screen is treated as a mouse with a single pointer: every finger becomes
PointerType.Mouse, only one contact is tracked, there is no touch slop, no multi-touch gestures like pinch-to-zoom, and drag-to-scroll is unreliable. Pens lose their type, pressure and eraser state the same way.This PR adds a full native touch input pipeline for Windows rather than patching the symptoms:
PointerType.Touch, pens asPointerType.Stylus, and an inverted pen or pressed eraser button asPointerType.EraserComposeScenePointer.pressureFixes CMP-1609
Relates to CMP-2209, CMP-6429, CMP-9125, CMP-5945
Changes
WindowsTouchBridgethat subclasses the window procedure and handlesWM_POINTERmessages before the mouse event synthesis happens. The pointer input API (Windows 8+) is used instead of the legacyWM_TOUCH, which is emulated on top of it and requires a thread-affine registration call.ComposeSceneMediatorkeeps track of the active contacts and sends each event toComposeScenewith the complete list of pressed pointers, which is what makes multi-finger gestures work.PT_TOUCHtoTouch,PT_PENtoStyluswith the pressure fromGetPointerPenInfo, andPEN_FLAG_INVERTED/PEN_FLAG_ERASERtoEraser.WM_POINTERCAPTURECHANGEDandPOINTER_FLAG_CANCELED(for example, the system capturing the pointer for an edge gesture) cancel the ongoing pointer input to avoid stuck pointers.EnableMouseInPointeris intentionally not called: it's process-global and would reroute the mouse input AWT relies on. Touch and pen produceWM_POINTERmessages without it.compose.windows.nativeTouchsystem property and has no effect on other operating systems.net.java.dev.jna:jna-platform:5.19.1dependency to the desktop target ofcompose:ui:ui(declared in both version catalogs).Multitouchexample to the mpp demo that visualizes the active pointers.Implementation notes:
windowHandle.GetPointerPenInfobut not mapped, sinceComposeScenePointerhas no corresponding fields.Testing
Tested on Windows 11, Recording attached below.
Compose.MPP.demo.2026-07-12.21-11-33.mp4
./gradlew :compose:mpp:demo:runDesktop -Dcompose.windows.nativeTouch=trueVerified:
Components/Multitouchexample shows one pointer per finger withtypes=Touch(Stylusfor a pen). Without the flag it shows a singleMousepointer.LazyColumnwith a finger, touch slop, pinch-to-zoom viadetectTransformGestures.Components/Pen Inputexample (this makes the demo introduced in Introduce pen-oriented input demo #3079 functional on Windows).This should be tested by QA.
Release Notes
Features - Desktop
compose.windows.nativeTouchsystem property