Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Incorrect and inconsistent window positions #10021

Open
thewh1teagle opened this issue Jun 8, 2024 · 1 comment
Open

[bug] Incorrect and inconsistent window positions #10021

thewh1teagle opened this issue Jun 8, 2024 · 1 comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@thewh1teagle
Copy link
Contributor

thewh1teagle commented Jun 8, 2024

Describe the bug

I use tauri on v2 project on macOS
When creating new window with specific position, the position is incorrect and inconsistent comparing of doing it with global tauri.

Reproduction

Example on Rust side, it creates the window with invalid offset.

#[tauri::command]
async fn test(app_handle: AppHandle) {
  if let Some(window) = app_handle.get_webview_window("main") {
    let position = window.outer_position().unwrap();
    println!("position: {:?}", position);
    let window = WebviewWindowBuilder::new(&app_handle, "main1", WebviewUrl::App("/index.html".into()))
      .position(position.x as f64 + 30.0, position.y as f64 + 30.0) // 30px offset x+y
      .build();
  }
}

Example correct position using global tauri:

// needs  window:allow-create permission
(async () => {
    const position = await window.__TAURI__.window.getCurrent().outerPosition()
    console.log(position.x, position.y)
    new window.__TAURI__.window.Window("main1", {url: "/index.html", x: position.x + 30, y: position.y + 30})
})()

Expected behavior

The window should be created with offset of 30px on x,y

Full tauri info output

npx tauri info
WARNING: no lock files found, defaulting to npm

[✔] Environment
    - OS: Mac OS 14.4.1 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.75.0 (82e1608df 2023-12-21)
    ✔ cargo: 1.75.0 (1d8b05cdd 2023-11-20)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 18.19.1
    - yarn: 1.22.22
    - npm: 10.2.4
    - bun: 1.1.6

[-] Packages
    - tauri [RUST]: 2.0.0-beta.22
    - tauri-build [RUST]: 2.0.0-beta.17
    - wry [RUST]: 0.40.1
    - tao [RUST]: 0.28.0
    - tauri-cli [RUST]: 2.0.0-beta.17
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-beta.9

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../src

Stack trace

No response

Additional context

  1. Position values are inconsistent
    window.outer_position returns PhysicalPosition<i32> while WebviewWindowBuilder::new().position() expects f64
  2. Using window.set_position(position); right after creating it move it to correct position
@thewh1teagle thewh1teagle added status: needs triage This issue needs to triage, applied to new issues type: bug labels Jun 8, 2024
@pewsheen
Copy link
Contributor

WebviewWindowBuilder::new().position() expects a LogicalPosition. Could you try offsetting the position and then convert it to the LogicalPosition to see if it's correct?

It may look like:

let mut position = window.outer_position().unwrap();
println!("Physical position: {:?}", position);
position.x += 30;
position.y += 30;
let logical_position = position.to_logical::<f64>(window.scale_factor().unwrap());
println!("Logical position: {:?}", &logical_position);
let _window =
      WebviewWindowBuilder::new(&app_handle, "main1", WebviewUrl::App("/index.html".into()))
          .position(logical_position.x as f64, logical_position.y as f64) // 30px offset x+y
          .build();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

2 participants