aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Third2019-12-04 12:38:57 +0000
committerAlan Third2019-12-10 20:38:21 +0000
commitfbf9fea4fdad467429058077b8087dbd0758b964 (patch)
tree7180b3632eb606fae872747e93a136feeab1829e /src
parent9042ece787cf93665776ffb69893fcb1357aacbe (diff)
downloademacs-fbf9fea4fdad467429058077b8087dbd0758b964.tar.gz
emacs-fbf9fea4fdad467429058077b8087dbd0758b964.zip
Fix mouse-position on macOS (bug#4892)
* src/nsterm.m (ns_mouse_position): Implement a search for the frame under the mouse pointer.
Diffstat (limited to 'src')
-rw-r--r--src/nsterm.m52
1 files changed, 38 insertions, 14 deletions
diff --git a/src/nsterm.m b/src/nsterm.m
index 493807b2a45..6d8fe350e24 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2475,7 +2475,7 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
2475 -------------------------------------------------------------------------- */ 2475 -------------------------------------------------------------------------- */
2476{ 2476{
2477 id view; 2477 id view;
2478 NSPoint position; 2478 NSPoint view_position;
2479 Lisp_Object frame, tail; 2479 Lisp_Object frame, tail;
2480 struct frame *f; 2480 struct frame *f;
2481 struct ns_display_info *dpyinfo; 2481 struct ns_display_info *dpyinfo;
@@ -2498,31 +2498,55 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
2498 XFRAME (frame)->mouse_moved = 0; 2498 XFRAME (frame)->mouse_moved = 0;
2499 2499
2500 dpyinfo->last_mouse_scroll_bar = nil; 2500 dpyinfo->last_mouse_scroll_bar = nil;
2501 f = dpyinfo->ns_focus_frame ? dpyinfo->ns_focus_frame : SELECTED_FRAME (); 2501
2502 if (dpyinfo->last_mouse_frame 2502#ifdef NS_IMPL_COCOA
2503 /* While dropping, use the last mouse frame only if there is no 2503 /* Find the uppermost Emacs frame under the mouse pointer.
2504 currently focused frame. */ 2504
2505 && (!EQ (track_mouse, Qdropping) || !f) 2505 This doesn't work on GNUstep, although in recent versions there
2506 is compatibility code that makes it a noop. */
2507
2508 NSPoint screen_position = [NSEvent mouseLocation];
2509 NSInteger window_number = 0;
2510 do
2511 {
2512 NSWindow *w;
2513
2514 window_number = [NSWindow windowNumberAtPoint:screen_position
2515 belowWindowWithWindowNumber:window_number];
2516 w = [NSApp windowWithWindowNumber:window_number];
2517
2518 if (w && [[w delegate] isKindOfClass:[EmacsView class]])
2519 f = ((EmacsView *)[w delegate])->emacsframe;
2520 }
2521 while (window_number > 0 && !f);
2522#endif
2523
2524 if (!f)
2525 f = dpyinfo->ns_focus_frame ? dpyinfo->ns_focus_frame : SELECTED_FRAME ();
2526
2527 /* While dropping, use the last mouse frame only if there is no
2528 currently focused frame. */
2529 if (!f
2530 && EQ (track_mouse, Qdropping)
2531 && dpyinfo->last_mouse_frame
2506 && FRAME_LIVE_P (dpyinfo->last_mouse_frame)) 2532 && FRAME_LIVE_P (dpyinfo->last_mouse_frame))
2507 f = dpyinfo->last_mouse_frame; 2533 f = dpyinfo->last_mouse_frame;
2508 else
2509 f = dpyinfo->ns_focus_frame ? dpyinfo->ns_focus_frame : SELECTED_FRAME ();
2510 2534
2511 if (f && FRAME_NS_P (f)) 2535 if (f && FRAME_NS_P (f))
2512 { 2536 {
2513 view = FRAME_NS_VIEW (f); 2537 view = FRAME_NS_VIEW (f);
2514 2538
2515 position = [[view window] mouseLocationOutsideOfEventStream]; 2539 view_position = [[view window] mouseLocationOutsideOfEventStream];
2516 position = [view convertPoint: position fromView: nil]; 2540 view_position = [view convertPoint: view_position fromView: nil];
2517 remember_mouse_glyph (f, position.x, position.y, 2541 remember_mouse_glyph (f, view_position.x, view_position.y,
2518 &dpyinfo->last_mouse_glyph); 2542 &dpyinfo->last_mouse_glyph);
2519 NSTRACE_POINT ("position", position); 2543 NSTRACE_POINT ("view_position", view_position);
2520 2544
2521 if (bar_window) *bar_window = Qnil; 2545 if (bar_window) *bar_window = Qnil;
2522 if (part) *part = scroll_bar_above_handle; 2546 if (part) *part = scroll_bar_above_handle;
2523 2547
2524 if (x) XSETINT (*x, lrint (position.x)); 2548 if (x) XSETINT (*x, lrint (view_position.x));
2525 if (y) XSETINT (*y, lrint (position.y)); 2549 if (y) XSETINT (*y, lrint (view_position.y));
2526 if (time) 2550 if (time)
2527 *time = dpyinfo->last_mouse_movement_time; 2551 *time = dpyinfo->last_mouse_movement_time;
2528 *fp = f; 2552 *fp = f;