Skip to content

Commit

Permalink
Use "outer" positions in all window-related operations
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Dec 6, 2024
1 parent 3b2a422 commit 69b4021
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,22 @@ 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 position =
window_attributes.position.take();

Check failure on line 546 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / all (macOS-latest, 1.80)

cannot borrow `window_attributes.position` as mutable, as `window_attributes` is not declared as mutable

Check failure on line 546 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / all (macOS-latest, 1.80)

cannot borrow `window_attributes.position` as mutable, as `window_attributes` is not declared as mutable

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;
Expand Down Expand Up @@ -1340,7 +1352,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());
Expand Down
2 changes: 1 addition & 1 deletion winit/src/program/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,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 {
Expand Down

0 comments on commit 69b4021

Please sign in to comment.