rust-windowing / rust-windowing/winit

Pinch Gesture on web platform

Open
#4,535 24 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

DS - web S - api
Dominant language
Rust
Stars
6.2k
Forks
1.3k
Avg merge
2d 19h
Merged PRs (30d)
9

Description

Connected to: bevyengine/bevy#23421

Description

I am trying to detect pinch to zoom gestures when using winit on the web. This is problematic because pinch to zoom gestures use the same MouseWheel event scrolling uses. The only difference is that event.ctrlKey is set.

This results in a hacky solution to try to detect whether the control key is pressed by listening to two separate events.

Solution

Adding modifier state directly to the MouseWheel event and other events similar to it would allow higher ease of use for situations such as this one. Another solution could be to expose just a variable called is_pinching that represents the control key.

A new proposed solution is to send a pinch event when the ctrlKey modifier is sent during the event.

Example JS Code

// current
document.addEventListener('wheel', (e) => {
    dispatchModifiers(...)
    dispatchWheelEvent({ x: e.deltaX, y: e.deltaY });
});

// proposed
document.addEventListener('wheel', (e) => {
    dispatchModifiers(...)
    if (!e.ctrlKey) dispatchWheelEvent({ x: e.deltaX, y: e.deltaY, modifiers: ... });
    else dispatchPinchEvent({ … });
});

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the web platform wheel listener shown in the issue and compare its current MouseWheel dispatch with the proposed pinch branch. Trace how ctrlKey is handled and determine the event API and modifier behavior needed to distinguish pinch gestures from ordinary wheel events. Done means pinch gestures no longer require the separate modifier-listener workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.