Save logical position when restoring on macos (#4061)
* save logical position on restore * only use logical position on macos * fix adjustment * fix windows window restoration * fix inner_size for windows
This commit is contained in:
1 parent
e947f5ec08
commit
65dd1f1762
2 files changed
+35
-19
No files matched your search
@@ -570,7 +570,7 @@ impl AppBuilder {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
_ = Command::new("taskkill")
|
_ = Command::new("taskkill")
|
||||||
.args(["/F", "/PID", &pid.to_string()])
|
.args(["/PID", &pid.to_string()])
|
||||||
.spawn();
|
.spawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+34
-18
@@ -532,19 +532,25 @@ impl App {
|
|||||||
let Ok(position) = window.outer_position() else {
|
let Ok(position) = window.outer_position() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
let (x, y) = if cfg!(target_os = "macos") {
|
||||||
|
let position = position.to_logical::<i32>(window.scale_factor());
|
||||||
|
(position.x, position.y)
|
||||||
|
} else {
|
||||||
|
(position.x, position.y)
|
||||||
|
};
|
||||||
|
|
||||||
let size = window.outer_size();
|
let (width, height) = if cfg!(target_os = "macos") {
|
||||||
|
let size = window.outer_size();
|
||||||
let x = position.x;
|
let size = size.to_logical::<u32>(window.scale_factor());
|
||||||
let y = position.y;
|
// This is to work around a bug in how tao handles inner_size on macOS
|
||||||
|
// We *want* to use inner_size, but that's currently broken, so we use outer_size instead and then an adjustment
|
||||||
// This is to work around a bug in how tao handles inner_size on macOS
|
//
|
||||||
// We *want* to use inner_size, but that's currently broken, so we use outer_size instead and then an adjustment
|
// https://github.com/tauri-apps/tao/issues/889
|
||||||
//
|
let adjustment = if window.is_decorated() { 28 } else { 0 };
|
||||||
// https://github.com/tauri-apps/tao/issues/889
|
(size.width, size.height.saturating_sub(adjustment))
|
||||||
let adjustment = match window.is_decorated() {
|
} else {
|
||||||
true if cfg!(target_os = "macos") => 56,
|
let size = window.inner_size();
|
||||||
_ => 0,
|
(size.width, size.height)
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(monitor_name) = monitor.name() else {
|
let Some(monitor_name) = monitor.name() else {
|
||||||
@@ -561,8 +567,8 @@ impl App {
|
|||||||
let state = PreservedWindowState {
|
let state = PreservedWindowState {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
width: size.width.max(200),
|
width: width.max(200),
|
||||||
height: size.height.saturating_sub(adjustment).max(200),
|
height: height.max(200),
|
||||||
monitor: monitor_name.to_string(),
|
monitor: monitor_name.to_string(),
|
||||||
url: Some(url),
|
url: Some(url),
|
||||||
};
|
};
|
||||||
@@ -599,14 +605,24 @@ impl App {
|
|||||||
|
|
||||||
// Only set the outer position if it wasn't explicitly set
|
// Only set the outer position if it wasn't explicitly set
|
||||||
if explicit_window_position.is_none() {
|
if explicit_window_position.is_none() {
|
||||||
window.set_outer_position(tao::dpi::PhysicalPosition::new(
|
if cfg!(target_os = "macos") {
|
||||||
position.0, position.1,
|
window.set_outer_position(tao::dpi::LogicalPosition::new(
|
||||||
));
|
position.0, position.1,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
window.set_outer_position(tao::dpi::PhysicalPosition::new(
|
||||||
|
position.0, position.1,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only set the inner size if it wasn't explicitly set
|
// Only set the inner size if it wasn't explicitly set
|
||||||
if explicit_inner_size.is_none() {
|
if explicit_inner_size.is_none() {
|
||||||
window.set_inner_size(tao::dpi::PhysicalSize::new(size.0, size.1));
|
if cfg!(target_os = "macos") {
|
||||||
|
window.set_inner_size(tao::dpi::LogicalSize::new(size.0, size.1));
|
||||||
|
} else {
|
||||||
|
window.set_inner_size(tao::dpi::PhysicalSize::new(size.0, size.1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the url if it exists
|
// Set the url if it exists
|
||||||
|
|||||||
Reference in new issue
Block a user