@@ -1031,11 +1031,19 @@ impl Clone for IdRef {
1031
1031
1032
1032
#[ allow( non_snake_case) ]
1033
1033
unsafe fn NSEventToEvent ( window : & Window , nsevent : id ) -> Option < Event > {
1034
- unsafe fn mousePosition ( window : & Window , nsevent : & id ) -> ( i32 , i32 ) {
1034
+ unsafe fn get_mouse_position ( window : & Window , nsevent : id ) -> ( i32 , i32 ) {
1035
1035
let window_point = nsevent. locationInWindow ( ) ;
1036
+ let cWindow: id = msg_send ! [ nsevent, window] ;
1037
+ let view_point = if cWindow == nil {
1038
+ let window_rect = window. window . convertRectFromScreen_ ( NSRect :: new ( window_point, NSSize :: new ( 0.0 , 0.0 ) ) ) ;
1039
+ window. view . convertPoint_fromView_ ( window_rect. origin , nil)
1040
+ } else {
1041
+ window. view . convertPoint_fromView_ ( window_point, nil)
1042
+ } ;
1043
+ let view_rect = NSView :: frame ( * window. view ) ;
1036
1044
let scale_factor = window. hidpi_factor ( ) ;
1037
- ( ( scale_factor * window_point . x as f32 ) as i32 ,
1038
- ( scale_factor * window_point . y as f32 ) as i32 )
1045
+ ( ( scale_factor * view_point . x as f32 ) as i32 ,
1046
+ ( scale_factor * ( view_rect . size . height - view_point . y ) as f32 ) as i32 )
1039
1047
}
1040
1048
1041
1049
if nsevent == nil { return None ; }
@@ -1049,37 +1057,26 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> {
1049
1057
match event_type {
1050
1058
NSLeftMouseDown => {
1051
1059
Some ( MouseInput ( Pressed , MouseButton :: Left ,
1052
- Some ( mousePosition ( window, & nsevent) ) ) )
1060
+ Some ( get_mouse_position ( window, nsevent) ) ) )
1053
1061
} ,
1054
1062
NSLeftMouseUp => {
1055
1063
Some ( MouseInput ( Released , MouseButton :: Left ,
1056
- Some ( mousePosition ( window, & nsevent) ) ) )
1064
+ Some ( get_mouse_position ( window, nsevent) ) ) )
1057
1065
} ,
1058
1066
NSRightMouseDown => {
1059
1067
Some ( MouseInput ( Pressed , MouseButton :: Right ,
1060
- Some ( mousePosition ( window, & nsevent) ) ) )
1068
+ Some ( get_mouse_position ( window, nsevent) ) ) )
1061
1069
} ,
1062
1070
NSRightMouseUp => {
1063
1071
Some ( MouseInput ( Released , MouseButton :: Right ,
1064
- Some ( mousePosition ( window, & nsevent) ) ) )
1072
+ Some ( get_mouse_position ( window, nsevent) ) ) )
1065
1073
} ,
1066
1074
NSMouseMoved |
1067
1075
NSLeftMouseDragged |
1068
1076
NSOtherMouseDragged |
1069
1077
NSRightMouseDragged => {
1070
- let window_point = nsevent. locationInWindow ( ) ;
1071
- let cWindow: id = msg_send ! [ nsevent, window] ;
1072
- let view_point = if cWindow == nil {
1073
- let window_rect = window. window . convertRectFromScreen_ ( NSRect :: new ( window_point, NSSize :: new ( 0.0 , 0.0 ) ) ) ;
1074
- window. view . convertPoint_fromView_ ( window_rect. origin , nil)
1075
- } else {
1076
- window. view . convertPoint_fromView_ ( window_point, nil)
1077
- } ;
1078
- let view_rect = NSView :: frame ( * window. view ) ;
1079
- let scale_factor = window. hidpi_factor ( ) ;
1080
-
1081
- Some ( MouseMoved ( ( scale_factor * view_point. x as f32 ) as i32 ,
1082
- ( scale_factor * ( view_rect. size . height - view_point. y ) as f32 ) as i32 ) )
1078
+ let ( x, y) = get_mouse_position ( window, nsevent) ;
1079
+ Some ( MouseMoved ( x, y) )
1083
1080
} ,
1084
1081
NSKeyDown => {
1085
1082
let mut events = VecDeque :: new ( ) ;
0 commit comments