feat: macOS Zoom cursor tracking prototype (SPC z w)

This commit is contained in:
2026-02-22 21:19:01 +01:00
parent 8f3e46c22d
commit 9d650efecb

View File

@@ -937,7 +937,67 @@ Keeps the status bar and tab bar fully visible at any zoom level.")
:desc "Readable (32pt)" "r" #'my/zoom-readable
:desc "Toggle magnifier" "m" #'my/mag-toggle
:desc "Mag zoom in" "M" #'my/mag-zoom-in
:desc "Mag zoom out" "N" #'my/mag-zoom-out))
:desc "Mag zoom out" "N" #'my/mag-zoom-out
:desc "Cursor warp (macOS Zoom)" "w" #'my/cursor-warp-toggle))
;;; ============================================================
;;; ACCESSIBILITY — MACOS ZOOM CURSOR TRACKING (SPC z w)
;;; ============================================================
;; Prototype pro macOS Zoom "Follow mouse cursor" mode.
;;
;; Princip: po každém klávesovém příkazu přesune myš na pozici textového
;; kurzoru. macOS Zoom v "Follow mouse" módu pak sleduje kurzor.
;; Myš je neviditelná při psaní (make-pointer-invisible) → žádné vizuální
;; rušení. Při pohybu myší se viewport nepohybuje (warp se přeskočí).
;;
;; SETUP (jednorázové nastavení macOS):
;; System Settings → Accessibility → Zoom → Zoom style: Full Screen
;; "When zoomed in, the screen image moves: Continuously with pointer"
;; Zoom level: dle potřeby (např. 4-16×)
;; Pak zapni SPC z w pro aktivaci cursor trackingu.
;;
;; SPC z w toggle cursor warp on/off
;; SPC z +/- font scaling (volitelné, pro jemné doladění)
(defvar my/cursor-warp-enabled nil
"When non-nil, mouse is warped to text cursor on each keyboard command.")
;; Hide mouse pointer while typing (standard Emacs feature).
(setq make-pointer-invisible t)
(defun my/last-input-was-mouse-p ()
"Return non-nil if last input event was a mouse or scroll event."
(and last-input-event
(or (mouse-event-p last-input-event)
(mouse-movement-p last-input-event)
(and (listp last-input-event)
(memq (car last-input-event)
'(wheel-up wheel-down wheel-left wheel-right
mouse-4 mouse-5 mouse-6 mouse-7))))))
(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)."
(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))
;; Place mouse at vertical center of cursor line.
(y (+ (cdr pos) (/ (line-pixel-height) 2))))
(set-mouse-pixel-position (selected-frame) x y))))
(add-hook 'post-command-hook #'my/warp-mouse-to-cursor)
(defun my/cursor-warp-toggle ()
"Toggle macOS Zoom cursor tracking on/off."
(interactive)
(setq my/cursor-warp-enabled (not my/cursor-warp-enabled))
(if my/cursor-warp-enabled
(message "Cursor warp ON — macOS Zoom will follow text cursor")
(message "Cursor warp OFF")))
;;; ============================================================