tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] availableMonitors returns wrong position on macos~

Open qzd1989 opened this issue 1 year ago • 2 comments

Describe the bug

Here are my three monitors: image

Here is my code:

//vue file
import {
  availableMonitors
} from "@tauri-apps/api/window";
onMounted(async () => {
  const pm = await availableMonitors();
  console.log(pm);
});

Here is the results: a2

Reproduction

simple code.

Expected behavior

Is it a bug?

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.6.1 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.5.1
    - pnpm: 9.6.0
    - yarn: 1.22.22
    - npm: 10.8.2

[-] Packages
    - tauri 🦀: 2.0.0-rc.10
    - tauri-build 🦀: 2.0.0-rc.9
    - wry 🦀: 0.43.1
    - tao 🦀: 0.30.0
    - @tauri-apps/api : 2.0.0-rc.4
    - @tauri-apps/cli : 2.0.0-rc.13

[-] Plugins
    - tauri-plugin-dialog 🦀: 2.0.0-rc.5
    - @tauri-apps/plugin-dialog : 2.0.0-rc.1
    - tauri-plugin-store 🦀: 2.0.0-rc.3
    - @tauri-apps/plugin-store : 2.0.0-rc.1
    - tauri-plugin-fs 🦀: 2.0.0-rc.3
    - @tauri-apps/plugin-fs : 2.0.0-rc.2
    - tauri-plugin-shell 🦀: 2.0.0-rc.3
    - @tauri-apps/plugin-shell : 2.0.0-rc.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React (Next.js)
    - bundler: Vite

Stack trace

No response

Additional context

No response

qzd1989 avatar Sep 12 '24 20:09 qzd1989

I am also encountering this same issue. My displays are as follows:

1920x1080, x: -1920, y: 0
2560x1440, x: 0,     y: 0
1920x1080, x: 2560,  y: 0

But it's telling me that my displays are:

3840x2160, x: -3840, y: 0
2560x1440, x: 0,     y: 0
1920x1080, x: 2560,  y: 0

Not sure where the 3840x2160 monitor comes from. Perhaps from my closed macbook pro display, which is currently in shell mode, but that is 3024x1964. It's completely missing my first 1080p monitor.

The only difference from the OP is that I am calling this from rust, instead of in js/ts:

fn get_monitors(&self, window: tauri::Window) -> anyhow::Result<Vec<super::Display>> {
    let monitors = window
        .available_monitors()?
        .iter()
        .map(|monitor| super::Display {
            x: monitor.position().x,
            y: monitor.position().y,
            width: monitor.size().width,
            height: monitor.size().height,
        })
        .collect();
    Ok(monitors)
}

Output (custom display type, mapped to the tauri return):

[Display { x: 0, y: 0, width: 2560, height: 1440 }, Display { x: -3840, y: 0, width: 3840, height: 2160 }, Display { x: 2560, y: 0, width: 1920, height: 1080 }]

tauri info output:

[✔] Environment
    - OS: Mac OS 15.1.1 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ 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-aarch64-apple-darwin (default)
    - node: 20.16.0
    - yarn: 1.22.22
    - npm: 10.8.1

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

[-] Plugins
    - tauri-plugin-log 🦀: 2.0.2
    - @tauri-apps/plugin-log : not installed!
    - tauri-plugin-single-instance 🦀: 2.0.1
    - @tauri-apps/plugin-single-instance : not installed!
    - tauri-plugin-global-shortcut 🦀: 2.0.1
    - @tauri-apps/plugin-global-shortcut : 2.0.0

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../out
    - devUrl: http://localhost:3000/
    - framework: React (Next.js)
    - bundler: Webpack

zacbre avatar Dec 03 '24 17:12 zacbre

Not sure where the 3840x2160 monitor comes from. Perhaps from my closed macbook pro display, which is currently in shell mode, but that is 3024x1964. It's completely missing my first 1080p monitor.

Is the 1080p scaled to 200%? Maybe availableMonitors returns virtual instead of physical sizes (even though it's not supposed to)

FabianLars avatar Dec 03 '24 18:12 FabianLars