You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
I took a look into this, and my initial conclusion is that the correct thing to do here (specifically on the web platform) is to map wheel events with ctrlKey: true to PinchGesture events rather than MouseWheel events at the Winit level. This seems to have broad browser support and be a de facto standard (albeit a weird one). The only place this isn't supported is in Safari on iOS which has dedicated non-standard gesturestart and gesturechange events instead.
I took a look into this, and my initial conclusion is that the correct thing to do here (specifically on the web platform) is to map wheel events with ctrlKey: true to PinchGesture events rather than MouseWheel events at the Winit level. This seems to have broad browser support and be a de facto standard (albeit a weird one). The only place this isn't supported is in Safari on iOS which has dedicated non-standard gesturestart and gesturechange events instead.
I really dislike using non-standard APIs, but I think it might be important to do so here. If not, we are ignoring a major platform. I'm happy to develop towards that goal.
I'm not 100% certain of how wasm-bindgen works, but I think we could safely copy-paste the definition to Winit as a fallback (and hopefully delete it in a few years if WebKit ever decides to be standards-conformant here).
I'm not 100% certain of how wasm-bindgen works, but I think we could safely copy-paste the definition to Winit as a fallback (and hopefully delete it in a few years if WebKit ever decides to be standards-conformant here).
It actually is on computers. It provides more information through the gesture event API.
Activity
madsmtm commentedon Mar 19, 2026
JoshBashed commentedon Mar 19, 2026
This is a global. I think just adding it to the event is best.
madsmtm commentedon Mar 19, 2026
JoshBashed commentedon Mar 19, 2026
madsmtm commentedon Mar 19, 2026
JoshBashed commentedon Mar 19, 2026
alice-i-cecile commentedon Mar 19, 2026
JoshBashed commentedon Mar 19, 2026
JoshBashed commentedon Mar 19, 2026
madsmtm commentedon Mar 19, 2026
madsmtm commentedon Mar 20, 2026
kchibisov commentedon Mar 21, 2026
JoshBashed commentedon Mar 22, 2026
kchibisov commentedon Mar 22, 2026
JoshBashed commentedon Mar 22, 2026
JoshBashed commentedon Mar 22, 2026
kchibisov commentedon Mar 22, 2026
[-]Design of the `ModifiersChanged` event is poor[/-][+]Pinch Gesture on web platform[/+]JoshBashed commentedon Mar 22, 2026
kchibisov commentedon Mar 22, 2026
kchibisov commentedon Mar 22, 2026
nicoburns commentedon Mar 22, 2026
I took a look into this, and my initial conclusion is that the correct thing to do here (specifically on the
webplatform) is to mapwheelevents withctrlKey: truetoPinchGestureevents rather thanMouseWheelevents at the Winit level. This seems to have broad browser support and be a de facto standard (albeit a weird one). The only place this isn't supported is in Safari on iOS which has dedicated non-standardgesturestartandgesturechangeevents instead.Documented at: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent#browser_compatibility
JoshBashed commentedon Mar 22, 2026
I really dislike using non-standard APIs, but I think it might be important to do so here. If not, we are ignoring a major platform. I'm happy to develop towards that goal.
web_sysseems to support it with thecfg(web_sys_unstable_apis)feature. https://docs.rs/web-sys/latest/web_sys/struct.GestureEvent.htmlmadsmtm commentedon Mar 24, 2026
I chimed in on the issue briefly on Bevy's Discord because it was being discussed there, the bulk of the discussion still happened here.
I agree with Nico's assessment.
I'm not 100% certain of how
wasm-bindgenworks, but I think we could safely copy-paste the definition to Winit as a fallback (and hopefully delete it in a few years if WebKit ever decides to be standards-conformant here).JoshBashed commentedon Mar 24, 2026
It actually is on computers. It provides more information through the gesture event API.