diff options
author | 2025-01-06 20:26:07 +0100 | |
---|---|---|
committer | 2025-01-06 20:26:07 +0100 | |
commit | e543329c79dbb8e583915b14148c757d6bfd6b38 (patch) | |
tree | 7f994feece86caf4ea8e3a609eab73713d4f9076 | |
parent | f2c9b6b2ffc50d67d9789e77cb55eeb2a0ebe470 (diff) | |
parent | bfab1a32d1d50875875800413b6f399689ec6d04 (diff) | |
download | iced-e543329c79dbb8e583915b14148c757d6bfd6b38.tar.gz iced-e543329c79dbb8e583915b14148c757d6bfd6b38.tar.bz2 iced-e543329c79dbb8e583915b14148c757d6bfd6b38.zip |
Merge pull request #2688 from iced-rs/fix/window-position-inconsistency
Use "outer" positions in all window-related operations
-rw-r--r-- | core/src/window/event.rs | 4 | ||||
-rw-r--r-- | winit/src/program.rs | 17 | ||||
-rw-r--r-- | winit/src/program/window_manager.rs | 2 |
3 files changed, 19 insertions, 4 deletions
diff --git a/core/src/window/event.rs b/core/src/window/event.rs index 4e2751ee..45d29179 100644 --- a/core/src/window/event.rs +++ b/core/src/window/event.rs @@ -9,8 +9,8 @@ pub enum Event { /// A window was opened. Opened { /// The position of the opened window. This is relative to the top-left corner of the desktop - /// the window is on, including virtual desktops. Refers to window's "inner" position, - /// or the client area, in logical pixels. + /// the window is on, including virtual desktops. Refers to window's "outer" position, + /// or the window area, in logical pixels. /// /// **Note**: Not available in Wayland. position: Option<Point>, diff --git a/winit/src/program.rs b/winit/src/program.rs index 26b713f3..cc19a4e0 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -508,10 +508,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; @@ -1310,7 +1325,7 @@ fn run_action<P, C>( if let Some(window) = window_manager.get(id) { let position = window .raw - .inner_position() + .outer_position() .map(|position| { let position = position .to_logical::<f32>(window.raw.scale_factor()); diff --git a/winit/src/program/window_manager.rs b/winit/src/program/window_manager.rs index 451b2caf..a3c991df 100644 --- a/winit/src/program/window_manager.rs +++ b/winit/src/program/window_manager.rs @@ -165,7 +165,7 @@ where { pub fn position(&self) -> Option<Point> { self.raw - .inner_position() + .outer_position() .ok() .map(|position| position.to_logical(self.raw.scale_factor())) .map(|position| Point { |