tauri-apps / tauri

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

[bug] The example "parent-window" doesn't work on Windows 11 #8299

Closed inkyMountain closed 9 months ago

inkyMountain commented 10 months ago

Describe the bug

Child window can't be created on Windows 11

Reproduction

Run the "parent-window" example on Windows 11 with command cargo run --example parent-window and click "create child window" button on the main window. https://github.com/tauri-apps/tauri/assets/36476221/671de62c-b4b5-43e1-a1d9-7050bcbdba7f

Expected behavior

A child window should show up, but none appears.

Platform and versions

[✔] Environment
    - OS: Windows 10.0.22621 X64
    ✔ WebView2: 119.0.2151.72
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.74.0 (79e9716c9 2023-11-13)
    ✔ cargo: 1.74.0 (ecb9851af 2023-10-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 16.20.2
    - pnpm: 8.8.0
    - yarn: 1.22.21
    - npm: 8.19.4

[-] Packages
    - tauri [RUST]: 2.0.0-alpha.18
    - tauri-build [RUST]: 2.0.0-alpha.12
    - wry [RUST]: 0.35.0 (0.34.2, 0.35.0)
    - tao [RUST]: 0.24.0 (0.23.0, 0.24.0)
    - @tauri-apps/api [NPM]: 2.0.0-alpha.12
    - @tauri-apps/cli [NPM]: 2.0.0-alpha.18

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:5173/
    - framework: React
    - bundler: Vite

The info above is the result ran in a hello world tauri app, because I don't know how to run `npm run tauri info` in the repo of tauri.

Stack trace

No response

Additional context

I did the same on MacOS and everything works fine, so it might be a platform specific issue.

amrbashir commented 10 months ago

I think the problem is that on Windows, the webview itself is a child window and so when you create a child window on Windows it is actually rendered behind the webview of the main window.

if you want the a similar behavior to macOS you need to be using window.owner_window() on Windows instead.

amrbashir commented 10 months ago

I am not really sure if I should solve this issue, or just make parent_window act the same as owner_window to make it consistent on all platforms.

inkyMountain commented 10 months ago

I think the problem is that on Windows, the webview itself is a child window and so when you create a child window on Windows it is actually rendered behind the webview of the main window.

if you want the a similar behavior to macOS you need to be using window.owner_window() on Windows instead.

Thanks for your reply. I noticed that if window A is the owner of Window B, window B won't move along with A when A is being dragged. But child window will in this scenario. So I have a try that I listen to the move event of window A, set B's position to make it the same as A. Then it looks like B is embedded into A. A small problem is that, if A is fastly dragged, at some moments B is a little out of A.

amrbashir commented 10 months ago

yeah on Windows, parent window don't control the position of the owned window, there is no relationship between their position, unlike macOS. You also need to have in mind that child windows while move with the parent, they don't overflow the parent like this image shows image

So it depends on your use case really.