wails icon indicating copy to clipboard operation
wails copied to clipboard

Disable Pinch Zoom

Open allcapsc opened this issue 4 years ago • 14 comments

Is your feature request related to a problem? Please describe.

I've been using Wails as an alternative for Electron but have noticed Wails doesn't support disabling Window Pinch or Mouse Scroll Zoom which can sometimes seem unprofessional when pushing an app to production. I would think this is a necessary feature for some people when wanting to limit control on an app window.

Describe the solution you'd like

I think it would be best for an option in the App Structure to Enable/Disable PinchZoom which would default to true and be edited to false to stop zooming entirely on an app window.

Describe alternatives you've considered

An alternative I tried was using CSS in the frontend but that doesn't do anything for limiting zoom pinch control on laptop touch-pads.

Additional context

No response

allcapsc avatar Oct 28 '22 23:10 allcapsc

Thanks for opening this! Sounds annoying. You haven't mentioned what platform you're targeting. Happy to accept a PR.

leaanthony avatar Oct 29 '22 01:10 leaanthony

Wouldn't the user-scalable=no option in a meta viewport tag cover your use case?

brody192 avatar Oct 29 '22 02:10 brody192

Wouldn't the user-scalable=no option in a meta viewport tag cover your use case?

Unfortunately no, I also tried that but it does not stop pinch zoom on desktop rather mobile only.

allcapsc avatar Oct 29 '22 03:10 allcapsc

Thanks for opening this! Sounds annoying. You haven't mentioned what platform you're targeting. Happy to accept a PR.

Currently targeting Windows, If I can find some info I'll try adding it onto here.

allcapsc avatar Oct 29 '22 03:10 allcapsc

Unfortunately no, I also tried that but it does not stop pinch zoom on desktop rather mobile only.

Have you tried prevent default on various gesture events?

brody192 avatar Oct 29 '22 04:10 brody192

Should be pretty straight forward to be implemented for Windows: ICoreWebView2Settings5.IsPinchZoomEnabled

https://github.com/wailsapp/wails/blob/638caf72f0a85c9b29dc4d4e993d2f80e01491b7/v2/internal/frontend/desktop/windows/go-webview2/pkg/edge/ICoreWebViewSettings.go#L358

Couldn't yet find more information for macOS and Linux.

stffabi avatar Oct 29 '22 21:10 stffabi

Any update on this? It is weird that one of my application has disabled zoom, but some are not. Not sure what I did in that app.

Updated: I used the vanilla template (back on Wails version 2.2.0) which disable the pinch zoom.

In the meantime, this method works for me in the front-end:

//Manually disable pinch zoom!
document.addEventListener("wheel", event => {
    const { ctrlKey } = event;
    if (ctrlKey) {
       event.preventDefault();
       return
    }
}, { passive: false });

KiddoV avatar Feb 24 '23 13:02 KiddoV

@KiddoV can you please provide more information about the difference between v2.2 and current regarding this? As far as I'm aware, we haven't ever supported this feature but there was a PR to manually set the scale of the viewport

leaanthony avatar Feb 24 '23 19:02 leaanthony

TBH, that version is too old and I don't know what is the differences between those, but looking at my old application which using v2.2.0 and the vanilla template, hitting CTRL+Mouse Wheel doesn't zoom in/out (I don't think I did something in the front-end back then) like other app which currently at the latest version/ svelte templates.

KiddoV avatar Feb 24 '23 19:02 KiddoV

Any update on this? It is weird that one of my application has disabled zoom, but some are not. Not sure what I did in that app.

Updated: I used the vanilla template (back on Wails version 2.2.0) which disable the pinch zoom.

In the meantime, this method works for me in the front-end:

//Manually disable pinch zoom!
document.addEventListener("wheel", event => {
    const { ctrlKey } = event;
    if (ctrlKey) {
       event.preventDefault();
       return
    }
}, { passive: false });

TYSM, this method works fine on me! 😃

FoliageOwO avatar Jun 16 '23 11:06 FoliageOwO

I know that this option was officially added but that's only to windows. Any options for Linux?

Jake-Schuler avatar May 03 '25 23:05 Jake-Schuler

If it's in webkit2gtk then it's an option 😅

leaanthony avatar May 05 '25 09:05 leaanthony

Hi there! Could you share your full Wails version, operating system, and a small example that reproduces the problem? It would also help to know what you expected to happen and what happened instead. Thanks!

taliesin-ai avatar Oct 15 '26 07:10 taliesin-ai

Adding a real-world macOS data point for this request.

App: magpie (https://github.com/yetone/magpie), a Wails v3 desktop app.

Symptom: On macOS, two-finger trackpad scrolling inside the WKWebView does not scroll the page. The user must grab the overlay scrollbar on the right edge to scroll. Pinch-to-zoom on the trackpad works, which suggests the gesture is being interpreted as a magnification event rather than a scrollWheel event.

Environment: macOS 13.4 (22F66), arm64, magpie 0.1.1271.

Binary evidence: Inspecting the shipped magpie binary (/Applications/magpie.app/Contents/MacOS/magpie), the only zoom-related C calls are windowZoomIn, windowZoomOut, windowZoomSet, windowZoomReset, windowZoomGet from Wails' own macOS webview code. There is no scrollWheel override and no DisableZoom field in WebviewWindowOptions (confirmed: the symbol does not exist in the binary). The setPageZoom path only calls -[WKWebView setMagnification:], which leaves allowsMagnification at its default value.

Workaround currently in use: Dragging the native scrollbar works because it goes through NSScrollView directly, bypassing WKWebView's magnify path.

This is blocking basic usability on macOS trackpads for any Wails app that does not override the WKWebView magnification behavior. A DisableZoom: true option (or defaulting allowsMagnification = NO on macOS) would fix it. Related: #6226

xiaosheng1126 avatar Oct 16 '26 13:10 xiaosheng1126