Save logical position when restoring on macos #4061
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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