File tree 1 file changed +15
-2
lines changed
src/platform_impl/apple/appkit
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -945,8 +945,21 @@ impl WindowDelegate {
945
945
}
946
946
947
947
pub fn surface_position ( & self ) -> PhysicalPosition < i32 > {
948
- let content_rect = self . window ( ) . contentRectForFrameRect ( self . window ( ) . frame ( ) ) ;
949
- let logical = LogicalPosition :: new ( content_rect. origin . x , content_rect. origin . y ) ;
948
+ // The calculation here is a bit awkward because we've gotta reconcile the
949
+ // different origins (Winit prefers top-left vs. NSWindow's bottom-left),
950
+ // and I couldn't find a built-in way to do so.
951
+
952
+ // The position of the window and the view, both in Winit screen coordinates.
953
+ let window_position = flip_window_screen_coordinates ( self . window ( ) . frame ( ) ) ;
954
+ let view_position = flip_window_screen_coordinates (
955
+ self . window ( ) . contentRectForFrameRect ( self . window ( ) . frame ( ) ) ,
956
+ ) ;
957
+
958
+ // And use that to convert the view position to window coordinates.
959
+ let surface_position =
960
+ NSPoint :: new ( view_position. x - window_position. x , view_position. y - window_position. y ) ;
961
+
962
+ let logical = LogicalPosition :: new ( surface_position. x , surface_position. y ) ;
950
963
logical. to_physical ( self . scale_factor ( ) )
951
964
}
952
965
You can’t perform that action at this time.
0 commit comments