Fix point coordinate differences across OS’s.

This commit is contained in:
Yuan Fu 2019-02-10 12:53:55 -05:00
parent 5a9ceec283
commit 6ce7402874
No known key found for this signature in database
GPG Key ID: 1CF5ECABEC37A901

View File

@ -199,32 +199,44 @@ Position is calculated base on WIDTH and HEIGHT of childframe text window"
;; y position + a little padding (16) ;; y position + a little padding (16)
16)) 16))
(defun eldoc-box--point-position-relative-to-native-frame (&optional position window)
"Return (X . Y) as the coordinate of POSITION in WINDOW.
The coordinate is relative to the native frame.
WINDOW nil means use selected window."
(let* ((window (window-normalize-window window t))
(pos-in-window
(pos-visible-in-window-p
(or position (window-point window)) window t)))
(when pos-in-window
;; change absolute to relative to native frame
(let ((edges (window-edges window t nil t)))
(cons (+ (nth 0 edges) (nth 0 pos-in-window))
(+ (nth 1 edges) (nth 1 pos-in-window)))))))
(defun eldoc-box--default-at-point-position-function (width height) (defun eldoc-box--default-at-point-position-function (width height)
"Set `eldoc-box-position-function' to this function to have childframe appear under point. "Set `eldoc-box-position-function' to this function to have childframe appear under point.
Position is calculated base on WIDTH and HEIGHT of childframe text window" Position is calculated base on WIDTH and HEIGHT of childframe text window"
;; (window-absolute-pixel-position) (let* ((point-pos (eldoc-box--point-position-relative-to-native-frame))
;; (posn-x-y (posn-at-point)) ;; calculate point coordinate relative to native frame
(let* ((point-pos (window-absolute-pixel-position)) ;; because childframe coordinate is relative to native frame
(frame-pos (frame-edges nil 'native-edges)) (x (car point-pos))
(x (- (car point-pos) (car frame-pos))) ; relative to native frame (y (cdr point-pos))
(y (- (cdr point-pos) (nth 1 frame-pos)))
;; (en (frame-char-width)) ;; (en (frame-char-width))
(em (frame-char-height)) (em (frame-char-height))
(frame-geometry (frame-geometry)) (frame-geometry (frame-geometry)))
(tool-bar (if (and tool-bar-mode
(alist-get 'tool-bar-external frame-geometry))
(cdr (alist-get 'tool-bar-size frame-geometry))
0)))
(cons (if (< (- (frame-inner-width) width) x) (cons (if (< (- (frame-inner-width) width) x)
;; space on the right of the pos is not enough ;; space on the right of the pos is not enough
;; put to left ;; put to left
(max 0 (- x width)) (max 0 (- x width))
;; normal, just return x
x) x)
(if (< (- (frame-inner-height) height) y) (if (< (- (frame-inner-height) height) y)
;; space under the pos is not enough ;; space under the pos is not enough
;; put above ;; put above
(max 0 (- y height)) (max 0 (- y height))
(+ y em tool-bar))))) ;; normal, just return y + em
(+ y em)))))
(defun eldoc-box--get-frame (buffer) (defun eldoc-box--get-frame (buffer)
"Return a childframe displaying BUFFER. "Return a childframe displaying BUFFER.