Trackpad gestures
Handle trackpad scrolling, pinch-to-zoom and rotation with standard Compose modifiers.
Trackpad gestures reach Compose as standard pointer events. Modifier.scrollable, the lazy lists
and Modifier.transformable handle them with no extra code, and you add no dependency beyond
nucleus-application.

Events per gesture
| Gesture | macOS | Windows | Linux |
|---|---|---|---|
| Two-finger scroll | PanStart / PanMove / PanEnd | PanStart / PanMove / PanEnd (precision touchpad) | Scroll |
| Mouse wheel | Scroll | Scroll | Scroll |
| Pinch, Ctrl + wheel | ScaleStart / ScaleChange / ScaleEnd | Scale* | Scale* |
| Rotation | two Touch pointers | none | two Touch pointers |
Scroll
Scrolling containers work as they are. Only a custom pointerInput handler needs care: on macOS
and on a Windows precision touchpad a swipe arrives as PanMove, so a handler that listens for
Scroll alone misses it.
Modifier.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent()
val change = event.changes.first()
when (event.type) {
PointerEventType.PanMove -> move(change.panOffset)
PointerEventType.Scroll -> move(change.scrollDelta)
else -> Unit
}
}
}
}To receive every trackpad step as Scroll instead, start the JVM with
-Dnucleus.tao.trackpadPanEvents=false.
Changed in 3.0
On Windows, a precision touchpad now scrolls with Pan* events and the OS inertia, as on macOS.
Handlers that only listen for Scroll must also handle PanMove.
Zoom with a pinch
Changed in 3.0
detectTransformGestures no longer sees a pinch. Use Modifier.transformable or listen for the
Scale* events. See Migrate from 2.x.
@Composable
fun ZoomableImage() {
var scale by remember { mutableFloatStateOf(1f) }
val state = rememberTransformableState { zoomChange, _, _ -> scale *= zoomChange }
Box(
Modifier
.fillMaxSize()
.graphicsLayer(scaleX = scale, scaleY = scale)
.transformable(state),
)
}In a custom handler, read PointerInputChange.scaleFactor on ScaleChange. It is a ratio per
event: above 1f zooms in, below 1f zooms out.
When the OS cancels a pinch, for example because the system takes over the gesture, the
pinch ends with ScaleEnd and Nucleus then cancels the window's pointer input. Gesture handlers
see a cancellation, not a release. A trackpad pan in progress ends with PanEnd first, and the
next finger movement starts a new one.
Rotate
Modifier.transformable and detectTransformGestures read the rotation angle on macOS and Linux.
Windows reports no trackpad rotation. A pinch and a rotation never run at the same time: the
gesture that starts first keeps the trackpad until it ends.
API reference
| Symbol | Notes |
|---|---|
PointerEventType.PanStart / PanMove / PanEnd | macOS trackpad and Windows precision-touchpad scroll |
PointerInputChange.panOffset | Pan delta in pixels |
PointerEventType.ScaleStart / ScaleChange / ScaleEnd | Pinch and Ctrl + wheel |
PointerInputChange.scaleFactor | Zoom ratio per event |
-Dnucleus.tao.trackpadPanEvents=false | Send trackpad pans as Scroll |
-Dnucleus.tao.directManipulation=false | Windows: drop DirectManipulation, back to the legacy wheel emulation |
What's next
- Pen and touch input: touchscreen contacts and pressure.
- Pointer icons: cursors beyond the four Compose defines.
- Migrate from 2.x: every behavior change in 3.0.
Last updated on