@@ -393,17 +393,38 @@ extern "C" fn update_tracking_areas(this: &Object, _self: Sel, _: id) {
393393extern "C" fn mouse_moved ( this : & Object , _sel : Sel , event : id ) {
394394 let state = unsafe { WindowState :: from_view ( this) } ;
395395
396- let point: NSPoint = unsafe {
396+ // Window-relative position (existing behavior)
397+ let window_point: NSPoint = unsafe {
397398 let point = NSEvent :: locationInWindow ( event) ;
398-
399399 msg_send ! [ this, convertPoint: point fromView: nil]
400400 } ;
401+
402+ // Screen-absolute position (new!)
403+ // NSEvent::mouseLocation returns screen coordinates with Y=0 at BOTTOM
404+ // We need to flip Y-axis to match Windows/X11 convention (Y=0 at TOP)
405+ let screen_point: NSPoint = unsafe {
406+ NSEvent :: mouseLocation ( event)
407+ } ;
408+
409+ // Get the screen height to flip Y coordinate
410+ let screen_height = unsafe {
411+ let screen: id = msg_send ! [ class!( NSScreen ) , mainScreen] ;
412+ let frame: NSRect = msg_send ! [ screen, frame] ;
413+ frame. size . height
414+ } ;
415+
401416 let modifiers = unsafe { NSEvent :: modifierFlags ( event) } ;
402417
403- let position = Point { x : point. x , y : point. y } ;
418+ let position = Point { x : window_point. x , y : window_point. y } ;
419+ // Flip Y-axis: convert from bottom-origin to top-origin
420+ let screen_position = Point {
421+ x : screen_point. x ,
422+ y : screen_height - screen_point. y
423+ } ;
404424
405425 state. trigger_event ( Event :: Mouse ( MouseEvent :: CursorMoved {
406426 position,
427+ screen_position,
407428 modifiers : make_modifiers ( modifiers) ,
408429 } ) ) ;
409430}
@@ -430,9 +451,29 @@ extern "C" fn scroll_wheel(this: &Object, _: Sel, event: id) {
430451 } ) ) ;
431452}
432453
433- fn get_drag_position ( sender : id ) -> Point {
434- let point: NSPoint = unsafe { msg_send ! [ sender, draggingLocation] } ;
435- Point :: new ( point. x , point. y )
454+ fn get_drag_position ( sender : id ) -> ( Point , Point ) {
455+ // Window-relative position
456+ let window_point: NSPoint = unsafe { msg_send ! [ sender, draggingLocation] } ;
457+
458+ // For drag events, we need to get screen position from the global mouse location
459+ // since NSDraggingInfo doesn't provide it directly
460+ // NSEvent::mouseLocation returns coordinates with Y=0 at BOTTOM
461+ let screen_point: NSPoint = unsafe {
462+ let ns_event_class: id = msg_send ! [ class!( NSEvent ) , class] ;
463+ msg_send ! [ ns_event_class, mouseLocation]
464+ } ;
465+
466+ // Get screen height to flip Y coordinate (convert from bottom-origin to top-origin)
467+ let screen_height = unsafe {
468+ let screen: id = msg_send ! [ class!( NSScreen ) , mainScreen] ;
469+ let frame: NSRect = msg_send ! [ screen, frame] ;
470+ frame. size . height
471+ } ;
472+
473+ (
474+ Point :: new ( window_point. x , window_point. y ) ,
475+ Point :: new ( screen_point. x , screen_height - screen_point. y )
476+ )
436477}
437478
438479fn get_drop_data ( sender : id ) -> DropData {
@@ -473,9 +514,11 @@ extern "C" fn dragging_entered(this: &Object, _sel: Sel, sender: id) -> NSUInteg
473514 let state = unsafe { WindowState :: from_view ( this) } ;
474515 let modifiers = state. keyboard_state ( ) . last_mods ( ) ;
475516 let drop_data = get_drop_data ( sender) ;
517+ let ( position, screen_position) = get_drag_position ( sender) ;
476518
477519 let event = MouseEvent :: DragEntered {
478- position : get_drag_position ( sender) ,
520+ position,
521+ screen_position,
479522 modifiers : make_modifiers ( modifiers) ,
480523 data : drop_data,
481524 } ;
@@ -487,9 +530,11 @@ extern "C" fn dragging_updated(this: &Object, _sel: Sel, sender: id) -> NSUInteg
487530 let state = unsafe { WindowState :: from_view ( this) } ;
488531 let modifiers = state. keyboard_state ( ) . last_mods ( ) ;
489532 let drop_data = get_drop_data ( sender) ;
533+ let ( position, screen_position) = get_drag_position ( sender) ;
490534
491535 let event = MouseEvent :: DragMoved {
492- position : get_drag_position ( sender) ,
536+ position,
537+ screen_position,
493538 modifiers : make_modifiers ( modifiers) ,
494539 data : drop_data,
495540 } ;
@@ -508,9 +553,11 @@ extern "C" fn perform_drag_operation(this: &Object, _sel: Sel, sender: id) -> BO
508553 let state = unsafe { WindowState :: from_view ( this) } ;
509554 let modifiers = state. keyboard_state ( ) . last_mods ( ) ;
510555 let drop_data = get_drop_data ( sender) ;
556+ let ( position, screen_position) = get_drag_position ( sender) ;
511557
512558 let event = MouseEvent :: DragDropped {
513- position : get_drag_position ( sender) ,
559+ position,
560+ screen_position,
514561 modifiers : make_modifiers ( modifiers) ,
515562 data : drop_data,
516563 } ;
0 commit comments