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] [macos] physical position of windows and monitors reported incorrectly #7890

Open
icambron opened this issue Sep 22, 2023 · 0 comments
Labels
platform: macOS status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@icambron
Copy link
Contributor

icambron commented Sep 22, 2023

Describe the bug

Setup: I have a Macbook Pro hooked up to an external monitor as below. The Macbook is set to "more space" which means it's a 3600x2388 monitor scaled to 1800x1169. Next to it is an external monitor running at 3440x1440.

Displays

The laptop screen works fine in isolation: monitor.size() returns PhysicalSize { width: 3600, height: 2338 } and monitor.position() returns PhysicalPosition { x: 0, y: 0 }. Windows inside the monitor report a physical position with x between 0 and 3600. So far so good. It's just using totally unscaled numbers.

But the second monitor reports its position as PhysicalPosition { x: 1800, y: -271 }. This implies it's using the scaled size of the laptop screen to compute the external monitor's offset in physical space:

  • 1800 is the scaled width of the laptop screen, so 1800 is the starting x value the secondary monitor to its right
  • because the scaled height of the laptop screen is 1169, the secondary monitor is 271 pixels taller and thus starts at -271

So it's being inconsistent: widths unscaled, offsets scaled.

What makes this problematic is that windows inside the second monitor report their physical positions in ways consistent with the second monitor. So a window there has a physical x position of between 1800 and 5200 (1800 + 3440 = 5200). This makes the total physical space inconsistent, such that:

  • there are multiple window positions that report the same physical position (e.g. x=2000 corresponds to a position on both monitors)
  • dragging the window from left to right so that it crosses into the second monitor will cause the physical position to rise until it his the edge of the monitor, then drop sharply down (from 3599 to 1800)
  • calling set_position() on its current physical position can switch which monitor it's on:
    match event {
        tauri::WindowEvent::Moved(tauri_pos) => { // physical position of moved window on second monitor
            println!("{:?}", tauri_pos); // => PhysicalPosition { x: 1947, y: -12 }
            
           // now move it to the position it thinks it's already at
         // moves it back onto the first monitor!
          window.set_position(tauri_pos);

In practice, where this came up for me is that I save the positions and current monitor of windows so that when the user reopens the application, the windows reopen in the right places. I check that the saved positions lie within the bounding box of the stored monitor name and then set_position the tauri windows into place. But it often puts them on the wrong monitor. This is because the stored physical position is actually ambiguous, since I recorded it from the position on the secondary monitor but it's equally valid on the laptop monitor and that's where Tauri puts it.

Reproduction

No response

Expected behavior

I think monitors and windows need to be completely consistent about whether physical position corresponds to scaled or unscaled sizes and positions. (I suspect they should mean scaled sizes always, but that may have consequences I don't understand; the more important point is to be consistent.)

Platform and versions

[✔] Environment                                                                                                                                                                                                                                                                                                                                         
    - OS: Mac OS 13.5.2 X64                                                                                                                                                                                                                                                                                                                             
    ✔ Xcode Command Line Tools: installed                                                                                                                                                                                                                                                                                                               
    ✔ rustc: 1.69.0 (84c898d65 2023-04-16)                                                                                                                                                                                                                                                                                                              
    ✔ Cargo: 1.69.0 (6e9a83356 2023-04-12)                                                                                                                                                                                                                                                                                                              
    ✔ rustup: 1.26.0 (2023-04-05)                                                                                                                                                                                                                                                                                                                       
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)                                                                                                                                                                                                                                                                                             
    - node: 20.5.1                                                                                                                                                                                                                                                                                                                                      
    - yarn: 1.22.19                                                                                                                                                                                                                                                                                                                                     
    - npm: 9.8.0                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                        
[-] Packages                                                                                                                                                                                                                                                                                                                                            
    - tauri [RUST]: 1.4.1                                                                                                                                                                                                                                                                                                                               
    - tauri-build [RUST]: 1.4.0                                                                                                                                                                                                                                                                                                                         
    - wry [RUST]: 0.24.3                                                                                                                                                                                                                                                                                                                                
    - tao [RUST]: 0.16.2                                                                                                                                                                                                                                                                                                                                
    - @tauri-apps/api [NPM]: 1.4.0                                                                                                                                                                                                                                                                                                                      
    - @tauri-apps/cli [NPM]: 1.4.0                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                        
[-] App                                                                                                                                                                                                                                                                                                                                                 
    - build-type: bundle                                                                                                                                                                                                                                                                                                                                
    - CSP: default-src blob: data: filesystem: ws: wss: http: https: tauri: asset: customprotocol: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'                                                                                                                                                                                                 
    - distDir: ../dist                                                                                                                                                                                                                                                                                                                                  
    - devPath: http://localhost:3000/                                                                                                                                                                                                                                                                                                                   
    - framework: React                                                                                                                                                                                                                                                                                                                                  
    - bundler: Vite

Stack trace

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: macOS 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