tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[feat] zoom in and out functionality (ctrl/ctrl+shift + "=" and ctrl/ctrl+shift+ "-")

Open Geometryse opened this issue 2 years ago • 8 comments

Describe the problem

Browsers such as edge and chrome have a zoom in and out functionality with hotkeys mentioned in the title, and I would like to include that in my application with tauri, but the hotkeys aren't working for me.

Describe the solution you'd like

add the hotkey support

Alternatives considered

No response

Additional context

No response

Geometryse avatar Jan 30 '22 19:01 Geometryse

tracking issue at https://github.com/tauri-apps/wry/issues/388

FabianLars avatar Jan 30 '22 19:01 FabianLars

It would seem the upstream has been fixed, I guess now it's just about extending the MenuItem enum and implementing what has been done on wry right?

I may help with that if this is begginer-friendly enough

martpie avatar May 10 '22 13:05 martpie

I think this issue is related to https://github.com/tauri-apps/wry/issues/569 . And it is work in progress in https://github.com/tauri-apps/wry/pull/574 .

keiya01 avatar May 10 '22 13:05 keiya01

Looks like the upstream issues this depends on have been resolved. What can I do to enable this?

candrewlee14 avatar Sep 19 '22 18:09 candrewlee14

even though it landed in upstream, tauri still needs to expose it.

amrbashir avatar Sep 19 '22 22:09 amrbashir

Bumping this up. Any idea when we'd get this into the framework?

rajatkulkarni95 avatar Nov 20 '22 15:11 rajatkulkarni95

Bumping this up again! This would be a welcome addition to Tauri, mainly for accessibility concerns.

Looky1173 avatar Dec 18 '22 17:12 Looky1173

Is there any workaround? I hope this gets added soon, would be great to have for accessibility.

salmenf avatar Jan 09 '23 19:01 salmenf

image Can tauri add a new `zoom` configuration item in the tauri.conf.json configuration file. @FabianLars

This allows users to set the default zoom of the window

mxismean avatar Feb 10 '23 01:02 mxismean

A year has passed. I want to know how the progress of this bug is? When can TAURI support Zoom? @FabianLars

mxismean avatar Mar 20 '23 07:03 mxismean

In the meantime, there is a pure js based way to get Zoom working in Tauri. using document.body.style.zoom = 1.5 from JS worked flawlessly in Windows, mac, and Linux Taui 1.5 builds. So there is a pure browser-based way to do this for now as its support in both Chromium (Tauri windows) and web-kit(Tauri mac/linux) (But not Firefox.)

So one could listen to the shortcut and do this Zoom JS thingy to make Zoom work in most cases. There are some caveats to this approach as iframes are not affected by Zoom and other things some edge cases wont work as expeced in some cases.

abose avatar Nov 01 '23 13:11 abose

Also looking forward to this for accessibility.

phudtran avatar Nov 04 '23 03:11 phudtran

In the meantime, there is a pure js based way to get Zoom working in Tauri. using document.body.style.zoom = 1.5 from JS worked flawlessly in Windows, mac, and Linux Taui 1.5 builds.

But how can a user of an app do that?

zeenix avatar Dec 04 '23 14:12 zeenix

In the meantime, there is a pure js based way to get Zoom working in Tauri. using document.body.style.zoom = 1.5 from JS worked flawlessly in Windows, mac, and Linux Taui 1.5 builds. So there is a pure browser-based way to do this for now as its support in both Chromium (Tauri windows) and web-kit(Tauri mac/linux) (But not Firefox.)

So one could listen to the shortcut and do this Zoom JS thingy to make Zoom work in most cases. There are some caveats to this approach as iframes are not affected by Zoom and other things some edge cases wont work as expeced in some cases.

This is not equivalent to zoom in browsers or in electron. For example some elements that would extend to window borders at 1.0 zoom level will cut off early if you reduce it through document.body.style.zoom.

StenniHub avatar Dec 04 '23 14:12 StenniHub

Hi all, managed to fix this by calling the webviews scale API from rust. See This pull request for the code changes needed(it's not much) https://github.com/phcode-dev/phoenix-desktop/pull/162 .

After this , call the js zoom_window API.

     await __TAURI__.tauri.invoke("zoom_window", {scaleFactor:1.2});

Tested working in Windows, Linux, and mac.

abose avatar Dec 27 '23 13:12 abose

How about reading the value, though ? Because when the user presses Ctrl++/-, we need to increment/decrement the value, requiring knowing it beforehand. Thanks

KaKi87 avatar Dec 27 '23 16:12 KaKi87

How about reading the value, though ? Because when the user presses Ctrl++/-, we need to increment/decrement the value, requiring knowing it beforehand. Thanks

We use our own storage layer for persisting preferences as browser local storage is not reliable in tauri. You can test with local storage though where you start with 1 in a zoom jey stored in storage and increment zoom by .1 on ctrl+ keyboard shortcut and decrement on.keyboard minus. So we don't really have to read back the scaling factor back from rust layer, instead use localstorage at browser side.

abose avatar Dec 27 '23 18:12 abose

That's unreliable as well, because there's no way to ensure that zoom isn't changeable by any other means.

KaKi87 avatar Dec 27 '23 18:12 KaKi87

That is probably how chrome/browser internally handles the zoom scale storage too, someone has to store the zoom scale factor to restore it later. If not the webkit layer, then we do it at the application side. It is pretty reliable as long as your storage layer is reliable.

abose avatar Dec 28 '23 03:12 abose

In Chrome, zoom can be changed in many ways : command line arguments, hamburger menu, Ctrl+wheel, Ctrl+keyboard... So, it's stored somewhere all these inputs can be tracked. So, in Tauri, storing this in the app would be unreliable as zoom will eventually be changeable from all these places as well.

KaKi87 avatar Dec 28 '23 07:12 KaKi87

Hi all, managed to fix this by calling the webviews scale API from rust. See This pull request for the code changes needed(it's not much) phcode-dev/phoenix-desktop#162 .

After this , call the js zoom_window API.

     await __TAURI__.tauri.invoke("zoom_window", {scaleFactor:1.2});

Tested working in Windows, Linux, and mac.

it worked for me. Thank a lot

namduong-arbin avatar Mar 13 '24 04:03 namduong-arbin

Windows Only

Uh, why ?

KaKi87 avatar Apr 05 '24 00:04 KaKi87

This API is only available in Windows webview2, but we can provide a polyfill as mentioned here https://github.com/tauri-apps/tauri/pull/9352#issuecomment-2034985866

Legend-Master avatar Apr 05 '24 00:04 Legend-Master