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] Window set_size broken #11740

Closed richards-native closed 2 days ago

richards-native commented 2 days ago

Describe the bug

Apologies if this issue already exists, I saw a couple around this but none talking about this problem specifically.

It looks like sometime between 2.0.0 and 2.1.1, window sizing in from the tauri config and using set_size (from Rust or JS) is not working properly. Setting the window size in the config, the values seem to be off by a small amount (14px X and 37px Y on a 528x100px window). Using set_size seems to basically have no effect on the size.

Looking into the source, it appears the issue is in the Tao crate. Commenting out this section of code fixes the issue, initial window size is correct and set_size works again.

if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW) && !is_decorated {
  let mut pt: POINT = unsafe { mem::zeroed() };
  if unsafe { ClientToScreen(self.hwnd(), &mut pt) }.as_bool() == true {
    let mut window_rc: RECT = unsafe { mem::zeroed() };
    if unsafe { GetWindowRect(self.hwnd(), &mut window_rc) }.is_ok() {
      let left_b = pt.x - window_rc.left;
      let right_b = pt.x + width - window_rc.right;
      let top_b = pt.y - window_rc.top;
      let bottom_b = pt.y + height - window_rc.bottom;

      width = width + (left_b - right_b);
      height = height + (top_b - bottom_b);
    }
  }
}

From this I was able to see it only happens for undecorated windows where shadows are enabled, disabling the shadows does work but that's not the style I am looking for in my application.

Reproduction

No response

Expected behavior

Window resizes correctly.

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22631 x86_64 (X64)
    ✔ WebView2: 130.0.2849.80
    ✔ MSVC:
        - Visual Studio Build Tools 2017
        - Visual Studio Build Tools 2019
        - Visual Studio Community 2022
    ✔ rustc: 1.80.1 (3f5fd8dd4 2024-08-06)
    ✔ cargo: 1.80.1 (376290515 2024-07-16)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 22.7.0
    - npm: 10.8.2

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

[-] Plugins
    - tauri-plugin-websocket 🦀: 2.0.1
    - @tauri-apps/plugin-websocket : 2.0.0
    - tauri-plugin-fs 🦀: 2.0.3
    - @tauri-apps/plugin-fs : 2.0.0 (outdated, latest: 2.0.2)
    - tauri-plugin-updater 🦀: 2.0.2
    - @tauri-apps/plugin-updater : 2.0.0
    - tauri-plugin-single-instance 🦀: 2.0.1
    - @tauri-apps/plugin-single-instance : not installed!
    - tauri-plugin-log 🦀: 2.0.2
    - @tauri-apps/plugin-log : 2.0.0

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist/tauri-app/browser
    - devUrl: http://localhost:1420/
    - framework: Angular
    - bundler: Webpack

Stack trace

No response

Additional context

No response

amrbashir commented 2 days ago

I believe this to be duplicate of #11695 and thus fixed by https://github.com/tauri-apps/tao/pull/1017