tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.36k stars 2.58k forks source link

[bug] Initial window position treated as PhysicalPosition on Windows since Tauri 2.1 #11718

Closed dgerhardt closed 2 days ago

dgerhardt commented 4 days ago

Describe the bug

Up to Tauri 2.0.6, the position values passed to the Window constructor and set in tauri.conf.json were treated as LogicalPosition. This is no longer the case since Tauri 2.1.0, at least on Windows 11.

Reproduction

const initialX = 100;
const initialY = 100;
const win = new WebviewWindow('win', {
  x: initialX,
  y: initialY
});
win.once('tauri://created', async () => {
  const pos = await win.outerPosition();
  const scaleFactor = await win.scaleFactor();
  const logicalPos = pos.toLogical(scaleFactor);
  console.log('Position (converted to logical)', logicalPos);
  console.log(
    'Logical position should match initial position (x, y)',
    Math.round(logicalPos.x) === initialX,
    Math.round(logicalPos.y) === initialY);
  console.log('Physical Position (physical)', pos);
});

Output

Position (converted to logical) LogicalPosition { type: "Logical", x: 40, y: 40 }
Logical position should match initial position (x, y) false false
Physical Position (physical) Physical { Positiontype: "Physical", x: 100, y: 100 }

Expected behavior

Position values passed to the Window constructor should be treated as LogicalPosition.

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.26100 x86_64 (X64)
    ✔ WebView2: 131.0.2903.48
    ✔ MSVC: Visual Studio Build Tools 2022
    ✔ rustc: 1.82.0 (f6e511eec 2024-10-15)
    ✔ cargo: 1.82.0 (8f40fc59f 2024-08-21)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 22.11.0
    - yarn: 1.22.19
    - npm: 10.9.0

[-] Packages
    - tauri 🦀: 2.1.1
    - tauri-build 🦀: 2.0.3
    - wry 🦀: 0.47.0
    - tao 🦀: 0.30.8
    - @tauri-apps/api : 2.1.0
    - @tauri-apps/cli : 2.1.0

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.2
    - @tauri-apps/plugin-shell : 2.0.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - bundler: Vite

Stack trace

No response

Additional context

Tested on Windows 11 with a High DPI display and 250% scaling.