tao icon indicating copy to clipboard operation
tao copied to clipboard

[macOS] `outer_position` and `set_outer_position` may work unexpectedly with multiple monitors in different DPI

Open pewsheen opened this issue 10 months ago • 0 comments

Describe the bug

  • When calling outer_position, tao will get the window's coordination (LogicalPosition) and then multiply it by the monitor's scale_factor which the window currently displays to a PhysicalPosition.
  • When we call set_outer_position, the scale_factor is also obtained from the monitor that the window currently displays.
  • If we call outer_position from a monitor and set_outer_position from another monitor, the PhysicalPostiion and LogicalPosition conversions may use different scale_factor, and the LogicalPosition obtained from and given to macOS may be different after conversion.

Let's have an example:

We have 2 monitors:

  • M1: 2x, 100x100 (in logical)
  • M2: 1x, 100x100 (in logical)

and a window sit in M1 with LogicalPosition(80, 20)

(0 ,0)           (100, 0)           (200, 0)
  ┌──────────────────┬──────────────────┐
  │          (80, 20)│                  │
  │            ┌───┐ │                  │
  │            │   │ │                  │
  │            │win│ │                  │
  │            └───┘ │                  │
  │                  │                  │
  │                  │                  │
  │                  │                  │
  │M1(2x)            │M2(1x)            │
  └──────────────────┴──────────────────┘
  • User call outer_position, they got PhysicalPosition(160, 40)
  • User call set_outer_position(PhysicalPosition(160, 40)) when the window is in M1, tao converts it to LogicalPosition(80, 20).
  • User call set_outer_position(PhysicalPosition(160, 40)) when the window is in M2, tao converts it to LogicalPosition(160, 40), since M2's scale_factor is 1.0. The window will be moved to M2 because the coordination sits within M2's bounds.

Steps To Reproduce Refer to the example above.

Expected behavior To set the window position as expected.

Platform and Versions (please complete the following information): OS: macOS 14.0

Would you want to assign yourself to resolve this bug?

  • [ ] Yes
  • [ ] No

Additional context

Related issue:

  • https://github.com/tauri-apps/tauri/issues/7890
  • https://github.com/tauri-apps/tauri/issues/7139
  • https://github.com/rust-windowing/winit/issues/2645

pewsheen avatar Oct 17 '23 07:10 pewsheen