Subject: Re: bug#27053: 26.0.50; x-show-tip gets wrong mouse position if frame moves w/o mouse moving on macOS

From: Alan Third <[email-masked]>
Date: Thu, 25 May 2017 20:23:26 +0100

On Thu, May 25, 2017 at 09:01:11AM +0200, martin rudalics wrote:
> > I do not know what the best solution to this is. They could be stored
> > in screen local coordinates and converted to frame local as they're
> > needed, or they could be recalculated/asked for whenever the frame is
> > moved.
> 
> Both, X and Windows query the absolute mouse position here and the NS
> code should do the same (just that I don't have any idea what the direct
> NS equivalent for XQueryPointer/GetCursorPos is - it should be somehwere
> hidden in ns_mouse_position's
> 
>       position = [[view window] mouseLocationOutsideOfEventStream];
>       position = [view convertPoint: position fromView: nil];
> 
> but I'm too lazy to figure that out).  last_mouse_motion_x/_y are
> conceptually reserved for note_mouse_movement and should not be used for
> anything else (IMHO).

Looks like the right way to get it in screen‐coords is

    [NSEvent mouseLocation]

which returns an NSPoint.

https://developer.apple.com/reference/appkit/nsevent/1533380-mouselocation?language=objc

Seems strange to me that it’s in NSEvent, but I guess it makes sense
to someone.

Patch attached.

I’ve just noticed the grocer’s apostrophe in the commit message.

*sigh*

It seems to me that the NS port seems to like storing values and then
reusing them later even though they can be asked for directly in
real‐time. I don’t know if that’s a coding style thing or what.
-- 
Alan Third
>From 4edade12422f7dc147e7de540f447e2f779508c3 Mon Sep 17 00:00:00 2001
From: Alan Third <[email-masked]>
Date: Thu, 25 May 2017 20:13:21 +0100
Subject: [PATCH] Fix NS tooltip's showing in the wrong place (bug#27053)

* src/nsfns.m (compute_tip_xy): Get current mouse position instead of
last recorded position.
---
 src/nsfns.m | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/src/nsfns.m b/src/nsfns.m
index 3833ee75ac..f2f6a491a9 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -2742,22 +2742,7 @@ and GNUstep implementations ("distributor-specific release
 
   if ((!INTEGERP (left) && !INTEGERP (right))
       || (!INTEGERP (top) && !INTEGERP (bottom)))
-    {
-      pt.x = dpyinfo->last_mouse_motion_x;
-      pt.y = dpyinfo->last_mouse_motion_y;
-      /* Convert to screen coordinates */
-      pt = [view convertPoint: pt toView: nil];
-#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
-      pt = [[view window] convertBaseToScreen: pt];
-#else
-      {
-        NSRect r = NSMakeRect (pt.x, pt.y, 0, 0);
-        r = [[view window] convertRectToScreen: r];
-        pt.x = r.origin.x;
-        pt.y = r.origin.y;
-      }
-#endif
-    }
+    pt = [NSEvent mouseLocation];
   else
     {
       /* Absolute coordinates.  */
-- 
2.12.0