-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Save logical position when restoring on macos #4061
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
base: main
Are you sure you want to change the base?
Conversation
I found Update: Tested on my macOS (15.4.1) and windows (11 24H2) |
What's blocking here? |
Thanks for the PR! Should we implement LogicalPosition for all platforms, not just macos? Does it make sense to maintain both? I believe the 56 offset is meant to handle the thickness of the topbar, otherwise it marches down on a reload. Also CI not passing is blocking this PR, might be worth merging main to see if the failures go away. |
On macos, there's 1-1 mapping from points on screen to points in Logical Position, (and there's 2 points on screen have the same expression in Physical Position, like (1380, 100)) I once tried use logical position on windows but it failed to restore to the same location if 2 monitors have different scale. So I revert it in 0fbd886 For CI failure, I think there's some network issue, can re rerun it? |
On macOS, it behaves strange with multiple monitor physical location. That is to say
Consider we have 2 monitor main and extra which physical size is
2560x1440
(scale: 2.0) and1920x1080
(scale: 1.0)The physical position of A is
(1200, 100)
, and the logical position of it would be(600, 50)
due to scale factor.The code before this PR would save
(1200, 100)
to "window-state.json" and everything just works.But for point B, which "relative" physical position is
(100, 100)
(offset from left-top of "extra" monitor),In this case, winit would tell the physical position is
(1380, 100)
, which is the same as logical position(1380, 100)
.If we save
(1380, 100)
to state file, and when restore, the winit would think we are at main screen and position to(640, 50)
in logical position.window.outer_position()
p1.to_logical(window.scale_factor())
TL;DR, in macOS the position system is consist in "logical" coordinates.
Edit:
This seems only macOS related, so I restrict patch only on
cfg!(target_os = "macos")
There're several related issues you could reference
outer_position
andset_outer_position
may work unexpectedly with multiple monitors in different DPI tauri-apps/tao#816MonitorHandle::position
andMonitorHandle::size
metrics are unclear rust-windowing/winit#2645restore_state
API should useLogicalSize
(notPhysicalSize
) when restoring the window size tauri-apps/plugins-workspace#2620