I have been using this snippet without a problem for a while. Is it sufficient
to resolve the issues we are discussing with mouse-position and mouse-pixel-position?
(setq mouse-position-function
(lambda (frame-x-dot-y)
"Under macOS and Windows 7, mouse-position and mouse-pixel-position sometimes return the prior frame; change to always return the selected frame."
(if (consp frame-x-dot-y) (setcar frame-x-dot-y (selected-frame)))
frame-x-dot-y))
Bob