From 169e5fcfaa01b95877bcc9acbdd2fdd5e8da854d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 6 Dec 2024 04:28:06 +0100 Subject: [PATCH] Use "outer" positions in all window-related operations --- winit/src/program.rs | 17 ++++++++++++++++- winit/src/program/window_manager.rs | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/winit/src/program.rs b/winit/src/program.rs index 13873edd07..8f87ed4d7a 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -538,10 +538,25 @@ where log::info!("Window attributes for id `{id:#?}`: {window_attributes:#?}"); + // On macOS, the `position` in `WindowAttributes` represents the "inner" + // position of the window; while on other platforms it's the "outer" position. + // We fix the inconsistency on macOS by positioning the window after creation. + #[cfg(target_os = "macos")] + let mut window_attributes = window_attributes; + + #[cfg(target_os = "macos")] + let position = + window_attributes.position.take(); + let window = event_loop .create_window(window_attributes) .expect("Create window"); + #[cfg(target_os = "macos")] + if let Some(position) = position { + window.set_outer_position(position); + } + #[cfg(target_arch = "wasm32")] { use winit::platform::web::WindowExtWebSys; @@ -1340,7 +1355,7 @@ fn run_action( if let Some(window) = window_manager.get(id) { let position = window .raw - .inner_position() + .outer_position() .map(|position| { let position = position .to_logical::(window.raw.scale_factor()); diff --git a/winit/src/program/window_manager.rs b/winit/src/program/window_manager.rs index 10a973fe4e..c9c991d370 100644 --- a/winit/src/program/window_manager.rs +++ b/winit/src/program/window_manager.rs @@ -164,7 +164,7 @@ where { pub fn position(&self) -> Option { self.raw - .inner_position() + .outer_position() .ok() .map(|position| position.to_logical(self.raw.scale_factor())) .map(|position| Point {