fix: warp uses posn-at-point+window-pixel-edges (frame-relative, not display-absolute)

This commit is contained in:
2026-02-22 21:26:42 +01:00
parent 9d650efecb
commit f49ef939a2

View File

@@ -978,16 +978,23 @@ Keeps the status bar and tab bar fully visible at any zoom level.")
(defun my/warp-mouse-to-cursor ()
"Move mouse pointer to current text cursor position.
Skips if last input was a mouse event (let user pan freely with mouse)."
Skips if last input was a mouse event (let user pan freely with mouse).
Uses posn-at-point + window-pixel-edges to get frame-relative coordinates.
window-absolute-pixel-position is NOT used: on macOS it returns
display-absolute coordinates, but set-mouse-pixel-position expects
frame-relative — causing incorrect warps to screen corners."
(when (and my/cursor-warp-enabled
(display-graphic-p)
(not (my/last-input-was-mouse-p))
(not (window-minibuffer-p (selected-window))))
(when-let* ((pos (window-absolute-pixel-position))
(x (car pos))
(when-let* ((posn (posn-at-point))
(xy (posn-x-y posn)))
(let* ((edges (window-pixel-edges (selected-window)))
(x (+ (nth 0 edges) (car xy)))
;; Place mouse at vertical center of cursor line.
(y (+ (cdr pos) (/ (line-pixel-height) 2))))
(set-mouse-pixel-position (selected-frame) x y))))
(y (+ (nth 1 edges) (cdr xy) (/ (line-pixel-height) 2))))
(set-mouse-pixel-position (selected-frame) x y)))))
(add-hook 'post-command-hook #'my/warp-mouse-to-cursor)